All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ancientlightstudios.quarkus.kotlin.openapi.emitter.statements.AnyOfBuilderDeserializationStatement.kt Maven / Gradle / Ivy

There is a newer version: 0.4.14
Show newest version
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("}")
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy