openapi.templates.kora.kotlinServerRequestMappers.mustache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openapi-generator Show documentation
Show all versions of openapi-generator Show documentation
Kora openapi-generator module
package {{package}}
import ru.tinkoff.kora.http.server.common.form.MultipartReader
import ru.tinkoff.kora.http.server.common.handler.HttpServerRequestMapper
import ru.tinkoff.kora.http.server.common.HttpServerRequest
{{#isSuspend}}
import java.util.concurrent.CompletionStage;
{{/isSuspend}}
@ru.tinkoff.kora.common.annotation.Generated("openapi generator kora server"){{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}
interface {{classname}}ServerRequestMappers {
{{#operations}}
{{#operation}}
{{#hasFormParams}}
@ru.tinkoff.kora.common.annotation.Generated("openapi generator kora server")
class {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}FormParamRequestMapper{{#vendorExtensions.requiresFormParamMappers}}({{#vendorExtensions.formParamMappers}}
private val {{paramName}}Converter: ru.tinkoff.kora.http.server.common.handler.StringParameterReader<{{paramType}}>,
{{/vendorExtensions.formParamMappers}}
){{/vendorExtensions.requiresFormParamMappers}}: HttpServerRequestMapper<{{#isSuspend}}CompletionStage<{{/isSuspend}}{{classname}}Controller.{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}FormParam{{#isSuspend}}>{{/isSuspend}}> {
override fun apply(request: HttpServerRequest): {{#isSuspend}}CompletionStage<{{/isSuspend}}{{classname}}Controller.{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}FormParam{{#isSuspend}}>{{/isSuspend}} {
{{#vendorExtensions.urlEncodedForm}}
return request.body().asArrayStage().thenApply { bytes ->
val bodyString = bytes.decodeToString()
val formData = ru.tinkoff.kora.http.server.common.form.FormUrlEncodedServerRequestMapper.read(bodyString)
{{#formParams}}
val {{paramName}}Part = formData.get("{{baseName}}"){{#isArray}}
val {{paramName}} = if ({{paramName}}Part == null) emptyList() else {{paramName}}Part.values()
{{/isArray}}{{^isArray}}{{#vendorExtensions.requiresMapper}}
val {{paramName}} = if ({{paramName}}Part == null || {{paramName}}Part.values().isEmpty()) null else {{paramName}}Converter.read({{paramName}}Part.values().first())
{{/vendorExtensions.requiresMapper}}{{^vendorExtensions.requiresMapper}}
val {{paramName}} = if ({{paramName}}Part == null || {{paramName}}Part.values().isEmpty()) null else {{paramName}}Part.values().first()
{{/vendorExtensions.requiresMapper}}{{#required}}
if ({{paramName}} == null) {
throw ru.tinkoff.kora.http.server.common.HttpServerResponseException.of(400, "Form key '{{baseName}}' is required")
}
{{/required}}{{/isArray}}{{/formParams}}
{{classname}}Controller.{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}FormParam(
{{#formParams}}{{paramName}}{{^-last}}, {{/-last}}{{/formParams}}
)
}{{^isSuspend}}.toCompletableFuture().get(){{/isSuspend}}{{/vendorExtensions.urlEncodedForm}}{{#vendorExtensions.multipartForm}}
class {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}FormParamState {
{{#formParams}}
{{#isFile}} var {{paramName}}: ru.tinkoff.kora.http.common.form.FormMultipart.FormPart.MultipartFile? = null
{{/isFile}}{{^isFile}} var {{paramName}}: {{{dataType}}}? = null
{{/isFile}}{{/formParams}}
}
return MultipartReader.read(request)
.thenApply { parts ->
val state = {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}FormParamState()
for (part in parts) {
when (part.name()) {
{{#formParams}}
"{{baseName}}" -> {
{{#isFile}} state.{{paramName}} = part
{{/isFile}}{{^isFile}} state.{{paramName}} = part.content().decodeToString()
{{/isFile}}
}
{{/formParams}}
else -> {}
}
}
{{#formParams}}{{#required}}
if (state.{{paramName}} == null) {
throw ru.tinkoff.kora.http.server.common.HttpServerResponseException.of(400, "Form key '{{baseName}}' is required")
}
{{/required}}{{/formParams}}
{{classname}}Controller.{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}FormParam(
{{#formParams}}state.{{paramName}}{{#required}}!!{{/required}}{{^-last}}, {{/-last}}{{/formParams}}
)
}{{^isSuspend}}.toCompletableFuture().get(){{/isSuspend}}
{{/vendorExtensions.multipartForm}}
}
}
{{/hasFormParams}}
{{/operation}}
{{/operations}}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy