openapi.templates.kora.kotlinServerResponseMappers.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.handler.HttpServerResponseMapper
import ru.tinkoff.kora.http.server.common.handler.HttpServerResponseEntityMapper
import ru.tinkoff.kora.http.server.common.HttpServerRequest
import ru.tinkoff.kora.http.server.common.HttpServerResponse
import ru.tinkoff.kora.http.common.HttpResponseEntity
import ru.tinkoff.kora.http.common.header.HttpHeaders
import ru.tinkoff.kora.http.common.body.HttpBody
import ru.tinkoff.kora.common.Context
import {{package}}.{{classname}}Responses.*
{{#imports}}import {{import}}
{{/imports}}
@ru.tinkoff.kora.common.annotation.Generated("openapi generator kora server"){{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}
interface {{classname}}ServerResponseMappers {
{{#operations}}
{{#operation}}
@ru.tinkoff.kora.common.annotation.Generated("openapi generator kora server")
class {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}{{code}}ResponseMapper(
{{#responses}}
{{#dataType}}
{{#vendorExtensions.hasMapperTag}}
@{{vendorExtensions.mapperTag}}
{{/vendorExtensions.hasMapperTag}}
response{{code}}Delegate: HttpServerResponseMapper<{{{dataType}}}>{{#vendorExtensions.hasMore}},{{/vendorExtensions.hasMore}}
{{/dataType}}
{{/responses}}
): HttpServerResponseMapper<{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}ApiResponse>{
{{#responses}}
{{#dataType}}
private val response{{code}}Delegate = HttpServerResponseEntityMapper(response{{code}}Delegate)
{{/dataType}}
{{/responses}}
override fun apply(ctx: Context, rq: HttpServerRequest, rs: {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}ApiResponse): HttpServerResponse { {{^vendorExtensions.singleResponse}}
when (rs) {
{{/vendorExtensions.singleResponse}}{{#responses}}{{^vendorExtensions.singleResponse}}
is {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}ApiResponse{{^vendorExtensions.singleResponse}}.{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}{{#isDefault}}Default{{/isDefault}}{{^isDefault}}{{code}}{{/isDefault}}ApiResponse{{/vendorExtensions.singleResponse}} -> {
{{/vendorExtensions.singleResponse}}
{{#vendorExtensions.isBinaryUnknownType}}
val headers = HttpHeaders.of("content-type", "{{{vendorExtensions.contentType}}}")
{{/vendorExtensions.isBinaryUnknownType}}
{{^vendorExtensions.isBinaryUnknownType}}
val headers = HttpHeaders.of()
{{/vendorExtensions.isBinaryUnknownType}}{{#headers}}{{#required}}
headers.set("{{baseName}}", rs.{{#lambda.camelcase}}{{nameInCamelCase}}{{/lambda.camelcase}});{{/required}}{{^required}}
rs.{{#lambda.camelcase}}{{nameInCamelCase}}{{/lambda.camelcase}}?.let { headers.set("{{baseName}}", it) }{{/required}}{{/headers}}
{{#isBinary}}{{#vendorExtensions.isBinaryUnknownType}}
val entity = HttpResponseEntity.of({{#isDefault}}rs.statusCode{{/isDefault}}{{^isDefault}}{{code}}{{/isDefault}}, headers, rs.content)
return response{{code}}Delegate.apply(ctx, rq, entity)
{{/vendorExtensions.isBinaryUnknownType}}{{^vendorExtensions.isBinaryUnknownType}}
return HttpServerResponse.of({{#isDefault}}rs.statusCode{{/isDefault}}{{^isDefault}}{{code}}{{/isDefault}}, headers, HttpBody.of(ctx, "{{{vendorExtensions.contentType}}}", rs.content))
{{/vendorExtensions.isBinaryUnknownType}}{{/isBinary}}
{{^isBinary}}{{^dataType}}
return HttpServerResponse.of({{#isDefault}}rs.statusCode{{/isDefault}}{{^isDefault}}{{code}}{{/isDefault}}, headers)
{{/dataType}}{{#dataType}}
val entity = HttpResponseEntity.of({{#isDefault}}rs.statusCode{{/isDefault}}{{^isDefault}}{{code}}{{/isDefault}}, headers, rs.content)
return response{{code}}Delegate.apply(ctx, rq, entity)
{{/dataType}}{{/isBinary}}{{^vendorExtensions.singleResponse}}
}{{/vendorExtensions.singleResponse}}
{{/responses}}{{^vendorExtensions.singleResponse}}
}{{/vendorExtensions.singleResponse}}
}
}
{{/operation}}
{{/operations}}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy