diff --git a/server/zally-ruleset-zally/src/main/kotlin/org/zalando/zally/ruleset/zally/PathParameterRule.kt b/server/zally-ruleset-zally/src/main/kotlin/org/zalando/zally/ruleset/zally/PathParameterRule.kt index c58021482..83da258c1 100644 --- a/server/zally-ruleset-zally/src/main/kotlin/org/zalando/zally/ruleset/zally/PathParameterRule.kt +++ b/server/zally-ruleset-zally/src/main/kotlin/org/zalando/zally/ruleset/zally/PathParameterRule.kt @@ -55,8 +55,9 @@ class PathParameterRule { if (context.isOpenAPI3()) { return context.api.getAllParameters() .filterValues { - val contentMap = it.content.orEmpty() - contentMap.isEmpty() || contentMap.size > 1 + if (it.content != null) { + it.content.isEmpty() || it.content.size > 1 + } else false } .map { (_, parameter) -> context.violation(contentMapStructureErrorMessage(parameter.name), parameter) diff --git a/server/zally-ruleset-zally/src/test/kotlin/org/zalando/zally/ruleset/zally/PathParameterRuleTest.kt b/server/zally-ruleset-zally/src/test/kotlin/org/zalando/zally/ruleset/zally/PathParameterRuleTest.kt index c1f97932c..64ac99bee 100644 --- a/server/zally-ruleset-zally/src/test/kotlin/org/zalando/zally/ruleset/zally/PathParameterRuleTest.kt +++ b/server/zally-ruleset-zally/src/test/kotlin/org/zalando/zally/ruleset/zally/PathParameterRuleTest.kt @@ -266,10 +266,50 @@ class PathParameterRuleTest { val violations = rule.validateParameterContentMapStructure(context) - assertThat(violations).hasSize(2) - assertThat(violations).containsDescriptionsInAnyOrder( - PathParameterRule.contentMapStructureErrorMessage("X-HEADER-ID"), - PathParameterRule.contentMapStructureErrorMessage("item-id") + assertThat(violations).hasSize(1) + assertThat(violations).descriptionsAllEqualTo( + PathParameterRule.contentMapStructureErrorMessage("X-HEADER-ID") + ) + } + + @Test + fun `return no violations if 'content' is not defined`() { + @Language("YAML") + val context = DefaultContextFactory().getOpenApiContext( + """ + openapi: '3.0.0' + info: + title: Schema and content Parameter properties validation + contact: + info: "Team One" + paths: + /endpoint: + post: + summary: | + Some summary. + security: + - oauth2: ["uid"] + parameters: + - name: X-HEADER-ID + description: Header description + in: header + required: false + schema: + type: string + - $\ref: "#/components/parameters/QueryParameter" + components: + parameters: + QueryParameter: + name: item-id + in: path + description: The id of the pet to retrieve + schema: + type: string + """.trimIndent() ) + + val violations = rule.validateParameterContentMapStructure(context) + + assertThat(violations).isEmpty() } }