apiController.mustache 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package {{package}};
  2. {{#imports}}import {{import}};
  3. {{/imports}}
  4. {{#_api_controller_impl_}}
  5. {{#swagger2AnnotationLibrary}}
  6. import io.swagger.v3.oas.annotations.Operation;
  7. import io.swagger.v3.oas.annotations.Parameter;
  8. import io.swagger.v3.oas.annotations.media.Content;
  9. import io.swagger.v3.oas.annotations.media.Schema;
  10. import io.swagger.v3.oas.annotations.responses.ApiResponse;
  11. import io.swagger.v3.oas.annotations.security.SecurityRequirement;
  12. import io.swagger.v3.oas.annotations.tags.Tag;
  13. {{/swagger2AnnotationLibrary}}
  14. {{#swagger1AnnotationLibrary}}
  15. import io.swagger.annotations.*;
  16. {{/swagger1AnnotationLibrary}}
  17. {{/_api_controller_impl_}}
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.http.HttpStatus;
  20. import org.springframework.http.MediaType;
  21. {{#useResponseEntity}}
  22. import org.springframework.http.ResponseEntity;
  23. import org.springframework.stereotype.Controller;
  24. import org.springframework.web.bind.annotation.RestController;
  25. {{/useResponseEntity}}
  26. {{^useResponseEntity}}
  27. import org.springframework.web.bind.annotation.RestController;
  28. {{/useResponseEntity}}
  29. import org.springframework.web.bind.annotation.PathVariable;
  30. import org.springframework.web.bind.annotation.RequestBody;
  31. import org.springframework.web.bind.annotation.RequestHeader;
  32. import org.springframework.web.bind.annotation.RequestMapping;
  33. import org.springframework.web.bind.annotation.CookieValue;
  34. import org.springframework.web.bind.annotation.RequestParam;
  35. import org.springframework.web.bind.annotation.RequestPart;
  36. import org.springframework.web.multipart.MultipartFile;
  37. {{^isDelegate}}
  38. import org.springframework.web.context.request.NativeWebRequest;
  39. {{/isDelegate}}
  40. {{#useBeanValidation}}
  41. import {{javaxPackage}}.validation.constraints.*;
  42. import {{javaxPackage}}.validation.Valid;
  43. {{/useBeanValidation}}
  44. import java.util.List;
  45. import java.util.Map;
  46. import java.util.Optional;
  47. import {{javaxPackage}}.annotation.Generated;
  48. import com.crunii.micro.common.dto.Result;
  49. {{>generatedAnnotation}}
  50. {{#useResponseEntity}}
  51. @RestController
  52. {{/useResponseEntity}}
  53. {{^useResponseEntity}}
  54. @RestController
  55. {{/useResponseEntity}}
  56. {{#useRequestMappingOnController}}
  57. {{=<% %>=}}
  58. @RequestMapping("${openapi.<%title%>.base-path:<%>defaultBasePath%>}")
  59. <%={{ }}=%>
  60. {{/useRequestMappingOnController}}
  61. {{#operations}}
  62. public class {{classname}}Controller implements {{classname}} {
  63. {{#isDelegate}}
  64. private final {{classname}}Delegate delegate;
  65. public {{classname}}Controller(@Autowired(required = false) {{classname}}Delegate delegate) {
  66. this.delegate = Optional.ofNullable(delegate).orElse(new {{classname}}Delegate() {});
  67. }
  68. @Override
  69. public {{classname}}Delegate getDelegate() {
  70. return delegate;
  71. }
  72. {{/isDelegate}}
  73. {{^isDelegate}}
  74. {{^reactive}}
  75. private final NativeWebRequest request;
  76. @Autowired
  77. public {{classname}}Controller(NativeWebRequest request) {
  78. this.request = request;
  79. }
  80. @Override
  81. public Optional<NativeWebRequest> getRequest() {
  82. return Optional.ofNullable(request);
  83. }
  84. {{/reactive}}
  85. {{/isDelegate}}
  86. {{#_api_controller_impl_}}
  87. {{#operation}}
  88. /**
  89. * {{httpMethod}} {{{path}}}{{#summary}} : {{.}}{{/summary}}
  90. {{#notes}}
  91. * {{.}}
  92. {{/notes}}
  93. *
  94. {{#allParams}}
  95. * @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}
  96. {{/allParams}}
  97. * @return {{#responses}}{{message}} (status code {{code}}){{^-last}}
  98. * or {{/-last}}{{/responses}}
  99. {{#isDeprecated}}
  100. * @deprecated
  101. {{/isDeprecated}}
  102. {{#externalDocs}}
  103. * {{description}}
  104. * @see <a href="{{url}}">{{summary}} Documentation</a>
  105. {{/externalDocs}}
  106. * @see {{classname}}#{{operationId}}
  107. */
  108. {{#isDeprecated}}
  109. @Deprecated
  110. {{/isDeprecated}}
  111. public {{#responseWrapper}}{{.}}<{{/responseWrapper}}{{#useResponseEntity}}Result<{{/useResponseEntity}}{{>returnTypes}}{{#useResponseEntity}}>{{/useResponseEntity}}{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}(
  112. {{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{>cookieParams}}{{^-last}},
  113. {{/-last}}{{/allParams}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}},
  114. {{/hasParams}}{{^hasParams}}{{#reactive}},{{/reactive}}{{/hasParams}}{{#springFoxDocumentationProvider}}@ApiIgnore {{/springFoxDocumentationProvider}}{{#springDocDocumentationProvider}}@ParameterObject {{/springDocDocumentationProvider}}final Pageable pageable{{/vendorExtensions.x-spring-paginated}}
  115. ) {
  116. {{^isDelegate}}
  117. {{^async}}
  118. {{>methodBody}}
  119. {{/async}}
  120. {{#async}}
  121. return new Callable<{{#useResponseEntity}}Result<{{/useResponseEntity}}{{>returnTypes}}{{#useResponseEntity}}>{{/useResponseEntity}}>() {
  122. @Override
  123. public {{#useResponseEntity}}Result<{{/useResponseEntity}}{{>returnTypes}}{{#useResponseEntity}}>{{/useResponseEntity}} call() {
  124. {{>methodBody}}
  125. }
  126. };
  127. {{/async}}
  128. {{/isDelegate}}
  129. {{#isDelegate}}
  130. {{^isVoid}}return {{/isVoid}}{{#isVoid}}{{#useResponseEntity}}return {{/useResponseEntity}}{{^useResponseEntity}}{{#reactive}}return {{/reactive}}{{/useResponseEntity}}{{/isVoid}}delegate.{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#reactive}}, {{/reactive}}{{/hasParams}}pageable{{/vendorExtensions.x-spring-paginated}});
  131. {{/isDelegate}}
  132. }
  133. {{/operation}}
  134. {{/_api_controller_impl_}}
  135. }
  136. {{/operations}}