From 825404a1dff9f7ddead2dc12bfcd28fb298e827e Mon Sep 17 00:00:00 2001 From: Christophe Bornet Date: Sat, 8 Sep 2018 15:51:05 +0200 Subject: [PATCH] [Spring] Fix reactive + delegatePattern option (#978) --- bin/springboot-petstore-server-reactive.sh | 2 +- .../main/resources/JavaSpring/api.mustache | 2 +- .../resources/JavaSpring/apiDelegate.mustache | 11 +- .../api/AnotherFakeApiDelegate.java | 2 +- .../org/openapitools/api/FakeApiDelegate.java | 68 +++--- .../api/FakeClassnameTestApiDelegate.java | 2 +- .../org/openapitools/api/PetApiDelegate.java | 24 +- .../openapitools/api/StoreApiDelegate.java | 6 +- .../org/openapitools/api/UserApiDelegate.java | 18 +- .../api/AnotherFakeApiDelegate.java | 2 +- .../org/openapitools/api/FakeApiDelegate.java | 68 +++--- .../api/FakeClassnameTestApiDelegate.java | 2 +- .../org/openapitools/api/PetApiDelegate.java | 24 +- .../openapitools/api/StoreApiDelegate.java | 6 +- .../org/openapitools/api/UserApiDelegate.java | 18 +- .../org/openapitools/api/AnotherFakeApi.java | 18 +- .../api/AnotherFakeApiController.java | 12 +- .../api/AnotherFakeApiDelegate.java | 46 ++++ .../java/org/openapitools/api/FakeApi.java | 103 ++------ .../openapitools/api/FakeApiController.java | 12 +- .../org/openapitools/api/FakeApiDelegate.java | 230 ++++++++++++++++++ .../api/FakeClassnameTestApi.java | 18 +- .../api/FakeClassnameTestApiController.java | 12 +- .../api/FakeClassnameTestApiDelegate.java | 46 ++++ .../java/org/openapitools/api/PetApi.java | 83 +------ .../openapitools/api/PetApiController.java | 12 +- .../org/openapitools/api/PetApiDelegate.java | 160 ++++++++++++ .../java/org/openapitools/api/StoreApi.java | 47 +--- .../openapitools/api/StoreApiController.java | 12 +- .../openapitools/api/StoreApiDelegate.java | 93 +++++++ .../java/org/openapitools/api/UserApi.java | 57 +---- .../openapitools/api/UserApiController.java | 12 +- .../org/openapitools/api/UserApiDelegate.java | 129 ++++++++++ 33 files changed, 958 insertions(+), 399 deletions(-) create mode 100644 samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/AnotherFakeApiDelegate.java create mode 100644 samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeApiDelegate.java create mode 100644 samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeClassnameTestApiDelegate.java create mode 100644 samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/PetApiDelegate.java create mode 100644 samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/StoreApiDelegate.java create mode 100644 samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/UserApiDelegate.java diff --git a/bin/springboot-petstore-server-reactive.sh b/bin/springboot-petstore-server-reactive.sh index 820daf1b8d6..f8936804ad2 100755 --- a/bin/springboot-petstore-server-reactive.sh +++ b/bin/springboot-petstore-server-reactive.sh @@ -26,7 +26,7 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate --artifact-id springboot-reactive -t modules/openapi-generator/src/main/resources/JavaSpring -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g spring -o samples/server/petstore/springboot-reactive -Dreactive=true,hideGenerationTimestamp=true $@" +ags="generate --artifact-id springboot-reactive -t modules/openapi-generator/src/main/resources/JavaSpring -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g spring -o samples/server/petstore/springboot-reactive -Dreactive=true,delegatePattern=true,hideGenerationTimestamp=true $@" echo "Removing files and folders under samples/server/petstore/springboot-reactive/src/main" rm -rf samples/server/petstore/springboot-reactive/src/main diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/api.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/api.mustache index 6736878e6f0..08bebd3a975 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/api.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/api.mustache @@ -121,7 +121,7 @@ public interface {{classname}} { {{>methodBody}} {{/isDelegate}} {{#isDelegate}} - return getDelegate().{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{#reactive}}, exchange{{/reactive}}); + return getDelegate().{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}exchange{{/reactive}}); {{/isDelegate}} }{{/jdk8}} diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/apiDelegate.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/apiDelegate.mustache index 45f31bd4e14..76bc71fbb33 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/apiDelegate.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/apiDelegate.mustache @@ -12,6 +12,11 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.context.request.NativeWebRequest; {{/jdk8}} import org.springframework.web.multipart.MultipartFile; +{{#reactive}} +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +{{/reactive}} import java.util.List; import java.util.Map; @@ -45,9 +50,9 @@ public interface {{classname}}Delegate { /** * @see {{classname}}#{{operationId}} */ - {{#jdk8}}default {{/jdk8}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{^isFile}} {{>optionalDataType}} {{/isFile}}{{#isFile}}MultipartFile{{/isFile}} {{paramName}}{{#hasMore}}, - {{/hasMore}}{{^hasMore}}{{#reactive}}, - {{/reactive}}{{/hasMore}}{{/allParams}}{{#reactive}}ServerWebExchange exchange{{/reactive}}){{^jdk8}};{{/jdk8}}{{#jdk8}} { + {{#jdk8}}default {{/jdk8}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{^isFile}}{{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{#isBodyParam}}{{^reactive}}{{{dataType}}}{{/reactive}}{{#reactive}}{{^isListContainer}}Mono{{/isListContainer}}{{#isListContainer}}Flux{{/isListContainer}}<{{{baseType}}}>{{/reactive}}{{/isBodyParam}}{{/isFile}}{{#isFile}}MultipartFile{{/isFile}} {{paramName}}{{#hasMore}}, + {{/hasMore}}{{/allParams}}{{#reactive}}{{#hasParams}}, + {{/hasParams}}ServerWebExchange exchange{{/reactive}}){{^jdk8}};{{/jdk8}}{{#jdk8}} { {{>methodBody}} }{{/jdk8}} diff --git a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/AnotherFakeApiDelegate.java b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/AnotherFakeApiDelegate.java index 4db33947735..597b34a8c3a 100644 --- a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/AnotherFakeApiDelegate.java +++ b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/AnotherFakeApiDelegate.java @@ -26,7 +26,7 @@ public interface AnotherFakeApiDelegate { /** * @see AnotherFakeApi#call123testSpecialTags */ - default ResponseEntity call123testSpecialTags( Client client) { + default ResponseEntity call123testSpecialTags(Client client) { getRequest().ifPresent(request -> { for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { diff --git a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/FakeApiDelegate.java b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/FakeApiDelegate.java index 6dfe4160b17..0ba0769182f 100644 --- a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/FakeApiDelegate.java +++ b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/FakeApiDelegate.java @@ -35,7 +35,7 @@ public interface FakeApiDelegate { /** * @see FakeApi#fakeOuterBooleanSerialize */ - default ResponseEntity fakeOuterBooleanSerialize( Boolean body) { + default ResponseEntity fakeOuterBooleanSerialize(Boolean body) { getRequest().ifPresent(request -> { for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) { @@ -51,7 +51,7 @@ public interface FakeApiDelegate { /** * @see FakeApi#fakeOuterCompositeSerialize */ - default ResponseEntity fakeOuterCompositeSerialize( OuterComposite outerComposite) { + default ResponseEntity fakeOuterCompositeSerialize(OuterComposite outerComposite) { getRequest().ifPresent(request -> { for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) { @@ -67,7 +67,7 @@ public interface FakeApiDelegate { /** * @see FakeApi#fakeOuterNumberSerialize */ - default ResponseEntity fakeOuterNumberSerialize( BigDecimal body) { + default ResponseEntity fakeOuterNumberSerialize(BigDecimal body) { getRequest().ifPresent(request -> { for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) { @@ -83,7 +83,7 @@ public interface FakeApiDelegate { /** * @see FakeApi#fakeOuterStringSerialize */ - default ResponseEntity fakeOuterStringSerialize( String body) { + default ResponseEntity fakeOuterStringSerialize(String body) { getRequest().ifPresent(request -> { for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) { @@ -99,7 +99,7 @@ public interface FakeApiDelegate { /** * @see FakeApi#testBodyWithFileSchema */ - default ResponseEntity testBodyWithFileSchema( FileSchemaTestClass fileSchemaTestClass) { + default ResponseEntity testBodyWithFileSchema(FileSchemaTestClass fileSchemaTestClass) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @@ -107,8 +107,8 @@ public interface FakeApiDelegate { /** * @see FakeApi#testBodyWithQueryParams */ - default ResponseEntity testBodyWithQueryParams( String query, - User user) { + default ResponseEntity testBodyWithQueryParams(String query, + User user) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @@ -116,7 +116,7 @@ public interface FakeApiDelegate { /** * @see FakeApi#testClientModel */ - default ResponseEntity testClientModel( Client client) { + default ResponseEntity testClientModel(Client client) { getRequest().ifPresent(request -> { for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { @@ -132,20 +132,20 @@ public interface FakeApiDelegate { /** * @see FakeApi#testEndpointParameters */ - default ResponseEntity testEndpointParameters( BigDecimal number, - Double _double, - String patternWithoutDelimiter, - byte[] _byte, - Integer integer, - Integer int32, - Long int64, - Float _float, - String string, + default ResponseEntity testEndpointParameters(BigDecimal number, + Double _double, + String patternWithoutDelimiter, + byte[] _byte, + Integer integer, + Integer int32, + Long int64, + Float _float, + String string, MultipartFile binary, - LocalDate date, - OffsetDateTime dateTime, - String password, - String paramCallback) { + LocalDate date, + OffsetDateTime dateTime, + String password, + String paramCallback) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @@ -153,14 +153,14 @@ public interface FakeApiDelegate { /** * @see FakeApi#testEnumParameters */ - default ResponseEntity testEnumParameters( List enumHeaderStringArray, - String enumHeaderString, - List enumQueryStringArray, - String enumQueryString, - Integer enumQueryInteger, - Double enumQueryDouble, - List enumFormStringArray, - String enumFormString) { + default ResponseEntity testEnumParameters(List enumHeaderStringArray, + String enumHeaderString, + List enumQueryStringArray, + String enumQueryString, + Integer enumQueryInteger, + Double enumQueryDouble, + List enumFormStringArray, + String enumFormString) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @@ -168,7 +168,7 @@ public interface FakeApiDelegate { /** * @see FakeApi#testInlineAdditionalProperties */ - default ResponseEntity testInlineAdditionalProperties( Map requestBody) { + default ResponseEntity testInlineAdditionalProperties(Map requestBody) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @@ -176,8 +176,8 @@ public interface FakeApiDelegate { /** * @see FakeApi#testJsonFormData */ - default ResponseEntity testJsonFormData( String param, - String param2) { + default ResponseEntity testJsonFormData(String param, + String param2) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @@ -185,9 +185,9 @@ public interface FakeApiDelegate { /** * @see FakeApi#uploadFileWithRequiredFile */ - default ResponseEntity uploadFileWithRequiredFile( Long petId, + default ResponseEntity uploadFileWithRequiredFile(Long petId, MultipartFile requiredFile, - String additionalMetadata) { + String additionalMetadata) { getRequest().ifPresent(request -> { for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { diff --git a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/FakeClassnameTestApiDelegate.java b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/FakeClassnameTestApiDelegate.java index 6cd8c3eb203..e94d222a6c7 100644 --- a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/FakeClassnameTestApiDelegate.java +++ b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/FakeClassnameTestApiDelegate.java @@ -26,7 +26,7 @@ public interface FakeClassnameTestApiDelegate { /** * @see FakeClassnameTestApi#testClassname */ - default ResponseEntity testClassname( Client client) { + default ResponseEntity testClassname(Client client) { getRequest().ifPresent(request -> { for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { diff --git a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/PetApiDelegate.java b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/PetApiDelegate.java index 88a778effd8..65c95bf1c1e 100644 --- a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/PetApiDelegate.java +++ b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/PetApiDelegate.java @@ -28,7 +28,7 @@ public interface PetApiDelegate { /** * @see PetApi#addPet */ - default ResponseEntity addPet( Pet pet) { + default ResponseEntity addPet(Pet pet) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @@ -36,8 +36,8 @@ public interface PetApiDelegate { /** * @see PetApi#deletePet */ - default ResponseEntity deletePet( Long petId, - String apiKey) { + default ResponseEntity deletePet(Long petId, + String apiKey) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @@ -45,7 +45,7 @@ public interface PetApiDelegate { /** * @see PetApi#findPetsByStatus */ - default ResponseEntity> findPetsByStatus( List status) { + default ResponseEntity> findPetsByStatus(List status) { getRequest().ifPresent(request -> { for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { @@ -65,7 +65,7 @@ public interface PetApiDelegate { /** * @see PetApi#findPetsByTags */ - default ResponseEntity> findPetsByTags( List tags) { + default ResponseEntity> findPetsByTags(List tags) { getRequest().ifPresent(request -> { for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { @@ -85,7 +85,7 @@ public interface PetApiDelegate { /** * @see PetApi#getPetById */ - default ResponseEntity getPetById( Long petId) { + default ResponseEntity getPetById(Long petId) { getRequest().ifPresent(request -> { for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { @@ -105,7 +105,7 @@ public interface PetApiDelegate { /** * @see PetApi#updatePet */ - default ResponseEntity updatePet( Pet pet) { + default ResponseEntity updatePet(Pet pet) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @@ -113,9 +113,9 @@ public interface PetApiDelegate { /** * @see PetApi#updatePetWithForm */ - default ResponseEntity updatePetWithForm( Long petId, - String name, - String status) { + default ResponseEntity updatePetWithForm(Long petId, + String name, + String status) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @@ -123,8 +123,8 @@ public interface PetApiDelegate { /** * @see PetApi#uploadFile */ - default ResponseEntity uploadFile( Long petId, - String additionalMetadata, + default ResponseEntity uploadFile(Long petId, + String additionalMetadata, MultipartFile file) { getRequest().ifPresent(request -> { for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { diff --git a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/StoreApiDelegate.java b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/StoreApiDelegate.java index c0a27ceb4ef..85a55dfcbda 100644 --- a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/StoreApiDelegate.java +++ b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/StoreApiDelegate.java @@ -27,7 +27,7 @@ public interface StoreApiDelegate { /** * @see StoreApi#deleteOrder */ - default ResponseEntity deleteOrder( String orderId) { + default ResponseEntity deleteOrder(String orderId) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @@ -43,7 +43,7 @@ public interface StoreApiDelegate { /** * @see StoreApi#getOrderById */ - default ResponseEntity getOrderById( Long orderId) { + default ResponseEntity getOrderById(Long orderId) { getRequest().ifPresent(request -> { for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { @@ -63,7 +63,7 @@ public interface StoreApiDelegate { /** * @see StoreApi#placeOrder */ - default ResponseEntity placeOrder( Order order) { + default ResponseEntity placeOrder(Order order) { getRequest().ifPresent(request -> { for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { diff --git a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/UserApiDelegate.java b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/UserApiDelegate.java index 1920c36711a..aaf9227ee56 100644 --- a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/UserApiDelegate.java +++ b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/UserApiDelegate.java @@ -27,7 +27,7 @@ public interface UserApiDelegate { /** * @see UserApi#createUser */ - default ResponseEntity createUser( User user) { + default ResponseEntity createUser(User user) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @@ -35,7 +35,7 @@ public interface UserApiDelegate { /** * @see UserApi#createUsersWithArrayInput */ - default ResponseEntity createUsersWithArrayInput( List user) { + default ResponseEntity createUsersWithArrayInput(List user) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @@ -43,7 +43,7 @@ public interface UserApiDelegate { /** * @see UserApi#createUsersWithListInput */ - default ResponseEntity createUsersWithListInput( List user) { + default ResponseEntity createUsersWithListInput(List user) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @@ -51,7 +51,7 @@ public interface UserApiDelegate { /** * @see UserApi#deleteUser */ - default ResponseEntity deleteUser( String username) { + default ResponseEntity deleteUser(String username) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @@ -59,7 +59,7 @@ public interface UserApiDelegate { /** * @see UserApi#getUserByName */ - default ResponseEntity getUserByName( String username) { + default ResponseEntity getUserByName(String username) { getRequest().ifPresent(request -> { for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { @@ -79,8 +79,8 @@ public interface UserApiDelegate { /** * @see UserApi#loginUser */ - default ResponseEntity loginUser( String username, - String password) { + default ResponseEntity loginUser(String username, + String password) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @@ -96,8 +96,8 @@ public interface UserApiDelegate { /** * @see UserApi#updateUser */ - default ResponseEntity updateUser( String username, - User user) { + default ResponseEntity updateUser(String username, + User user) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } diff --git a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/AnotherFakeApiDelegate.java b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/AnotherFakeApiDelegate.java index 569d1299b99..0e835519fc6 100644 --- a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/AnotherFakeApiDelegate.java +++ b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/AnotherFakeApiDelegate.java @@ -18,6 +18,6 @@ public interface AnotherFakeApiDelegate { /** * @see AnotherFakeApi#call123testSpecialTags */ - ResponseEntity call123testSpecialTags( Client client); + ResponseEntity call123testSpecialTags(Client client); } diff --git a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeApiDelegate.java b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeApiDelegate.java index 48963d95265..0d6eb018765 100644 --- a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeApiDelegate.java +++ b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeApiDelegate.java @@ -27,85 +27,85 @@ public interface FakeApiDelegate { /** * @see FakeApi#fakeOuterBooleanSerialize */ - ResponseEntity fakeOuterBooleanSerialize( Boolean body); + ResponseEntity fakeOuterBooleanSerialize(Boolean body); /** * @see FakeApi#fakeOuterCompositeSerialize */ - ResponseEntity fakeOuterCompositeSerialize( OuterComposite outerComposite); + ResponseEntity fakeOuterCompositeSerialize(OuterComposite outerComposite); /** * @see FakeApi#fakeOuterNumberSerialize */ - ResponseEntity fakeOuterNumberSerialize( BigDecimal body); + ResponseEntity fakeOuterNumberSerialize(BigDecimal body); /** * @see FakeApi#fakeOuterStringSerialize */ - ResponseEntity fakeOuterStringSerialize( String body); + ResponseEntity fakeOuterStringSerialize(String body); /** * @see FakeApi#testBodyWithFileSchema */ - ResponseEntity testBodyWithFileSchema( FileSchemaTestClass fileSchemaTestClass); + ResponseEntity testBodyWithFileSchema(FileSchemaTestClass fileSchemaTestClass); /** * @see FakeApi#testBodyWithQueryParams */ - ResponseEntity testBodyWithQueryParams( String query, - User user); + ResponseEntity testBodyWithQueryParams(String query, + User user); /** * @see FakeApi#testClientModel */ - ResponseEntity testClientModel( Client client); + ResponseEntity testClientModel(Client client); /** * @see FakeApi#testEndpointParameters */ - ResponseEntity testEndpointParameters( BigDecimal number, - Double _double, - String patternWithoutDelimiter, - byte[] _byte, - Integer integer, - Integer int32, - Long int64, - Float _float, - String string, + ResponseEntity testEndpointParameters(BigDecimal number, + Double _double, + String patternWithoutDelimiter, + byte[] _byte, + Integer integer, + Integer int32, + Long int64, + Float _float, + String string, MultipartFile binary, - LocalDate date, - OffsetDateTime dateTime, - String password, - String paramCallback); + LocalDate date, + OffsetDateTime dateTime, + String password, + String paramCallback); /** * @see FakeApi#testEnumParameters */ - ResponseEntity testEnumParameters( List enumHeaderStringArray, - String enumHeaderString, - List enumQueryStringArray, - String enumQueryString, - Integer enumQueryInteger, - Double enumQueryDouble, - List enumFormStringArray, - String enumFormString); + ResponseEntity testEnumParameters(List enumHeaderStringArray, + String enumHeaderString, + List enumQueryStringArray, + String enumQueryString, + Integer enumQueryInteger, + Double enumQueryDouble, + List enumFormStringArray, + String enumFormString); /** * @see FakeApi#testInlineAdditionalProperties */ - ResponseEntity testInlineAdditionalProperties( Map requestBody); + ResponseEntity testInlineAdditionalProperties(Map requestBody); /** * @see FakeApi#testJsonFormData */ - ResponseEntity testJsonFormData( String param, - String param2); + ResponseEntity testJsonFormData(String param, + String param2); /** * @see FakeApi#uploadFileWithRequiredFile */ - ResponseEntity uploadFileWithRequiredFile( Long petId, + ResponseEntity uploadFileWithRequiredFile(Long petId, MultipartFile requiredFile, - String additionalMetadata); + String additionalMetadata); } diff --git a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeClassnameTestApiDelegate.java b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeClassnameTestApiDelegate.java index c81f614a811..c0d42c3a3e7 100644 --- a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeClassnameTestApiDelegate.java +++ b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeClassnameTestApiDelegate.java @@ -18,6 +18,6 @@ public interface FakeClassnameTestApiDelegate { /** * @see FakeClassnameTestApi#testClassname */ - ResponseEntity testClassname( Client client); + ResponseEntity testClassname(Client client); } diff --git a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/PetApiDelegate.java b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/PetApiDelegate.java index 13f6acf44c7..bae746c1414 100644 --- a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/PetApiDelegate.java +++ b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/PetApiDelegate.java @@ -20,46 +20,46 @@ public interface PetApiDelegate { /** * @see PetApi#addPet */ - ResponseEntity addPet( Pet pet); + ResponseEntity addPet(Pet pet); /** * @see PetApi#deletePet */ - ResponseEntity deletePet( Long petId, - String apiKey); + ResponseEntity deletePet(Long petId, + String apiKey); /** * @see PetApi#findPetsByStatus */ - ResponseEntity> findPetsByStatus( List status); + ResponseEntity> findPetsByStatus(List status); /** * @see PetApi#findPetsByTags */ - ResponseEntity> findPetsByTags( List tags); + ResponseEntity> findPetsByTags(List tags); /** * @see PetApi#getPetById */ - ResponseEntity getPetById( Long petId); + ResponseEntity getPetById(Long petId); /** * @see PetApi#updatePet */ - ResponseEntity updatePet( Pet pet); + ResponseEntity updatePet(Pet pet); /** * @see PetApi#updatePetWithForm */ - ResponseEntity updatePetWithForm( Long petId, - String name, - String status); + ResponseEntity updatePetWithForm(Long petId, + String name, + String status); /** * @see PetApi#uploadFile */ - ResponseEntity uploadFile( Long petId, - String additionalMetadata, + ResponseEntity uploadFile(Long petId, + String additionalMetadata, MultipartFile file); } diff --git a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/StoreApiDelegate.java b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/StoreApiDelegate.java index 1967f371327..6fa60ee6c17 100644 --- a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/StoreApiDelegate.java +++ b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/StoreApiDelegate.java @@ -19,7 +19,7 @@ public interface StoreApiDelegate { /** * @see StoreApi#deleteOrder */ - ResponseEntity deleteOrder( String orderId); + ResponseEntity deleteOrder(String orderId); /** * @see StoreApi#getInventory @@ -29,11 +29,11 @@ public interface StoreApiDelegate { /** * @see StoreApi#getOrderById */ - ResponseEntity getOrderById( Long orderId); + ResponseEntity getOrderById(Long orderId); /** * @see StoreApi#placeOrder */ - ResponseEntity placeOrder( Order order); + ResponseEntity placeOrder(Order order); } diff --git a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/UserApiDelegate.java b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/UserApiDelegate.java index 1aefe4ec201..70404052360 100644 --- a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/UserApiDelegate.java +++ b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/UserApiDelegate.java @@ -19,33 +19,33 @@ public interface UserApiDelegate { /** * @see UserApi#createUser */ - ResponseEntity createUser( User user); + ResponseEntity createUser(User user); /** * @see UserApi#createUsersWithArrayInput */ - ResponseEntity createUsersWithArrayInput( List user); + ResponseEntity createUsersWithArrayInput(List user); /** * @see UserApi#createUsersWithListInput */ - ResponseEntity createUsersWithListInput( List user); + ResponseEntity createUsersWithListInput(List user); /** * @see UserApi#deleteUser */ - ResponseEntity deleteUser( String username); + ResponseEntity deleteUser(String username); /** * @see UserApi#getUserByName */ - ResponseEntity getUserByName( String username); + ResponseEntity getUserByName(String username); /** * @see UserApi#loginUser */ - ResponseEntity loginUser( String username, - String password); + ResponseEntity loginUser(String username, + String password); /** * @see UserApi#logoutUser @@ -55,7 +55,7 @@ public interface UserApiDelegate { /** * @see UserApi#updateUser */ - ResponseEntity updateUser( String username, - User user); + ResponseEntity updateUser(String username, + User user); } diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/AnotherFakeApi.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/AnotherFakeApi.java index bc85f007ea5..3b15b7d64ef 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/AnotherFakeApi.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/AnotherFakeApi.java @@ -7,8 +7,6 @@ package org.openapitools.api; import org.openapitools.model.Client; import io.swagger.annotations.*; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PathVariable; @@ -27,12 +25,15 @@ import javax.validation.Valid; import javax.validation.constraints.*; import java.util.List; import java.util.Map; -import java.util.Optional; @Validated @Api(value = "another-fake", description = "the another-fake API") public interface AnotherFakeApi { + default AnotherFakeApiDelegate getDelegate() { + return new AnotherFakeApiDelegate() {}; + } + @ApiOperation(value = "To test special tags", nickname = "call123testSpecialTags", notes = "To test special tags and operation ID starting with number", response = Client.class, tags={ "$another-fake?", }) @ApiResponses(value = { @ApiResponse(code = 200, message = "successful operation", response = Client.class) }) @@ -41,16 +42,7 @@ public interface AnotherFakeApi { consumes = { "application/json" }, method = RequestMethod.PATCH) default Mono> call123testSpecialTags(@ApiParam(value = "client model" ,required=true ) @Valid @RequestBody Mono client, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - result = ApiUtil.getExampleResponse(exchange, "{ \"client\" : \"client\"}"); - break; - } - } - return result.then(Mono.empty()); - + return getDelegate().call123testSpecialTags(client, exchange); } } diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/AnotherFakeApiController.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/AnotherFakeApiController.java index 997ef4798bb..3bc2df15df6 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/AnotherFakeApiController.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/AnotherFakeApiController.java @@ -2,11 +2,21 @@ package org.openapitools.api; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.context.request.NativeWebRequest; import java.util.Optional; @Controller @RequestMapping("${openapi.openAPIPetstore.base-path:/v2}") public class AnotherFakeApiController implements AnotherFakeApi { + private final AnotherFakeApiDelegate delegate; + + public AnotherFakeApiController(@org.springframework.beans.factory.annotation.Autowired(required = false) AnotherFakeApiDelegate delegate) { + this.delegate = Optional.ofNullable(delegate).orElse(new AnotherFakeApiDelegate() {}); + } + + @Override + public AnotherFakeApiDelegate getDelegate() { + return delegate; + } + } diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/AnotherFakeApiDelegate.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/AnotherFakeApiDelegate.java new file mode 100644 index 00000000000..ddc7c2a0e8f --- /dev/null +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/AnotherFakeApiDelegate.java @@ -0,0 +1,46 @@ +package org.openapitools.api; + +import org.openapitools.model.Client; +import io.swagger.annotations.*; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** + * A delegate to be called by the {@link AnotherFakeApiController}}. + * Implement this interface with a {@link org.springframework.stereotype.Service} annotated class. + */ + +public interface AnotherFakeApiDelegate { + + default Optional getRequest() { + return Optional.empty(); + } + + /** + * @see AnotherFakeApi#call123testSpecialTags + */ + default Mono> call123testSpecialTags(Mono client, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + result = ApiUtil.getExampleResponse(exchange, "{ \"client\" : \"client\"}"); + break; + } + } + return result.then(Mono.empty()); + + } + +} diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeApi.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeApi.java index 928e0e031f4..45ff9ab452c 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeApi.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeApi.java @@ -16,8 +16,6 @@ import org.openapitools.model.OuterComposite; import org.springframework.core.io.Resource; import org.openapitools.model.User; import io.swagger.annotations.*; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PathVariable; @@ -36,12 +34,15 @@ import javax.validation.Valid; import javax.validation.constraints.*; import java.util.List; import java.util.Map; -import java.util.Optional; @Validated @Api(value = "fake", description = "the fake API") public interface FakeApi { + default FakeApiDelegate getDelegate() { + return new FakeApiDelegate() {}; + } + @ApiOperation(value = "", nickname = "fakeOuterBooleanSerialize", notes = "Test serialization of outer boolean types", response = Boolean.class, tags={ "fake", }) @ApiResponses(value = { @ApiResponse(code = 200, message = "Output boolean", response = Boolean.class) }) @@ -49,16 +50,7 @@ public interface FakeApi { produces = { "*/*" }, method = RequestMethod.POST) default Mono> fakeOuterBooleanSerialize(@ApiParam(value = "Input boolean as post body" ) @Valid @RequestBody Mono body, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { - if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) { - result = ApiUtil.getExampleResponse(exchange, "null"); - break; - } - } - return result.then(Mono.empty()); - + return getDelegate().fakeOuterBooleanSerialize(body, exchange); } @@ -69,16 +61,7 @@ public interface FakeApi { produces = { "*/*" }, method = RequestMethod.POST) default Mono> fakeOuterCompositeSerialize(@ApiParam(value = "Input composite as post body" ) @Valid @RequestBody Mono outerComposite, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { - if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) { - result = ApiUtil.getExampleResponse(exchange, "{ \"my_string\" : \"my_string\", \"my_number\" : 0.80082819046101150206595775671303272247314453125, \"my_boolean\" : true}"); - break; - } - } - return result.then(Mono.empty()); - + return getDelegate().fakeOuterCompositeSerialize(outerComposite, exchange); } @@ -89,16 +72,7 @@ public interface FakeApi { produces = { "*/*" }, method = RequestMethod.POST) default Mono> fakeOuterNumberSerialize(@ApiParam(value = "Input number as post body" ) @Valid @RequestBody Mono body, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { - if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) { - result = ApiUtil.getExampleResponse(exchange, "null"); - break; - } - } - return result.then(Mono.empty()); - + return getDelegate().fakeOuterNumberSerialize(body, exchange); } @@ -109,16 +83,7 @@ public interface FakeApi { produces = { "*/*" }, method = RequestMethod.POST) default Mono> fakeOuterStringSerialize(@ApiParam(value = "Input string as post body" ) @Valid @RequestBody Mono body, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { - if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) { - result = ApiUtil.getExampleResponse(exchange, "null"); - break; - } - } - return result.then(Mono.empty()); - + return getDelegate().fakeOuterStringSerialize(body, exchange); } @@ -129,10 +94,7 @@ public interface FakeApi { consumes = { "application/json" }, method = RequestMethod.PUT) default Mono> testBodyWithFileSchema(@ApiParam(value = "" ,required=true ) @Valid @RequestBody Mono fileSchemaTestClass, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - return result.then(Mono.empty()); - + return getDelegate().testBodyWithFileSchema(fileSchemaTestClass, exchange); } @@ -143,10 +105,7 @@ public interface FakeApi { consumes = { "application/json" }, method = RequestMethod.PUT) default Mono> testBodyWithQueryParams(@NotNull @ApiParam(value = "", required = true) @Valid @RequestParam(value = "query", required = true) String query,@ApiParam(value = "" ,required=true ) @Valid @RequestBody Mono user, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - return result.then(Mono.empty()); - + return getDelegate().testBodyWithQueryParams(query, user, exchange); } @@ -158,16 +117,7 @@ public interface FakeApi { consumes = { "application/json" }, method = RequestMethod.PATCH) default Mono> testClientModel(@ApiParam(value = "client model" ,required=true ) @Valid @RequestBody Mono client, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - result = ApiUtil.getExampleResponse(exchange, "{ \"client\" : \"client\"}"); - break; - } - } - return result.then(Mono.empty()); - + return getDelegate().testClientModel(client, exchange); } @@ -181,10 +131,7 @@ public interface FakeApi { consumes = { "application/x-www-form-urlencoded" }, method = RequestMethod.POST) default Mono> testEndpointParameters(@ApiParam(value = "None", required=true, defaultValue="null") @RequestParam(value="number", required=true) BigDecimal number,@ApiParam(value = "None", required=true, defaultValue="null") @RequestParam(value="double", required=true) Double _double,@ApiParam(value = "None", required=true, defaultValue="null") @RequestParam(value="pattern_without_delimiter", required=true) String patternWithoutDelimiter,@ApiParam(value = "None", required=true, defaultValue="null") @RequestParam(value="byte", required=true) byte[] _byte,@ApiParam(value = "None", defaultValue="null") @RequestParam(value="integer", required=false) Integer integer,@ApiParam(value = "None", defaultValue="null") @RequestParam(value="int32", required=false) Integer int32,@ApiParam(value = "None", defaultValue="null") @RequestParam(value="int64", required=false) Long int64,@ApiParam(value = "None", defaultValue="null") @RequestParam(value="float", required=false) Float _float,@ApiParam(value = "None", defaultValue="null") @RequestParam(value="string", required=false) String string,@ApiParam(value = "file detail") @Valid @RequestPart("file") MultipartFile binary,@ApiParam(value = "None", defaultValue="null") @RequestParam(value="date", required=false) LocalDate date,@ApiParam(value = "None", defaultValue="null") @RequestParam(value="dateTime", required=false) OffsetDateTime dateTime,@ApiParam(value = "None", defaultValue="null") @RequestParam(value="password", required=false) String password,@ApiParam(value = "None", defaultValue="null") @RequestParam(value="callback", required=false) String paramCallback, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - return result.then(Mono.empty()); - + return getDelegate().testEndpointParameters(number, _double, patternWithoutDelimiter, _byte, integer, int32, int64, _float, string, binary, date, dateTime, password, paramCallback, exchange); } @@ -196,10 +143,7 @@ public interface FakeApi { consumes = { "application/x-www-form-urlencoded" }, method = RequestMethod.GET) default Mono> testEnumParameters(@ApiParam(value = "Header parameter enum test (string array)" , allowableValues=">, $") @RequestHeader(value="enum_header_string_array", required=false) List enumHeaderStringArray,@ApiParam(value = "Header parameter enum test (string)" , allowableValues="_abc, -efg, (xyz)", defaultValue="-efg") @RequestHeader(value="enum_header_string", required=false) String enumHeaderString,@ApiParam(value = "Query parameter enum test (string array)", allowableValues = ">, $") @Valid @RequestParam(value = "enum_query_string_array", required = false) List enumQueryStringArray,@ApiParam(value = "Query parameter enum test (string)", allowableValues = "_abc, -efg, (xyz)", defaultValue = "-efg") @Valid @RequestParam(value = "enum_query_string", required = false, defaultValue="-efg") String enumQueryString,@ApiParam(value = "Query parameter enum test (double)", allowableValues = "1, -2") @Valid @RequestParam(value = "enum_query_integer", required = false) Integer enumQueryInteger,@ApiParam(value = "Query parameter enum test (double)", allowableValues = "1.1, -1.2") @Valid @RequestParam(value = "enum_query_double", required = false) Double enumQueryDouble,@ApiParam(value = "Form parameter enum test (string array)", allowableValues=">, $", defaultValue="$") @RequestParam(value="enum_form_string_array", required=false) List enumFormStringArray,@ApiParam(value = "Form parameter enum test (string)", allowableValues="_abc, -efg, (xyz)", defaultValue="-efg") @RequestParam(value="enum_form_string", required=false) String enumFormString, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - return result.then(Mono.empty()); - + return getDelegate().testEnumParameters(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumFormStringArray, enumFormString, exchange); } @@ -210,10 +154,7 @@ public interface FakeApi { consumes = { "application/json" }, method = RequestMethod.POST) default Mono> testInlineAdditionalProperties(@ApiParam(value = "request body" ,required=true ) @Valid @RequestBody Mono requestBody, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - return result.then(Mono.empty()); - + return getDelegate().testInlineAdditionalProperties(requestBody, exchange); } @@ -224,10 +165,7 @@ public interface FakeApi { consumes = { "application/x-www-form-urlencoded" }, method = RequestMethod.GET) default Mono> testJsonFormData(@ApiParam(value = "field1", required=true, defaultValue="null") @RequestParam(value="param", required=true) String param,@ApiParam(value = "field2", required=true, defaultValue="null") @RequestParam(value="param2", required=true) String param2, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - return result.then(Mono.empty()); - + return getDelegate().testJsonFormData(param, param2, exchange); } @@ -244,16 +182,7 @@ public interface FakeApi { consumes = { "multipart/form-data" }, method = RequestMethod.POST) default Mono> uploadFileWithRequiredFile(@ApiParam(value = "ID of pet to update",required=true) @PathVariable("petId") Long petId,@ApiParam(value = "file detail") @Valid @RequestPart("file") MultipartFile requiredFile,@ApiParam(value = "Additional data to pass to server", defaultValue="null") @RequestParam(value="additionalMetadata", required=false) String additionalMetadata, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - result = ApiUtil.getExampleResponse(exchange, "{ \"code\" : 0, \"type\" : \"type\", \"message\" : \"message\"}"); - break; - } - } - return result.then(Mono.empty()); - + return getDelegate().uploadFileWithRequiredFile(petId, requiredFile, additionalMetadata, exchange); } } diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeApiController.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeApiController.java index 9d4b5917508..75c4b5587be 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeApiController.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeApiController.java @@ -2,11 +2,21 @@ package org.openapitools.api; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.context.request.NativeWebRequest; import java.util.Optional; @Controller @RequestMapping("${openapi.openAPIPetstore.base-path:/v2}") public class FakeApiController implements FakeApi { + private final FakeApiDelegate delegate; + + public FakeApiController(@org.springframework.beans.factory.annotation.Autowired(required = false) FakeApiDelegate delegate) { + this.delegate = Optional.ofNullable(delegate).orElse(new FakeApiDelegate() {}); + } + + @Override + public FakeApiDelegate getDelegate() { + return delegate; + } + } diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeApiDelegate.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeApiDelegate.java new file mode 100644 index 00000000000..b7c338d094f --- /dev/null +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeApiDelegate.java @@ -0,0 +1,230 @@ +package org.openapitools.api; + +import java.math.BigDecimal; +import org.openapitools.model.Client; +import org.openapitools.model.FileSchemaTestClass; +import java.time.LocalDate; +import java.util.Map; +import org.openapitools.model.ModelApiResponse; +import java.time.OffsetDateTime; +import org.openapitools.model.OuterComposite; +import org.springframework.core.io.Resource; +import org.openapitools.model.User; +import io.swagger.annotations.*; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** + * A delegate to be called by the {@link FakeApiController}}. + * Implement this interface with a {@link org.springframework.stereotype.Service} annotated class. + */ + +public interface FakeApiDelegate { + + default Optional getRequest() { + return Optional.empty(); + } + + /** + * @see FakeApi#fakeOuterBooleanSerialize + */ + default Mono> fakeOuterBooleanSerialize(Mono body, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { + if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) { + result = ApiUtil.getExampleResponse(exchange, "null"); + break; + } + } + return result.then(Mono.empty()); + + } + + /** + * @see FakeApi#fakeOuterCompositeSerialize + */ + default Mono> fakeOuterCompositeSerialize(Mono outerComposite, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { + if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) { + result = ApiUtil.getExampleResponse(exchange, "{ \"my_string\" : \"my_string\", \"my_number\" : 0.80082819046101150206595775671303272247314453125, \"my_boolean\" : true}"); + break; + } + } + return result.then(Mono.empty()); + + } + + /** + * @see FakeApi#fakeOuterNumberSerialize + */ + default Mono> fakeOuterNumberSerialize(Mono body, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { + if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) { + result = ApiUtil.getExampleResponse(exchange, "null"); + break; + } + } + return result.then(Mono.empty()); + + } + + /** + * @see FakeApi#fakeOuterStringSerialize + */ + default Mono> fakeOuterStringSerialize(Mono body, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { + if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) { + result = ApiUtil.getExampleResponse(exchange, "null"); + break; + } + } + return result.then(Mono.empty()); + + } + + /** + * @see FakeApi#testBodyWithFileSchema + */ + default Mono> testBodyWithFileSchema(Mono fileSchemaTestClass, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + return result.then(Mono.empty()); + + } + + /** + * @see FakeApi#testBodyWithQueryParams + */ + default Mono> testBodyWithQueryParams(String query, + Mono user, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + return result.then(Mono.empty()); + + } + + /** + * @see FakeApi#testClientModel + */ + default Mono> testClientModel(Mono client, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + result = ApiUtil.getExampleResponse(exchange, "{ \"client\" : \"client\"}"); + break; + } + } + return result.then(Mono.empty()); + + } + + /** + * @see FakeApi#testEndpointParameters + */ + default Mono> testEndpointParameters(BigDecimal number, + Double _double, + String patternWithoutDelimiter, + byte[] _byte, + Integer integer, + Integer int32, + Long int64, + Float _float, + String string, + MultipartFile binary, + LocalDate date, + OffsetDateTime dateTime, + String password, + String paramCallback, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + return result.then(Mono.empty()); + + } + + /** + * @see FakeApi#testEnumParameters + */ + default Mono> testEnumParameters(List enumHeaderStringArray, + String enumHeaderString, + List enumQueryStringArray, + String enumQueryString, + Integer enumQueryInteger, + Double enumQueryDouble, + List enumFormStringArray, + String enumFormString, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + return result.then(Mono.empty()); + + } + + /** + * @see FakeApi#testInlineAdditionalProperties + */ + default Mono> testInlineAdditionalProperties(Mono requestBody, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + return result.then(Mono.empty()); + + } + + /** + * @see FakeApi#testJsonFormData + */ + default Mono> testJsonFormData(String param, + String param2, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + return result.then(Mono.empty()); + + } + + /** + * @see FakeApi#uploadFileWithRequiredFile + */ + default Mono> uploadFileWithRequiredFile(Long petId, + MultipartFile requiredFile, + String additionalMetadata, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + result = ApiUtil.getExampleResponse(exchange, "{ \"code\" : 0, \"type\" : \"type\", \"message\" : \"message\"}"); + break; + } + } + return result.then(Mono.empty()); + + } + +} diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeClassnameTestApi.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeClassnameTestApi.java index 7588711e585..edc63ea5b8d 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeClassnameTestApi.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeClassnameTestApi.java @@ -7,8 +7,6 @@ package org.openapitools.api; import org.openapitools.model.Client; import io.swagger.annotations.*; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PathVariable; @@ -27,12 +25,15 @@ import javax.validation.Valid; import javax.validation.constraints.*; import java.util.List; import java.util.Map; -import java.util.Optional; @Validated @Api(value = "fake_classname_test", description = "the fake_classname_test API") public interface FakeClassnameTestApi { + default FakeClassnameTestApiDelegate getDelegate() { + return new FakeClassnameTestApiDelegate() {}; + } + @ApiOperation(value = "To test class name in snake case", nickname = "testClassname", notes = "To test class name in snake case", response = Client.class, authorizations = { @Authorization(value = "api_key_query") }, tags={ "fake_classname_tags 123#$%^", }) @@ -43,16 +44,7 @@ public interface FakeClassnameTestApi { consumes = { "application/json" }, method = RequestMethod.PATCH) default Mono> testClassname(@ApiParam(value = "client model" ,required=true ) @Valid @RequestBody Mono client, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - result = ApiUtil.getExampleResponse(exchange, "{ \"client\" : \"client\"}"); - break; - } - } - return result.then(Mono.empty()); - + return getDelegate().testClassname(client, exchange); } } diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeClassnameTestApiController.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeClassnameTestApiController.java index 905d8b60bd7..6566359e66f 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeClassnameTestApiController.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeClassnameTestApiController.java @@ -2,11 +2,21 @@ package org.openapitools.api; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.context.request.NativeWebRequest; import java.util.Optional; @Controller @RequestMapping("${openapi.openAPIPetstore.base-path:/v2}") public class FakeClassnameTestApiController implements FakeClassnameTestApi { + private final FakeClassnameTestApiDelegate delegate; + + public FakeClassnameTestApiController(@org.springframework.beans.factory.annotation.Autowired(required = false) FakeClassnameTestApiDelegate delegate) { + this.delegate = Optional.ofNullable(delegate).orElse(new FakeClassnameTestApiDelegate() {}); + } + + @Override + public FakeClassnameTestApiDelegate getDelegate() { + return delegate; + } + } diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeClassnameTestApiDelegate.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeClassnameTestApiDelegate.java new file mode 100644 index 00000000000..bffd475ef6b --- /dev/null +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeClassnameTestApiDelegate.java @@ -0,0 +1,46 @@ +package org.openapitools.api; + +import org.openapitools.model.Client; +import io.swagger.annotations.*; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** + * A delegate to be called by the {@link FakeClassnameTestApiController}}. + * Implement this interface with a {@link org.springframework.stereotype.Service} annotated class. + */ + +public interface FakeClassnameTestApiDelegate { + + default Optional getRequest() { + return Optional.empty(); + } + + /** + * @see FakeClassnameTestApi#testClassname + */ + default Mono> testClassname(Mono client, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + result = ApiUtil.getExampleResponse(exchange, "{ \"client\" : \"client\"}"); + break; + } + } + return result.then(Mono.empty()); + + } + +} diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/PetApi.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/PetApi.java index 150a6658bf1..1fa5b4235c8 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/PetApi.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/PetApi.java @@ -9,8 +9,6 @@ import org.openapitools.model.ModelApiResponse; import org.openapitools.model.Pet; import org.springframework.core.io.Resource; import io.swagger.annotations.*; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PathVariable; @@ -29,12 +27,15 @@ import javax.validation.Valid; import javax.validation.constraints.*; import java.util.List; import java.util.Map; -import java.util.Optional; @Validated @Api(value = "pet", description = "the pet API") public interface PetApi { + default PetApiDelegate getDelegate() { + return new PetApiDelegate() {}; + } + @ApiOperation(value = "Add a new pet to the store", nickname = "addPet", notes = "", authorizations = { @Authorization(value = "petstore_auth", scopes = { @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), @@ -47,10 +48,7 @@ public interface PetApi { consumes = { "application/json", "application/xml" }, method = RequestMethod.POST) default Mono> addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody Mono pet, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - return result.then(Mono.empty()); - + return getDelegate().addPet(pet, exchange); } @@ -65,10 +63,7 @@ public interface PetApi { @RequestMapping(value = "/pet/{petId}", method = RequestMethod.DELETE) default Mono> deletePet(@ApiParam(value = "Pet id to delete",required=true) @PathVariable("petId") Long petId,@ApiParam(value = "" ) @RequestHeader(value="api_key", required=false) String apiKey, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - return result.then(Mono.empty()); - + return getDelegate().deletePet(petId, apiKey, exchange); } @@ -85,20 +80,7 @@ public interface PetApi { produces = { "application/xml", "application/json" }, method = RequestMethod.GET) default Mono>> findPetsByStatus(@NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @Valid @RequestParam(value = "status", required = true) List status, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - result = ApiUtil.getExampleResponse(exchange, "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\"}"); - break; - } - if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { - result = ApiUtil.getExampleResponse(exchange, " 123456789 doggie aeiou aeiou"); - break; - } - } - return result.then(Mono.empty()); - + return getDelegate().findPetsByStatus(status, exchange); } @@ -115,20 +97,7 @@ public interface PetApi { produces = { "application/xml", "application/json" }, method = RequestMethod.GET) default Mono>> findPetsByTags(@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) List tags, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - result = ApiUtil.getExampleResponse(exchange, "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\"}"); - break; - } - if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { - result = ApiUtil.getExampleResponse(exchange, " 123456789 doggie aeiou aeiou"); - break; - } - } - return result.then(Mono.empty()); - + return getDelegate().findPetsByTags(tags, exchange); } @@ -143,20 +112,7 @@ public interface PetApi { produces = { "application/xml", "application/json" }, method = RequestMethod.GET) default Mono> getPetById(@ApiParam(value = "ID of pet to return",required=true) @PathVariable("petId") Long petId, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - result = ApiUtil.getExampleResponse(exchange, "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\"}"); - break; - } - if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { - result = ApiUtil.getExampleResponse(exchange, " 123456789 doggie aeiou aeiou"); - break; - } - } - return result.then(Mono.empty()); - + return getDelegate().getPetById(petId, exchange); } @@ -174,10 +130,7 @@ public interface PetApi { consumes = { "application/json", "application/xml" }, method = RequestMethod.PUT) default Mono> updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody Mono pet, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - return result.then(Mono.empty()); - + return getDelegate().updatePet(pet, exchange); } @@ -193,10 +146,7 @@ public interface PetApi { consumes = { "application/x-www-form-urlencoded" }, method = RequestMethod.POST) default Mono> updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated",required=true) @PathVariable("petId") Long petId,@ApiParam(value = "Updated name of the pet", defaultValue="null") @RequestParam(value="name", required=false) String name,@ApiParam(value = "Updated status of the pet", defaultValue="null") @RequestParam(value="status", required=false) String status, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - return result.then(Mono.empty()); - + return getDelegate().updatePetWithForm(petId, name, status, exchange); } @@ -213,16 +163,7 @@ public interface PetApi { consumes = { "multipart/form-data" }, method = RequestMethod.POST) default Mono> uploadFile(@ApiParam(value = "ID of pet to update",required=true) @PathVariable("petId") Long petId,@ApiParam(value = "Additional data to pass to server", defaultValue="null") @RequestParam(value="additionalMetadata", required=false) String additionalMetadata,@ApiParam(value = "file detail") @Valid @RequestPart("file") MultipartFile file, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - result = ApiUtil.getExampleResponse(exchange, "{ \"code\" : 0, \"type\" : \"type\", \"message\" : \"message\"}"); - break; - } - } - return result.then(Mono.empty()); - + return getDelegate().uploadFile(petId, additionalMetadata, file, exchange); } } diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/PetApiController.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/PetApiController.java index dba362fde18..a8c8c3765a6 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/PetApiController.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/PetApiController.java @@ -2,11 +2,21 @@ package org.openapitools.api; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.context.request.NativeWebRequest; import java.util.Optional; @Controller @RequestMapping("${openapi.openAPIPetstore.base-path:/v2}") public class PetApiController implements PetApi { + private final PetApiDelegate delegate; + + public PetApiController(@org.springframework.beans.factory.annotation.Autowired(required = false) PetApiDelegate delegate) { + this.delegate = Optional.ofNullable(delegate).orElse(new PetApiDelegate() {}); + } + + @Override + public PetApiDelegate getDelegate() { + return delegate; + } + } diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/PetApiDelegate.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/PetApiDelegate.java new file mode 100644 index 00000000000..1084c1bfe49 --- /dev/null +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/PetApiDelegate.java @@ -0,0 +1,160 @@ +package org.openapitools.api; + +import org.openapitools.model.ModelApiResponse; +import org.openapitools.model.Pet; +import org.springframework.core.io.Resource; +import io.swagger.annotations.*; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** + * A delegate to be called by the {@link PetApiController}}. + * Implement this interface with a {@link org.springframework.stereotype.Service} annotated class. + */ + +public interface PetApiDelegate { + + default Optional getRequest() { + return Optional.empty(); + } + + /** + * @see PetApi#addPet + */ + default Mono> addPet(Mono pet, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + return result.then(Mono.empty()); + + } + + /** + * @see PetApi#deletePet + */ + default Mono> deletePet(Long petId, + String apiKey, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + return result.then(Mono.empty()); + + } + + /** + * @see PetApi#findPetsByStatus + */ + default Mono>> findPetsByStatus(List status, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + result = ApiUtil.getExampleResponse(exchange, "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\"}"); + break; + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + result = ApiUtil.getExampleResponse(exchange, " 123456789 doggie aeiou aeiou"); + break; + } + } + return result.then(Mono.empty()); + + } + + /** + * @see PetApi#findPetsByTags + */ + default Mono>> findPetsByTags(List tags, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + result = ApiUtil.getExampleResponse(exchange, "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\"}"); + break; + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + result = ApiUtil.getExampleResponse(exchange, " 123456789 doggie aeiou aeiou"); + break; + } + } + return result.then(Mono.empty()); + + } + + /** + * @see PetApi#getPetById + */ + default Mono> getPetById(Long petId, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + result = ApiUtil.getExampleResponse(exchange, "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\"}"); + break; + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + result = ApiUtil.getExampleResponse(exchange, " 123456789 doggie aeiou aeiou"); + break; + } + } + return result.then(Mono.empty()); + + } + + /** + * @see PetApi#updatePet + */ + default Mono> updatePet(Mono pet, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + return result.then(Mono.empty()); + + } + + /** + * @see PetApi#updatePetWithForm + */ + default Mono> updatePetWithForm(Long petId, + String name, + String status, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + return result.then(Mono.empty()); + + } + + /** + * @see PetApi#uploadFile + */ + default Mono> uploadFile(Long petId, + String additionalMetadata, + MultipartFile file, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + result = ApiUtil.getExampleResponse(exchange, "{ \"code\" : 0, \"type\" : \"type\", \"message\" : \"message\"}"); + break; + } + } + return result.then(Mono.empty()); + + } + +} diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/StoreApi.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/StoreApi.java index 41c7a604a88..cd03846ff91 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/StoreApi.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/StoreApi.java @@ -8,8 +8,6 @@ package org.openapitools.api; import java.util.Map; import org.openapitools.model.Order; import io.swagger.annotations.*; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PathVariable; @@ -28,12 +26,15 @@ import javax.validation.Valid; import javax.validation.constraints.*; import java.util.List; import java.util.Map; -import java.util.Optional; @Validated @Api(value = "store", description = "the store API") public interface StoreApi { + default StoreApiDelegate getDelegate() { + return new StoreApiDelegate() {}; + } + @ApiOperation(value = "Delete purchase order by ID", nickname = "deleteOrder", notes = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", tags={ "store", }) @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"), @@ -41,10 +42,7 @@ public interface StoreApi { @RequestMapping(value = "/store/order/{order_id}", method = RequestMethod.DELETE) default Mono> deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted",required=true) @PathVariable("order_id") String orderId, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - return result.then(Mono.empty()); - + return getDelegate().deleteOrder(orderId, exchange); } @@ -57,10 +55,7 @@ public interface StoreApi { produces = { "application/json" }, method = RequestMethod.GET) default Mono>> getInventory(ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - return result.then(Mono.empty()); - + return getDelegate().getInventory(exchange); } @@ -73,20 +68,7 @@ public interface StoreApi { produces = { "application/xml", "application/json" }, method = RequestMethod.GET) default Mono> getOrderById(@Min(1L) @Max(5L) @ApiParam(value = "ID of pet that needs to be fetched",required=true) @PathVariable("order_id") Long orderId, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - result = ApiUtil.getExampleResponse(exchange, "{ \"petId\" : 6, \"quantity\" : 1, \"id\" : 0, \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\", \"complete\" : false, \"status\" : \"placed\"}"); - break; - } - if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { - result = ApiUtil.getExampleResponse(exchange, " 123456789 123456789 123 2000-01-23T04:56:07.000Z aeiou true"); - break; - } - } - return result.then(Mono.empty()); - + return getDelegate().getOrderById(orderId, exchange); } @@ -98,20 +80,7 @@ public interface StoreApi { produces = { "application/xml", "application/json" }, method = RequestMethod.POST) default Mono> placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @Valid @RequestBody Mono order, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - result = ApiUtil.getExampleResponse(exchange, "{ \"petId\" : 6, \"quantity\" : 1, \"id\" : 0, \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\", \"complete\" : false, \"status\" : \"placed\"}"); - break; - } - if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { - result = ApiUtil.getExampleResponse(exchange, " 123456789 123456789 123 2000-01-23T04:56:07.000Z aeiou true"); - break; - } - } - return result.then(Mono.empty()); - + return getDelegate().placeOrder(order, exchange); } } diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/StoreApiController.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/StoreApiController.java index f6d80aa6cce..d00b4841fc0 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/StoreApiController.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/StoreApiController.java @@ -2,11 +2,21 @@ package org.openapitools.api; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.context.request.NativeWebRequest; import java.util.Optional; @Controller @RequestMapping("${openapi.openAPIPetstore.base-path:/v2}") public class StoreApiController implements StoreApi { + private final StoreApiDelegate delegate; + + public StoreApiController(@org.springframework.beans.factory.annotation.Autowired(required = false) StoreApiDelegate delegate) { + this.delegate = Optional.ofNullable(delegate).orElse(new StoreApiDelegate() {}); + } + + @Override + public StoreApiDelegate getDelegate() { + return delegate; + } + } diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/StoreApiDelegate.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/StoreApiDelegate.java new file mode 100644 index 00000000000..8e95e0178b0 --- /dev/null +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/StoreApiDelegate.java @@ -0,0 +1,93 @@ +package org.openapitools.api; + +import java.util.Map; +import org.openapitools.model.Order; +import io.swagger.annotations.*; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** + * A delegate to be called by the {@link StoreApiController}}. + * Implement this interface with a {@link org.springframework.stereotype.Service} annotated class. + */ + +public interface StoreApiDelegate { + + default Optional getRequest() { + return Optional.empty(); + } + + /** + * @see StoreApi#deleteOrder + */ + default Mono> deleteOrder(String orderId, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + return result.then(Mono.empty()); + + } + + /** + * @see StoreApi#getInventory + */ + default Mono>> getInventory(ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + return result.then(Mono.empty()); + + } + + /** + * @see StoreApi#getOrderById + */ + default Mono> getOrderById(Long orderId, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + result = ApiUtil.getExampleResponse(exchange, "{ \"petId\" : 6, \"quantity\" : 1, \"id\" : 0, \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\", \"complete\" : false, \"status\" : \"placed\"}"); + break; + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + result = ApiUtil.getExampleResponse(exchange, " 123456789 123456789 123 2000-01-23T04:56:07.000Z aeiou true"); + break; + } + } + return result.then(Mono.empty()); + + } + + /** + * @see StoreApi#placeOrder + */ + default Mono> placeOrder(Mono order, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + result = ApiUtil.getExampleResponse(exchange, "{ \"petId\" : 6, \"quantity\" : 1, \"id\" : 0, \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\", \"complete\" : false, \"status\" : \"placed\"}"); + break; + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + result = ApiUtil.getExampleResponse(exchange, " 123456789 123456789 123 2000-01-23T04:56:07.000Z aeiou true"); + break; + } + } + return result.then(Mono.empty()); + + } + +} diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/UserApi.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/UserApi.java index 5e46fdae4f9..8f3bed7bb29 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/UserApi.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/UserApi.java @@ -8,8 +8,6 @@ package org.openapitools.api; import java.util.List; import org.openapitools.model.User; import io.swagger.annotations.*; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PathVariable; @@ -28,22 +26,22 @@ import javax.validation.Valid; import javax.validation.constraints.*; import java.util.List; import java.util.Map; -import java.util.Optional; @Validated @Api(value = "user", description = "the user API") public interface UserApi { + default UserApiDelegate getDelegate() { + return new UserApiDelegate() {}; + } + @ApiOperation(value = "Create user", nickname = "createUser", notes = "This can only be done by the logged in user.", tags={ "user", }) @ApiResponses(value = { @ApiResponse(code = 200, message = "successful operation") }) @RequestMapping(value = "/user", method = RequestMethod.POST) default Mono> createUser(@ApiParam(value = "Created user object" ,required=true ) @Valid @RequestBody Mono user, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - return result.then(Mono.empty()); - + return getDelegate().createUser(user, exchange); } @@ -53,10 +51,7 @@ public interface UserApi { @RequestMapping(value = "/user/createWithArray", method = RequestMethod.POST) default Mono> createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true ) @Valid @RequestBody Flux user, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - return result.then(Mono.empty()); - + return getDelegate().createUsersWithArrayInput(user, exchange); } @@ -66,10 +61,7 @@ public interface UserApi { @RequestMapping(value = "/user/createWithList", method = RequestMethod.POST) default Mono> createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true ) @Valid @RequestBody Flux user, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - return result.then(Mono.empty()); - + return getDelegate().createUsersWithListInput(user, exchange); } @@ -80,10 +72,7 @@ public interface UserApi { @RequestMapping(value = "/user/{username}", method = RequestMethod.DELETE) default Mono> deleteUser(@ApiParam(value = "The name that needs to be deleted",required=true) @PathVariable("username") String username, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - return result.then(Mono.empty()); - + return getDelegate().deleteUser(username, exchange); } @@ -96,20 +85,7 @@ public interface UserApi { produces = { "application/xml", "application/json" }, method = RequestMethod.GET) default Mono> getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing.",required=true) @PathVariable("username") String username, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - result = ApiUtil.getExampleResponse(exchange, "{ \"firstName\" : \"firstName\", \"lastName\" : \"lastName\", \"password\" : \"password\", \"userStatus\" : 6, \"phone\" : \"phone\", \"id\" : 0, \"email\" : \"email\", \"username\" : \"username\"}"); - break; - } - if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { - result = ApiUtil.getExampleResponse(exchange, " 123456789 aeiou aeiou aeiou aeiou aeiou aeiou 123"); - break; - } - } - return result.then(Mono.empty()); - + return getDelegate().getUserByName(username, exchange); } @@ -121,10 +97,7 @@ public interface UserApi { produces = { "application/xml", "application/json" }, method = RequestMethod.GET) default Mono> loginUser(@NotNull @ApiParam(value = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) String username,@NotNull @ApiParam(value = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) String password, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - return result.then(Mono.empty()); - + return getDelegate().loginUser(username, password, exchange); } @@ -134,10 +107,7 @@ public interface UserApi { @RequestMapping(value = "/user/logout", method = RequestMethod.GET) default Mono> logoutUser(ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - return result.then(Mono.empty()); - + return getDelegate().logoutUser(exchange); } @@ -148,10 +118,7 @@ public interface UserApi { @RequestMapping(value = "/user/{username}", method = RequestMethod.PUT) default Mono> updateUser(@ApiParam(value = "name that need to be deleted",required=true) @PathVariable("username") String username,@ApiParam(value = "Updated user object" ,required=true ) @Valid @RequestBody Mono user, ServerWebExchange exchange) { - exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); - Mono result = Mono.empty(); - return result.then(Mono.empty()); - + return getDelegate().updateUser(username, user, exchange); } } diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/UserApiController.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/UserApiController.java index 570a05d8d37..5bd8c1f9f57 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/UserApiController.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/UserApiController.java @@ -2,11 +2,21 @@ package org.openapitools.api; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.context.request.NativeWebRequest; import java.util.Optional; @Controller @RequestMapping("${openapi.openAPIPetstore.base-path:/v2}") public class UserApiController implements UserApi { + private final UserApiDelegate delegate; + + public UserApiController(@org.springframework.beans.factory.annotation.Autowired(required = false) UserApiDelegate delegate) { + this.delegate = Optional.ofNullable(delegate).orElse(new UserApiDelegate() {}); + } + + @Override + public UserApiDelegate getDelegate() { + return delegate; + } + } diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/UserApiDelegate.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/UserApiDelegate.java new file mode 100644 index 00000000000..03de7cd2b49 --- /dev/null +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/UserApiDelegate.java @@ -0,0 +1,129 @@ +package org.openapitools.api; + +import java.util.List; +import org.openapitools.model.User; +import io.swagger.annotations.*; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** + * A delegate to be called by the {@link UserApiController}}. + * Implement this interface with a {@link org.springframework.stereotype.Service} annotated class. + */ + +public interface UserApiDelegate { + + default Optional getRequest() { + return Optional.empty(); + } + + /** + * @see UserApi#createUser + */ + default Mono> createUser(Mono user, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + return result.then(Mono.empty()); + + } + + /** + * @see UserApi#createUsersWithArrayInput + */ + default Mono> createUsersWithArrayInput(Flux user, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + return result.then(Mono.empty()); + + } + + /** + * @see UserApi#createUsersWithListInput + */ + default Mono> createUsersWithListInput(Flux user, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + return result.then(Mono.empty()); + + } + + /** + * @see UserApi#deleteUser + */ + default Mono> deleteUser(String username, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + return result.then(Mono.empty()); + + } + + /** + * @see UserApi#getUserByName + */ + default Mono> getUserByName(String username, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + result = ApiUtil.getExampleResponse(exchange, "{ \"firstName\" : \"firstName\", \"lastName\" : \"lastName\", \"password\" : \"password\", \"userStatus\" : 6, \"phone\" : \"phone\", \"id\" : 0, \"email\" : \"email\", \"username\" : \"username\"}"); + break; + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + result = ApiUtil.getExampleResponse(exchange, " 123456789 aeiou aeiou aeiou aeiou aeiou aeiou 123"); + break; + } + } + return result.then(Mono.empty()); + + } + + /** + * @see UserApi#loginUser + */ + default Mono> loginUser(String username, + String password, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + return result.then(Mono.empty()); + + } + + /** + * @see UserApi#logoutUser + */ + default Mono> logoutUser(ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + return result.then(Mono.empty()); + + } + + /** + * @see UserApi#updateUser + */ + default Mono> updateUser(String username, + Mono user, + ServerWebExchange exchange) { + exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED); + Mono result = Mono.empty(); + return result.then(Mono.empty()); + + } + +}