com.ancientlightstudios.quarkus.kotlin.openapi.transformer.ApiSpecTransformer.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.transformer
import com.ancientlightstudios.quarkus.kotlin.openapi.Config
import com.ancientlightstudios.quarkus.kotlin.openapi.models.openapi.ApiSpec
import com.ancientlightstudios.quarkus.kotlin.openapi.models.transformed.AdditionalInformation
import com.ancientlightstudios.quarkus.kotlin.openapi.models.transformed.name.ClassName.Companion.className
import com.ancientlightstudios.quarkus.kotlin.openapi.models.transformed.RequestSuite
class ApiSpecTransformer(private val source: ApiSpec, private val config:Config) {
fun transform(): Pair {
val typeDefinitionRegistry = initializeTypeDefinitionRegistry()
return transform(config.interfaceName, typeDefinitionRegistry) to typeDefinitionRegistry
}
private fun initializeTypeDefinitionRegistry(): TypeDefinitionRegistry {
val schemaCollector = SchemaCollector()
source.requests.forEach {
RequestTransformer(it).initializeSchemaRegistry(schemaCollector)
}
return schemaCollector.getTypeDefinitionRegistry(config)
}
private fun transform(interfaceName: String, typeDefinitionRegistry: TypeDefinitionRegistry): RequestSuite {
return RequestSuite(
interfaceName.className(),
source.version,
source.requests.map { RequestTransformer(it).transform(typeDefinitionRegistry) },
AdditionalInformation(source.description)
)
}
}