com.ancientlightstudios.quarkus.kotlin.openapi.parser.RequestBodyBuilder.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-kotlin-openapi-maven-plugin Show documentation
Show all versions of quarkus-kotlin-openapi-maven-plugin Show documentation
A Maven plugin to use the OpenAPI generator.
package com.ancientlightstudios.quarkus.kotlin.openapi.parser
import com.ancientlightstudios.quarkus.kotlin.openapi.models.hints.NameSuggestionHint.nameSuggestion
import com.ancientlightstudios.quarkus.kotlin.openapi.models.transformable.TransformableBody
import com.fasterxml.jackson.databind.node.ObjectNode
class RequestBodyBuilder(private val node: ObjectNode) {
fun ParseContext.build(): TransformableBody {
return when (val ref = node.getTextOrNull("\$ref")) {
null -> extractBodyDefinition()
else -> extractBodyReference(ref)
}
}
private fun ParseContext.extractBodyDefinition() = TransformableBody(
node.getBooleanOrNull("required") ?: false, contextFor("content").parseAsContent()
)
private fun ParseContext.extractBodyReference(ref: String) = rootContext.contextFor(JsonPointer.fromPath(ref))
.parseAsRequestBody()
.apply { nameSuggestion = ref.nameSuggestion() }
}
fun ParseContext.parseAsRequestBody() =
contextNode.asObjectNode { "Json object expected for $contextPath" }
.let {
RequestBodyBuilder(it).run { [email protected]() }
}