com.ancientlightstudios.quarkus.kotlin.openapi.emitter.ServerRequestContainerEmitter.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.emitter
import com.ancientlightstudios.quarkus.kotlin.openapi.models.kotlin.kotlinClass
import com.ancientlightstudios.quarkus.kotlin.openapi.models.kotlin.kotlinFile
import com.ancientlightstudios.quarkus.kotlin.openapi.models.kotlin.kotlinMember
import com.ancientlightstudios.quarkus.kotlin.openapi.models.transformed.name.ClassName.Companion.className
import com.ancientlightstudios.quarkus.kotlin.openapi.models.transformed.Request
import com.ancientlightstudios.quarkus.kotlin.openapi.models.transformed.RequestSuite
import com.ancientlightstudios.quarkus.kotlin.openapi.models.transformed.name.VariableName.Companion.variableName
import com.ancientlightstudios.quarkus.kotlin.openapi.transformer.TypeDefinitionRegistry
class ServerRequestContainerEmitter : CodeEmitter {
override fun EmitterContext.emit(suite: RequestSuite, typeDefinitionRegistry: TypeDefinitionRegistry) {
suite.requests.forEach {
if (it.hasInputData()) {
emitRequestContainer(it)
}
}
}
private fun EmitterContext.emitRequestContainer(request: Request) {
kotlinFile(serverPackage(), request.name.extend(postfix = "Request").className()) {
registerImport(modelPackage(), wildcardImport = true)
kotlinClass(fileName) {
request.parameters.forEach {
kotlinMember(it.name.variableName(), it.type.safeType, accessModifier = null)
}
request.body?.let {
kotlinMember("body".variableName(), it.safeType, accessModifier = null)
}
}
}.also { generateFile(it) }
}
}