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

com.ancientlightstudios.quarkus.kotlin.openapi.transformer.ParameterTransformer.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.models.transformed.AdditionalInformation
import com.ancientlightstudios.quarkus.kotlin.openapi.models.transformed.Parameter
import com.ancientlightstudios.quarkus.kotlin.openapi.models.transformed.Source
import com.ancientlightstudios.quarkus.kotlin.openapi.models.openapi.parameter.Parameter as OpenApiParameter
import com.ancientlightstudios.quarkus.kotlin.openapi.models.openapi.parameter.Parameter.CookieParameter as OpenApiCookieParameter
import com.ancientlightstudios.quarkus.kotlin.openapi.models.openapi.parameter.Parameter.HeaderParameter as OpenApiHeaderParameter
import com.ancientlightstudios.quarkus.kotlin.openapi.models.openapi.parameter.Parameter.PathParameter as OpenApiPathParameter
import com.ancientlightstudios.quarkus.kotlin.openapi.models.openapi.parameter.Parameter.QueryParameter as OpenApiQueryParameter

class ParameterTransformer(private val source: OpenApiParameter) {

    fun initializeSchemaRegistry(schemaCollector: SchemaCollector, nameHint: String) {
        schemaCollector.registerSchema(source.schema, FlowDirection.Up) { "$nameHint ${source.name} parameter" }
    }

    fun transform(typeDefinitionRegistry: TypeDefinitionRegistry): Parameter {
        val name = source.name
        val type = typeDefinitionRegistry.getTypeDefinition(source.schema, FlowDirection.Up)
        return when (source) {
            is OpenApiPathParameter -> Parameter(
                name,
                type.useAs(true),
                Source.Path,
                AdditionalInformation(source.description)
            )

            is OpenApiQueryParameter -> Parameter(
                name,
                type.useAs(source.required),
                Source.Query,
                AdditionalInformation(source.description, source.deprecated)
            )

            is OpenApiHeaderParameter -> Parameter(
                name,
                type.useAs(source.required),
                Source.Header,
                AdditionalInformation(source.description, source.deprecated)
            )

            is OpenApiCookieParameter -> Parameter(
                name,
                type.useAs(source.required),
                Source.Cookie,
                AdditionalInformation(source.description, source.deprecated)
            )
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy