com.ancientlightstudios.quarkus.kotlin.openapi.emitter.statements.AnyOfBuilderDeserializationStatement.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.statements
import com.ancientlightstudios.quarkus.kotlin.openapi.emitter.CodeWriter
import com.ancientlightstudios.quarkus.kotlin.openapi.models.kotlin.KotlinStatement
import com.ancientlightstudios.quarkus.kotlin.openapi.models.transformed.name.ClassName
import com.ancientlightstudios.quarkus.kotlin.openapi.models.transformed.name.VariableName
import com.ancientlightstudios.quarkus.kotlin.openapi.utils.forEachWithStats
class AnyOfBuilderDeserializationStatement(val objectName: ClassName) : KotlinStatement {
private val parameters = mutableListOf()
fun addParameter(maybeName: VariableName) {
parameters.add(maybeName)
}
override fun render(writer: CodeWriter) = with(writer) {
write("return maybeAnyOf(context")
parameters.forEach { maybeName ->
write(", ${maybeName.render()}")
}
write(") {")
indent(newLineBefore = true, newLineAfter = true) {
write("${objectName.render()}(")
indent(newLineBefore = true, newLineAfter = true) {
parameters.forEachWithStats { status, maybeName ->
write("${maybeName.render()}.validValueOrNull()")
if (!status.last) {
writeln(",")
}
}
}
write(")")
}
writeln("}")
}
}