de.codecentric.hikaku.converters.openapi.extractors.ConsumesExtractor.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 io.swagger.v3.oas.models.OpenAPI
import io.swagger.v3.oas.models.Operation
internal class ConsumesExtractor(private val openApi: OpenAPI) {
operator fun invoke(operation: Operation?): Set {
return operation?.requestBody
?.content
?.keys
.orEmpty()
.union(extractConsumesFromComponents(operation))
.toSet()
}
private fun extractConsumesFromComponents(operation: Operation?): Set {
return operation?.requestBody
?.referencedSchema
?.let {
Regex("#/components/requestBodies/(?.+)")
.find(it)
?.groups
?.get("key")
?.value
}
?.let {
openApi.components
.requestBodies[it]
?.content
?.keys
}
.orEmpty()
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy