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

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

There is a newer version: 0.4.14
Show newest version
package com.ancientlightstudios.quarkus.kotlin.openapi.emitter

import com.ancientlightstudios.quarkus.kotlin.openapi.models.kotlin.KotlinFile
import java.nio.file.Path
import kotlin.io.path.Path

class EmitterContext(
    private val packageName: String,
    private val outputDirectory: Path,
    val pathPrefix: String,
    val additionalImports: List = listOf(),
    val omitNullsInSerialization: Boolean = true,
    val additionalProviders : List = listOf()
) {

    fun serverPackage() = "$packageName.server"

    fun clientPackage() = "$packageName.client"
    
    fun modelPackage() = "$packageName.model"

    fun apiPackage() = "com.ancientlightstudios.quarkus.kotlin.openapi"

    fun generateFile(file: KotlinFile) {
        val targetPath = if (file.packageName.isNotBlank()) {
            val subPath = file.packageName.split(".")
            outputDirectory.resolve(Path(subPath.first(), *subPath.drop(1).toTypedArray()))
        } else {
            outputDirectory
        }

        targetPath.toFile().mkdirs()

        val outputFile = targetPath.resolve("${file.fileName.render()}.kt").toFile()
        check(outputFile.exists() || outputFile.createNewFile()) { "Could not create file $outputFile" }

        outputFile.bufferedWriter().use {
            file.render(CodeWriter(it))
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy