de.codecentric.hikaku.converters.openapi.extractors.PathParameterExtractor.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hikaku-openapi Show documentation
Show all versions of hikaku-openapi Show documentation
A library that tests if the implementation of a REST-API meets its specification. This module contains a converter for OpenAPI specifications.
package de.codecentric.hikaku.converters.openapi.extractors
import de.codecentric.hikaku.converters.openapi.extensions.referencedSchema
import de.codecentric.hikaku.endpoints.PathParameter
import io.swagger.v3.oas.models.OpenAPI
import io.swagger.v3.oas.models.parameters.PathParameter as OpenApiPathParameter
import io.swagger.v3.oas.models.parameters.Parameter as OpenApiParameter
internal class PathParameterExtractor(private val openApi: OpenAPI) {
operator fun invoke(parameters: List?): Set {
return extractInlinePathParameters(parameters).union(extractPathParametersFromComponents(parameters))
}
private fun extractInlinePathParameters(parameters: List?): Set {
return parameters
?.filterIsInstance()
?.map { PathParameter(it.name) }
.orEmpty()
.toSet()
}
private fun extractPathParametersFromComponents(parameters: List?): Set {
return parameters
?.filter { it.referencedSchema != null }
?.map {
Regex("#/components/parameters/(?.+)")
.find(it.referencedSchema)
?.groups
?.get("key")
?.value
}
?.map {
openApi.components
.parameters[it]
}
?.filter { it?.`in` == "path" }
?.map { PathParameter(it?.name ?: "") }
.orEmpty()
.toSet()
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy