com.ancientlightstudios.quarkus.kotlin.openapi.transformer.ParameterTransformer.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.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)
)
}
}
}