diff --git a/documentation/operation.md b/documentation/operation.md index 19f46d6d6..f6ec4cee0 100644 --- a/documentation/operation.md +++ b/documentation/operation.md @@ -47,4 +47,4 @@ In general, there are 3 options to start a component: 1. With the build tool (Gradle, Yarn) 2. Build the source > start the bundle/jar/binary -3. Build the source > build Docker image > run Docker container \ No newline at end of file +3. Build the source > build Docker image > run Docker container diff --git a/server/zally-core/src/main/kotlin/org/zalando/zally/core/CaseChecker.kt b/server/zally-core/src/main/kotlin/org/zalando/zally/core/CaseChecker.kt index b3d559f41..f822e3f05 100644 --- a/server/zally-core/src/main/kotlin/org/zalando/zally/core/CaseChecker.kt +++ b/server/zally-core/src/main/kotlin/org/zalando/zally/core/CaseChecker.kt @@ -209,7 +209,7 @@ class CaseChecker( type: String, check: CaseCheck? ): List = context.api - .getAllParameters().values + .getAllParameters() .filter { type.toLowerCase() == it.`in` } .flatMap { param -> check("$type parameter", "$type parameters", check, param.name) diff --git a/server/zally-core/src/main/kotlin/org/zalando/zally/core/util/OpenApiUtil.kt b/server/zally-core/src/main/kotlin/org/zalando/zally/core/util/OpenApiUtil.kt index a768551f7..0900e6b8d 100644 --- a/server/zally-core/src/main/kotlin/org/zalando/zally/core/util/OpenApiUtil.kt +++ b/server/zally-core/src/main/kotlin/org/zalando/zally/core/util/OpenApiUtil.kt @@ -115,11 +115,13 @@ fun OpenAPI.getAllProperties(): Map> { * Returns all defined parameters of an API specification * @return a collection of parameters */ -fun OpenAPI.getAllParameters(): Map = this.components?.parameters.orEmpty() + - this.paths.orEmpty().values.flatMap { it?.parameters.orEmpty().mapNotNull { it.name to it } } + - this.paths.orEmpty().values.flatMap { - it?.readOperations().orEmpty().flatMap { it?.parameters.orEmpty().mapNotNull { it.name to it } } - } +fun OpenAPI.getAllParameters(): Collection = + this.components?.parameters?.values.orEmpty().filterNotNull().toList() + + this.paths.orEmpty().values.flatMap { it?.parameters.orEmpty().filterNotNull() } + + this.paths.orEmpty().values.flatMap { + it?.readOperations().orEmpty().flatMap { it?.parameters.orEmpty().filterNotNull() } + } + fun OpenAPI.getAllSecuritySchemes(): Map = this.components?.securitySchemes.orEmpty() diff --git a/server/zally-ruleset-zalando/src/main/kotlin/org/zalando/zally/ruleset/zalando/QueryParameterCollectionFormatRule.kt b/server/zally-ruleset-zalando/src/main/kotlin/org/zalando/zally/ruleset/zalando/QueryParameterCollectionFormatRule.kt index dd968bf92..6619ee968 100644 --- a/server/zally-ruleset-zalando/src/main/kotlin/org/zalando/zally/ruleset/zalando/QueryParameterCollectionFormatRule.kt +++ b/server/zally-ruleset-zalando/src/main/kotlin/org/zalando/zally/ruleset/zalando/QueryParameterCollectionFormatRule.kt @@ -21,7 +21,7 @@ class QueryParameterCollectionFormatRule { @Check(severity = Severity.SHOULD) fun checkParametersCollectionFormat(context: Context): List = if (context.isOpenAPI3()) - context.api.getAllParameters().values + context.api.getAllParameters() .filter { "query" == it.`in` && "array" == it.schema?.type } .filter { it.style == null || allowedStyle != it.style } .map { context.violation(description, it) } 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 83da258c1..57ef9a191 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 @@ -29,7 +29,7 @@ class PathParameterRule { @Check(severity = Severity.MUST) fun checkRequiredPathAttribute(context: Context): List = - context.api.getAllParameters().map { entry -> entry.value } + context.api.getAllParameters() .filter { parameter -> parameter.isInPath() && !parameter.required } @@ -42,8 +42,8 @@ class PathParameterRule { if (context.isOpenAPI3()) { return context.api .getAllParameters() - .filterValues { it.schema == null && it.content == null } - .map { (_, parameter) -> + .filter { it.schema == null && it.content == null } + .map { parameter -> context.violation(requiredSchemaOrContentErrorMessage(parameter.name), parameter) } } @@ -54,12 +54,12 @@ class PathParameterRule { fun validateParameterContentMapStructure(context: Context): List { if (context.isOpenAPI3()) { return context.api.getAllParameters() - .filterValues { + .filter { if (it.content != null) { it.content.isEmpty() || it.content.size > 1 } else false } - .map { (_, parameter) -> + .map { parameter -> context.violation(contentMapStructureErrorMessage(parameter.name), parameter) } }