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

openapi.templates.kora.javaClientRequestMappers.mustache Maven / Gradle / Ivy

There is a newer version: 1.1.16
Show newest version
package {{package}};

import ru.tinkoff.kora.http.client.common.form.UrlEncodedWriter;
import ru.tinkoff.kora.http.client.common.form.MultipartWriter;
import ru.tinkoff.kora.http.client.common.request.HttpClientRequestMapper;
import ru.tinkoff.kora.http.common.body.HttpBodyOutput;
import ru.tinkoff.kora.common.Context;

@ru.tinkoff.kora.common.annotation.Generated("openapi generator kora client"){{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}
public interface {{classname}}ClientRequestMappers {
{{#operations}}
{{#operation}}
{{#hasFormParams}}

  @ru.tinkoff.kora.common.annotation.Generated("openapi generator kora client")
  final class {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}FormParamRequestMapper implements HttpClientRequestMapper<{{classname}}.{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}FormParam> { {{#vendorExtensions.requiresFormParamMappers}}
    {{#vendorExtensions.formParamMappers}}
    private ru.tinkoff.kora.http.client.common.writer.StringParameterConverter<{{paramType}}> {{paramName}}Converter;
    {{/vendorExtensions.formParamMappers}}

    public {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}FormParamRequestMapper({{#vendorExtensions.formParamMappers}}{{#requireTag}}
      @{{mapperTag}}{{/requireTag}}
      ru.tinkoff.kora.http.client.common.writer.StringParameterConverter<{{paramType}}> {{paramName}}Converter{{^last}},{{/last}}
    {{/vendorExtensions.formParamMappers}}) {
    {{#vendorExtensions.formParamMappers}}
       this.{{paramName}}Converter = {{paramName}}Converter;
    {{/vendorExtensions.formParamMappers}}
    }

{{/vendorExtensions.requiresFormParamMappers}}

    @Override
    public HttpBodyOutput apply(Context ctx, {{classname}}.{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}FormParam value) throws Exception {
      {{#vendorExtensions.urlEncodedForm}}
      var b = new UrlEncodedWriter();{{#formParams}}
      if (value.{{paramName}}() != null) {
        {{#vendorExtensions.requiresMapper}}
        b.add("{{baseName}}", {{paramName}}Converter.convert(value.{{paramName}}()));
        {{/vendorExtensions.requiresMapper}}{{^vendorExtensions.requiresMapper}}
        b.add("{{baseName}}", java.util.Objects.toString(value.{{paramName}}()));
        {{/vendorExtensions.requiresMapper}}
      }
      {{/formParams}}
      return b.write();
      {{/vendorExtensions.urlEncodedForm}}{{#vendorExtensions.multipartForm}}
      var l = new java.util.ArrayList
      ();{{#formParams}}
              if (value.{{paramName}}() != null) {
          {{#isFile}}
                  var file = value.{{paramName}}();
                  l.add(file);
          {{/isFile}}{{^isFile}}
                  var buf = java.nio.charset.StandardCharsets.UTF_8.encode(java.util.Objects.toString(value.{{paramName}}()));
                  var part = ru.tinkoff.kora.http.common.form.FormMultipart.data(
                  "{{baseName}}",
                  java.util.Objects.toString(value.{{paramName}}())
                  );{{/isFile}}
      }
      {{/formParams}}
      return MultipartWriter.write(l);
      {{/vendorExtensions.multipartForm}}

    }
  }
{{/hasFormParams}}
{{/operation}}
{{/operations}}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy