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

JavaSpring.apiController.mustache Maven / Gradle / Ivy

package {{package}};

{{^jdk8}}
{{#imports}}import {{import}};
{{/imports}}
import io.swagger.v3.oas.annotations.*;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.*;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
{{/jdk8}}
import org.springframework.stereotype.Controller;
{{^jdk8}}
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
{{/jdk8}}
import org.springframework.web.bind.annotation.RequestMapping;
{{^jdk8}}
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
{{/jdk8}}
{{^isDelegate}}
import org.springframework.web.context.request.NativeWebRequest;
{{/isDelegate}}
{{^jdk8}}
import org.springframework.web.multipart.MultipartFile;

    {{#useBeanValidation}}
import javax.validation.constraints.*;
import javax.validation.Valid;
    {{/useBeanValidation}}
{{/jdk8}}
{{#jdk8}}
import java.util.Optional;
{{/jdk8}}
{{^jdk8}}
import java.util.List;
import java.util.Map;
    {{#async}}
import java.util.concurrent.Callable;
    {{/async}}
{{/jdk8}}
{{>generatedAnnotation}}
@Controller
{{=<% %>=}}
@RequestMapping("${openapi.<%title%>.base-path:<%>defaultBasePath%>}")
<%={{ }}=%>
{{#operations}}
public class {{classname}}Controller implements {{classname}} {
{{#isDelegate}}

    private final {{classname}}Delegate delegate;

    public {{classname}}Controller(@org.springframework.beans.factory.annotation.Autowired(required = false) {{classname}}Delegate delegate) {
    {{#jdk8}}
        this.delegate = Optional.ofNullable(delegate).orElse(new {{classname}}Delegate() {});
    }

    @Override
    public {{classname}}Delegate getDelegate() {
        return delegate;
    }
    {{/jdk8}}
    {{^jdk8}}
        this.delegate = delegate;
    }
    {{/jdk8}}
{{/isDelegate}}
{{^isDelegate}}
    {{^reactive}}

    {{^jdk8}}
    {{/jdk8}}
    private final NativeWebRequest request;

    @org.springframework.beans.factory.annotation.Autowired
    public {{classname}}Controller(NativeWebRequest request) {
        this.request = request;
    }
    {{#jdk8}}

    @Override
    public Optional getRequest() {
        return Optional.ofNullable(request);
    }
    {{/jdk8}}
    {{/reactive}}
{{/isDelegate}}

{{^jdk8}}
{{#operation}}
    /**
     * {{httpMethod}} {{{path}}}{{#summary}} : {{.}}{{/summary}}
    {{#notes}}
     * {{.}}
    {{/notes}}
     *
    {{#allParams}}
     * @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}
    {{/allParams}}
     * @return {{#responses}}{{message}} (status code {{code}}){{#hasMore}}
     *         or {{/hasMore}}{{/responses}}
    {{#isDeprecated}}
     * @deprecated
    {{/isDeprecated}}
    {{#externalDocs}}
     * {{description}}
     * @see {{summary}} Documentation
    {{/externalDocs}}
     * @see {{classname}}#{{operationId}}
     */
    public {{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{>cookieParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}) {
    {{^isDelegate}}
        {{^async}}
        {{>methodBody}}
        {{/async}}
        {{#async}}
        return new CallablereturnTypes}}>>() {
            @Override
            public ResponseEntity<{{>returnTypes}}> call() {
                {{>methodBody}}
            }
        };
        {{/async}}
    {{/isDelegate}}
    {{#isDelegate}}
        return delegate.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
    {{/isDelegate}}
    }

{{/operation}}
{{/jdk8}}
}
{{/operations}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy