openapi.templates.kora.javaServerRequestMappers.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
/**
* NOTE: This class is auto generated by Kora OpenAPI Generator (https://openapi-generator.tech) ({{{generatorVersion}}}).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
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;
{{^isBlocking}}
import java.util.concurrent.CompletionStage;
{{/isBlocking}}
@ru.tinkoff.kora.common.annotation.Generated("openapi generator kora server"){{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}
public interface {{classname}}ServerRequestMappers {
{{#operations}}
{{#operation}}
{{#hasFormParams}}
@ru.tinkoff.kora.common.annotation.Generated("openapi generator kora server")
final class {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}FormParamRequestMapper implements HttpServerRequestMapper<
{{#isBlocking}}{{classname}}Controller.{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}FormParam{{/isBlocking}}{{^isBlocking}}
CompletionStage<{{classname}}Controller.{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}FormParam>{{/isBlocking}}> {
{{#vendorExtensions.requiresFormParamMappers}}
{{#vendorExtensions.formParamMappers}}
private ru.tinkoff.kora.http.server.common.handler.StringParameterReader<{{paramType}}> {{paramName}}Converter;
{{/vendorExtensions.formParamMappers}}
public {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}FormParamRequestMapper({{#vendorExtensions.formParamMappers}}{{#requireTag}}
@{{mapperTag}}{{/requireTag}}
ru.tinkoff.kora.http.server.common.handler.StringParameterReader<{{paramType}}> {{paramName}}Converter{{^last}},{{/last}}
{{/vendorExtensions.formParamMappers}}) {
{{#vendorExtensions.formParamMappers}}
this.{{paramName}}Converter = {{paramName}}Converter;
{{/vendorExtensions.formParamMappers}}
}
{{/vendorExtensions.requiresFormParamMappers}}
@Override public {{#isBlocking}}
{{classname}}Controller.{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}FormParam{{/isBlocking}}{{^isBlocking}}
CompletionStage<{{classname}}Controller.{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}FormParam>{{/isBlocking}} apply(HttpServerRequest request) throws Exception {
{{#vendorExtensions.urlEncodedForm}}
return request.body().asArrayStage().toCompletableFuture().thenApply(bytes -> {
var bodyString = new String(bytes, java.nio.charset.StandardCharsets.UTF_8);
var formData = ru.tinkoff.kora.http.server.common.form.FormUrlEncodedServerRequestMapper.read(bodyString);{{#formParams}}
var {{paramName}}Part = formData.get("{{baseName}}");{{#isArray}}
var {{paramName}} = {{paramName}}Part == null ? java.util.List.of() : {{paramName}}Part;
{{/isArray}}{{^isArray}}{{#required}}
if ({{paramName}}Part == null || {{paramName}}Part.values().isEmpty()) {
throw ru.tinkoff.kora.http.server.common.HttpServerResponseException.of(400, "Form key '{{baseName}}' is required");
}
{{#vendorExtensions.requiresMapper}}
var {{paramName}} = {{paramName}}Converter.read({{paramName}}Part.values().get(0));
{{/vendorExtensions.requiresMapper}}{{^vendorExtensions.requiresMapper}}
var {{paramName}} = {{paramName}}Part.values().get(0);
{{/vendorExtensions.requiresMapper}}{{/required}}{{^required}}
{{#vendorExtensions.requiresMapper}}
var {{paramName}} = ({{paramName}}Part == null || {{paramName}}Part.values().isEmpty()) ? null : {{paramName}}Converter.read({{paramName}}Part.values().get(0));
{{/vendorExtensions.requiresMapper}}{{^vendorExtensions.requiresMapper}}
var {{paramName}} = ({{paramName}}Part == null || {{paramName}}Part.values().isEmpty()) ? null : {{paramName}}Part.values().get(0);
{{/vendorExtensions.requiresMapper}}{{/required}}
{{/isArray}}
{{/formParams}}
return new {{classname}}Controller.{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}FormParam(
{{#formParams}}{{paramName}}{{^-last}}, {{/-last}}{{/formParams}}
);
}){{#isBlocking}}.get(){{/isBlocking}};{{/vendorExtensions.urlEncodedForm}}{{#vendorExtensions.multipartForm}}
class {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}FormParamState {
{{#formParams}} @jakarta.annotation.Nullable
{{#isFile}} ru.tinkoff.kora.http.common.form.FormMultipart.FormPart.MultipartFile {{paramName}} = null;
{{/isFile}}{{^isFile}} {{{dataType}}} {{paramName}} = null;
{{/isFile}}{{/formParams}}
}
return MultipartReader.read(request)
.thenApply(parts -> {
var state = new {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}FormParamState();
for (var part : parts) {
switch (part.name()) {
default:
break;{{#formParams}}
case "{{baseName}}":
{{#isFile}} state.{{paramName}} = part;
break;
{{/isFile}}{{^isFile}} state.{{paramName}} = new String(part.content(), java.nio.charset.StandardCharsets.UTF_8);
break;
{{/isFile}}{{/formParams}}
}
}
{{#formParams}}{{#required}}
if (state.{{paramName}} == null) {
throw ru.tinkoff.kora.http.server.common.HttpServerResponseException.of(400, "Form key '{{baseName}}' is required");
}
{{/required}}{{/formParams}}
return new {{classname}}Controller.{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}FormParam(
{{#formParams}}state.{{paramName}}{{^-last}}, {{/-last}}{{/formParams}}
);
})
{{#isBlocking}}.toCompletableFuture().join(){{/isBlocking}};{{/vendorExtensions.multipartForm}}
}
}
{{/hasFormParams}}
{{/operation}}
{{/operations}}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy