JavaSpring.apiController.mustache Maven / Gradle / Ivy
package {{package}};
{{^jdk8}}
{{#imports}}import {{import}};
{{/imports}}
import io.swagger.annotations.*;
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.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}}
public {{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#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}}