Skip to content

Commit

Permalink
Change OpenAPI.getAllParameters() helper function return type to Coll…
Browse files Browse the repository at this point in the history
…ection

* Change return type in `OpenAPI.getAllParameters()`
* Update dependent rules
  • Loading branch information
vadeg committed Oct 26, 2021
1 parent f00c85c commit 55417a9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion documentation/operation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
3. Build the source > build Docker image > run Docker container
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class CaseChecker(
type: String,
check: CaseCheck?
): List<Violation> = context.api
.getAllParameters().values
.getAllParameters()
.filter { type.toLowerCase() == it.`in` }
.flatMap { param ->
check("$type parameter", "$type parameters", check, param.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,13 @@ fun OpenAPI.getAllProperties(): Map<String, Schema<Any>> {
* Returns all defined parameters of an API specification
* @return a collection of parameters
*/
fun OpenAPI.getAllParameters(): Map<String, Parameter> = 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<Parameter> =
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<String, SecurityScheme> = this.components?.securitySchemes.orEmpty()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class QueryParameterCollectionFormatRule {
@Check(severity = Severity.SHOULD)
fun checkParametersCollectionFormat(context: Context): List<Violation> =
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) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PathParameterRule {

@Check(severity = Severity.MUST)
fun checkRequiredPathAttribute(context: Context): List<Violation> =
context.api.getAllParameters().map { entry -> entry.value }
context.api.getAllParameters()
.filter { parameter ->
parameter.isInPath() && !parameter.required
}
Expand All @@ -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)
}
}
Expand All @@ -54,12 +54,12 @@ class PathParameterRule {
fun validateParameterContentMapStructure(context: Context): List<Violation> {
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)
}
}
Expand Down

0 comments on commit 55417a9

Please sign in to comment.