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

com.ancientlightstudios.quarkus.kotlin.openapi.transformer.ApiSpecTransformer.kt Maven / Gradle / Ivy

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy