methodBody.mustache 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. {{^reactive}}
  2. {{#examples}}
  3. {{#-first}}
  4. {{#async}}
  5. return CompletableFuture.supplyAsync(()-> {
  6. {{/async}}getRequest().ifPresent(request -> {
  7. {{#async}} {{/async}} for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
  8. {{/-first}}
  9. {{#async}} {{/async}}{{^async}} {{/async}} if (mediaType.isCompatibleWith(MediaType.valueOf("{{{contentType}}}"))) {
  10. {{#async}} {{/async}}{{^async}} {{/async}} String exampleString = {{>exampleString}};
  11. {{#async}} {{/async}}{{^async}} {{/async}} ApiUtil.setExampleResponse(request, "{{{contentType}}}", exampleString);
  12. {{#async}} {{/async}}{{^async}} {{/async}} break;
  13. {{#async}} {{/async}}{{^async}} {{/async}} }
  14. {{#-last}}
  15. {{#async}} {{/async}}{{^async}} {{/async}} }
  16. {{#async}} {{/async}} });
  17. {{#async}} {{/async}} {{#useResponseEntity}}return new Result<>({{#returnSuccessCode}}HttpStatus.valueOf({{{statusCode}}}){{/returnSuccessCode}}{{^returnSuccessCode}}HttpStatus.NOT_IMPLEMENTED{{/returnSuccessCode}});
  18. {{/useResponseEntity}}
  19. {{^useResponseEntity}}throw new IllegalArgumentException("Not implemented");
  20. {{/useResponseEntity}}
  21. {{#async}}
  22. }, Runnable::run);
  23. {{/async}}
  24. {{/-last}}
  25. {{/examples}}
  26. {{^examples}}
  27. {{#useResponseEntity}}return {{#async}}CompletableFuture.completedFuture({{/async}}new Result<>({{#returnSuccessCode}}HttpStatus.OK{{/returnSuccessCode}}{{^returnSuccessCode}}HttpStatus.NOT_IMPLEMENTED{{/returnSuccessCode}}){{#async}}){{/async}};
  28. {{/useResponseEntity}}
  29. {{^useResponseEntity}}throw new IllegalArgumentException("Not implemented");
  30. {{/useResponseEntity}}
  31. {{/examples}}
  32. {{/reactive}}
  33. {{#reactive}}
  34. Mono<Void> result = Mono.empty();
  35. {{#examples}}
  36. {{#-first}}
  37. exchange.getResponse().setStatusCode({{#returnSuccessCode}}HttpStatus.valueOf({{{statusCode}}}){{/returnSuccessCode}}{{^returnSuccessCode}}HttpStatus.NOT_IMPLEMENTED{{/returnSuccessCode}});
  38. for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) {
  39. {{/-first}}
  40. if (mediaType.isCompatibleWith(MediaType.valueOf("{{{contentType}}}"))) {
  41. String exampleString = {{>exampleString}};
  42. result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("{{{generatedContentType}}}"), exampleString);
  43. break;
  44. }
  45. {{#-last}}
  46. }
  47. {{/-last}}
  48. {{/examples}}
  49. {{^examples}}
  50. exchange.getResponse().setStatusCode({{#returnSuccessCode}}HttpStatus.OK{{/returnSuccessCode}}{{^returnSuccessCode}}HttpStatus.NOT_IMPLEMENTED{{/returnSuccessCode}});
  51. {{/examples}}
  52. return result{{#allParams}}{{#isBodyParam}}{{^isArray}}{{#paramName}}.then({{.}}){{/paramName}}{{/isArray}}{{#isArray}}{{#paramName}}.thenMany({{.}}){{/paramName}}{{/isArray}}{{/isBodyParam}}{{/allParams}}.then(Mono.empty());
  53. {{/reactive}}