From 1f23b019fa23cafe8f3ff1f7f30bee36b108c3b8 Mon Sep 17 00:00:00 2001 From: Oleh Kurpiak Date: Thu, 27 Apr 2023 14:32:11 +0300 Subject: [PATCH] [Spring] fix Paginated without params (#15315) (fix #15265) --- .../main/resources/JavaSpring/api.mustache | 8 +- .../JavaSpring/apiController.mustache | 4 +- .../resources/JavaSpring/apiDelegate.mustache | 2 +- .../java/spring/SpringCodegenTest.java | 86 +++++++++++++++---- ...dels-for-testing-with-spring-pageable.yaml | 28 ++++++ .../src/test/resources/bugs/issue_15265.yaml | 55 ++++++++++++ .../java/org/openapitools/api/PetApi.java | 36 ++++++++ .../org/openapitools/api/PetApiDelegate.java | 26 ++++++ .../src/main/resources/openapi.yaml | 31 +++++++ .../java/org/openapitools/api/PetApi.java | 36 ++++++++ .../org/openapitools/api/PetApiDelegate.java | 26 ++++++ .../src/main/resources/openapi.yaml | 31 +++++++ .../java/org/openapitools/api/PetApi.java | 51 +++++++++++ .../src/main/resources/openapi.yaml | 31 +++++++ .../java/org/openapitools/api/PetApi.java | 51 +++++++++++ .../src/main/resources/openapi.yaml | 31 +++++++ 16 files changed, 510 insertions(+), 23 deletions(-) create mode 100644 modules/openapi-generator/src/test/resources/bugs/issue_15265.yaml diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/api.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/api.mustache index 51908e42544..e02b4ba6b4b 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/api.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/api.mustache @@ -244,20 +244,20 @@ public interface {{classname}} { {{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{>cookieParams}}{{^-last}}, {{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}{{#swagger2AnnotationLibrary}}@Parameter(hidden = true){{/swagger2AnnotationLibrary}}{{#springFoxDocumentationProvider}}@ApiIgnore{{/springFoxDocumentationProvider}} final ServerWebExchange exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, - {{/hasParams}}{{#springFoxDocumentationProvider}}@ApiIgnore {{/springFoxDocumentationProvider}}{{#springDocDocumentationProvider}}@ParameterObject {{/springDocDocumentationProvider}}final Pageable pageable{{/vendorExtensions.x-spring-paginated}} + {{/hasParams}}{{^hasParams}}{{#reactive}},{{/reactive}}{{/hasParams}}{{#springFoxDocumentationProvider}}@ApiIgnore {{/springFoxDocumentationProvider}}{{#springDocDocumentationProvider}}@ParameterObject {{/springDocDocumentationProvider}}final Pageable pageable{{/vendorExtensions.x-spring-paginated}} ){{#unhandledException}} throws Exception{{/unhandledException}}{{^jdk8-default-interface}};{{/jdk8-default-interface}}{{#jdk8-default-interface}} { {{#delegate-method}} - {{^isVoid}}return {{/isVoid}}{{#isVoid}}{{#useResponseEntity}}return {{/useResponseEntity}}{{^useResponseEntity}}{{#reactive}}return {{/reactive}}{{/useResponseEntity}}{{/isVoid}}{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}, pageable{{/vendorExtensions.x-spring-paginated}}); + {{^isVoid}}return {{/isVoid}}{{#isVoid}}{{#useResponseEntity}}return {{/useResponseEntity}}{{^useResponseEntity}}{{#reactive}}return {{/reactive}}{{/useResponseEntity}}{{/isVoid}}{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#reactive}}, {{/reactive}}{{/hasParams}}pageable{{/vendorExtensions.x-spring-paginated}}); } // Override this method - {{#jdk8-default-interface}}default {{/jdk8-default-interface}} {{#responseWrapper}}{{.}}<{{/responseWrapper}}{{#useResponseEntity}}ResponseEntity<{{/useResponseEntity}}{{>returnTypes}}{{#useResponseEntity}}>{{/useResponseEntity}}{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{^isFile}}{{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{#isBodyParam}}{{^reactive}}{{{dataType}}}{{/reactive}}{{#reactive}}{{^isArray}}Mono<{{{dataType}}}>{{/isArray}}{{#isArray}}Flux<{{{baseType}}}>{{/isArray}}{{/reactive}}{{/isBodyParam}}{{/isFile}}{{#isFile}}{{#reactive}}Flux{{/reactive}}{{^reactive}}MultipartFile{{/reactive}}{{/isFile}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}{{#springFoxDocumentationProvider}}@ApiIgnore{{/springFoxDocumentationProvider}} final ServerWebExchange exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}, {{#springFoxDocumentationProvider}}@ApiIgnore{{/springFoxDocumentationProvider}} final Pageable pageable{{/vendorExtensions.x-spring-paginated}}){{#unhandledException}} throws Exception{{/unhandledException}} { + {{#jdk8-default-interface}}default {{/jdk8-default-interface}} {{#responseWrapper}}{{.}}<{{/responseWrapper}}{{#useResponseEntity}}ResponseEntity<{{/useResponseEntity}}{{>returnTypes}}{{#useResponseEntity}}>{{/useResponseEntity}}{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{^isFile}}{{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{#isBodyParam}}{{^reactive}}{{{dataType}}}{{/reactive}}{{#reactive}}{{^isArray}}Mono<{{{dataType}}}>{{/isArray}}{{#isArray}}Flux<{{{baseType}}}>{{/isArray}}{{/reactive}}{{/isBodyParam}}{{/isFile}}{{#isFile}}{{#reactive}}Flux{{/reactive}}{{^reactive}}MultipartFile{{/reactive}}{{/isFile}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}{{#springFoxDocumentationProvider}}@ApiIgnore{{/springFoxDocumentationProvider}} final ServerWebExchange exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#reactive}}, {{/reactive}}{{/hasParams}}{{#springFoxDocumentationProvider}}@ApiIgnore{{/springFoxDocumentationProvider}}final Pageable pageable{{/vendorExtensions.x-spring-paginated}}){{#unhandledException}} throws Exception{{/unhandledException}} { {{/delegate-method}} {{^isDelegate}} {{>methodBody}} {{/isDelegate}} {{#isDelegate}} - {{^isVoid}}return {{/isVoid}}{{#isVoid}}{{#useResponseEntity}}return {{/useResponseEntity}}{{^useResponseEntity}}{{#reactive}}return {{/reactive}}{{/useResponseEntity}}{{/isVoid}}getDelegate().{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}, pageable{{/vendorExtensions.x-spring-paginated}}); + {{^isVoid}}return {{/isVoid}}{{#isVoid}}{{#useResponseEntity}}return {{/useResponseEntity}}{{^useResponseEntity}}{{#reactive}}return {{/reactive}}{{/useResponseEntity}}{{/isVoid}}getDelegate().{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#reactive}}, {{/reactive}}{{/hasParams}}pageable{{/vendorExtensions.x-spring-paginated}}); {{/isDelegate}} }{{/jdk8-default-interface}} diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/apiController.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/apiController.mustache index 15b1f27c19a..a5fc96cab15 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/apiController.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/apiController.mustache @@ -122,7 +122,7 @@ public class {{classname}}Controller implements {{classname}} { public {{#responseWrapper}}{{.}}<{{/responseWrapper}}{{#useResponseEntity}}ResponseEntity<{{/useResponseEntity}}{{>returnTypes}}{{#useResponseEntity}}>{{/useResponseEntity}}{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}( {{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{>cookieParams}}{{^-last}}, {{/-last}}{{/allParams}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, - {{/hasParams}}{{#springFoxDocumentationProvider}}@ApiIgnore {{/springFoxDocumentationProvider}}final Pageable pageable{{/vendorExtensions.x-spring-paginated}} + {{/hasParams}}{{^hasParams}}{{#reactive}},{{/reactive}}{{/hasParams}}{{#springFoxDocumentationProvider}}@ApiIgnore {{/springFoxDocumentationProvider}}{{#springDocDocumentationProvider}}@ParameterObject {{/springDocDocumentationProvider}}final Pageable pageable{{/vendorExtensions.x-spring-paginated}} ) { {{^isDelegate}} {{^async}} @@ -138,7 +138,7 @@ public class {{classname}}Controller implements {{classname}} { {{/async}} {{/isDelegate}} {{#isDelegate}} - {{^isVoid}}return {{/isVoid}}{{#isVoid}}{{#useResponseEntity}}return {{/useResponseEntity}}{{^useResponseEntity}}{{#reactive}}return {{/reactive}}{{/useResponseEntity}}{{/isVoid}}delegate.{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#vendorExtensions.x-spring-paginated}}, pageable{{/vendorExtensions.x-spring-paginated}}); + {{^isVoid}}return {{/isVoid}}{{#isVoid}}{{#useResponseEntity}}return {{/useResponseEntity}}{{^useResponseEntity}}{{#reactive}}return {{/reactive}}{{/useResponseEntity}}{{/isVoid}}delegate.{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#reactive}}, {{/reactive}}{{/hasParams}}pageable{{/vendorExtensions.x-spring-paginated}}); {{/isDelegate}} } diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/apiDelegate.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/apiDelegate.mustache index a544adc2dcc..4f84e7b1da6 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/apiDelegate.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/apiDelegate.mustache @@ -64,7 +64,7 @@ public interface {{classname}}Delegate { {{/isDeprecated}} {{#jdk8-default-interface}}default {{/jdk8-default-interface}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}{{#useResponseEntity}}ResponseEntity<{{/useResponseEntity}}{{>returnTypes}}{{#useResponseEntity}}>{{/useResponseEntity}}{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{^isFile}}{{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{#isBodyParam}}{{^reactive}}{{{dataType}}}{{/reactive}}{{#reactive}}{{^isArray}}Mono<{{{dataType}}}>{{/isArray}}{{#isArray}}Flux<{{{baseType}}}>{{/isArray}}{{/reactive}}{{/isBodyParam}}{{/isFile}}{{#isFile}}{{#isArray}}List<{{/isArray}}{{#reactive}}Flux{{/reactive}}{{^reactive}}MultipartFile{{/reactive}}{{#isArray}}>{{/isArray}}{{/isFile}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}}, - {{/hasParams}}ServerWebExchange exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}, final Pageable pageable{{/vendorExtensions.x-spring-paginated}}){{#unhandledException}} throws Exception{{/unhandledException}}{{^jdk8-default-interface}};{{/jdk8-default-interface}}{{#jdk8-default-interface}} { + {{/hasParams}}ServerWebExchange exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#reactive}}, {{/reactive}}{{/hasParams}}final Pageable pageable{{/vendorExtensions.x-spring-paginated}}){{#unhandledException}} throws Exception{{/unhandledException}}{{^jdk8-default-interface}};{{/jdk8-default-interface}}{{#jdk8-default-interface}} { {{>methodBody}} }{{/jdk8-default-interface}} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java index 5e96027a229..777c004f8aa 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java @@ -868,8 +868,7 @@ public class SpringCodegenTest { Map files = generator.opts(input).generate().stream() .collect(Collectors.toMap(File::getName, Function.identity())); - JavaFileAssert javaFileAssert = JavaFileAssert.assertThat(files.get("PersonWithEmail.java")) - .printFileContent(); + JavaFileAssert javaFileAssert = JavaFileAssert.assertThat(files.get("PersonWithEmail.java")); if (useBeanValidation) javaFileAssert.hasImports((useJakarta? "jakarta" : "javax") + ".validation.constraints"); if (performBeanValidation) javaFileAssert.hasImports("org.hibernate.validator.constraints"); assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/model/PersonWithEmail.java"), contains); @@ -946,6 +945,71 @@ public class SpringCodegenTest { .assertMethod("readAgreements", "ServerWebExchange"); } + @Test + public void shouldGenerateValidCodeWithPaginated_reactive_issue15265() throws IOException { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/bugs/issue_15265.yaml"); + final SpringCodegen codegen = new SpringCodegen(); + codegen.setOpenAPI(openAPI); + codegen.setOutputDir(output.getAbsolutePath()); + + codegen.additionalProperties().put(SpringCodegen.REACTIVE, "true"); + codegen.additionalProperties().put(USE_TAGS, "true"); + codegen.additionalProperties().put(SpringCodegen.DATE_LIBRARY, "java8"); + codegen.additionalProperties().put(INTERFACE_ONLY, "true"); + codegen.additionalProperties().put(SKIP_DEFAULT_INTERFACE, "true"); + codegen.additionalProperties().put(IMPLICIT_HEADERS, "true"); + codegen.additionalProperties().put(OPENAPI_NULLABLE, "false"); + + ClientOptInput input = new ClientOptInput(); + input.openAPI(openAPI); + input.config(codegen); + + DefaultGenerator generator = new DefaultGenerator(); + + Map files = generator.opts(input).generate().stream() + .collect(Collectors.toMap(File::getName, Function.identity())); + + JavaFileAssert.assertThat(files.get("ConsentControllerApi.java")) + .assertMethod("paginated", "ServerWebExchange", "Pageable") + .toFileAssert() + .assertMethod("paginatedWithParams", "String", "ServerWebExchange", "Pageable"); + } + + @Test + public void shouldGenerateValidCodeWithPaginated_nonReactive_issue15265() throws IOException { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/bugs/issue_15265.yaml"); + final SpringCodegen codegen = new SpringCodegen(); + codegen.setOpenAPI(openAPI); + codegen.setOutputDir(output.getAbsolutePath()); + + codegen.additionalProperties().put(USE_TAGS, "true"); + codegen.additionalProperties().put(SpringCodegen.DATE_LIBRARY, "java8"); + codegen.additionalProperties().put(INTERFACE_ONLY, "true"); + codegen.additionalProperties().put(SKIP_DEFAULT_INTERFACE, "true"); + codegen.additionalProperties().put(IMPLICIT_HEADERS, "true"); + codegen.additionalProperties().put(OPENAPI_NULLABLE, "false"); + + ClientOptInput input = new ClientOptInput(); + input.openAPI(openAPI); + input.config(codegen); + + DefaultGenerator generator = new DefaultGenerator(); + + Map files = generator.opts(input).generate().stream() + .collect(Collectors.toMap(File::getName, Function.identity())); + + JavaFileAssert.assertThat(files.get("ConsentControllerApi.java")) + .assertMethod("paginated", "Pageable") + .toFileAssert() + .assertMethod("paginatedWithParams", "String", "Pageable"); + } + @Test public void shouldEscapeReservedKeyWordsForRequestParameters_7506_Regression() throws Exception { final SpringCodegen codegen = new SpringCodegen(); @@ -1483,7 +1547,6 @@ public class SpringCodegenTest { .collect(Collectors.toMap(File::getName, Function.identity())); JavaFileAssert.assertThat(files.get("PetApi.java")) - .printFileContent() .hasImports("io.swagger.v3.oas.annotations.ExternalDocumentation") .assertMethod("updatePet") .assertMethodAnnotations() @@ -1831,7 +1894,6 @@ public class SpringCodegenTest { .collect(Collectors.toMap(File::getName, Function.identity())); JavaFileAssert.assertThat(files.get("SomeMethodApi.java")) - .printFileContent() .assertMethod("methodWithValidation") .hasParameter("headerOne") .assertParameterAnnotations() @@ -1872,8 +1934,7 @@ public class SpringCodegenTest { Map files = generateFiles(codegen, "src/test/resources/bugs/issue_13365.yml"); //Assert that NotNull annotation exists alone with no other BeanValidation annotations - JavaFileAssert javaFileAssert = JavaFileAssert.assertThat(files.get("Person.java")) - .printFileContent(); + JavaFileAssert javaFileAssert = JavaFileAssert.assertThat(files.get("Person.java")); javaFileAssert.assertMethod("getName").assertMethodAnnotations() .containsWithName("NotNull").anyMatch(annotation -> !annotation.getNameAsString().equals("Valid") || @@ -1904,8 +1965,7 @@ public class SpringCodegenTest { Map files = generateFiles(codegen, "src/test/resources/bugs/issue_13365.yml"); //Assert that NotNull annotation exists alone with no other BeanValidation annotations - JavaFileAssert javaFileAssert = JavaFileAssert.assertThat(files.get("Person.java")) - .printFileContent(); + JavaFileAssert javaFileAssert = JavaFileAssert.assertThat(files.get("Person.java")); javaFileAssert.assertMethod("getName").assertMethodAnnotations() .containsWithName("NotNull").anyMatch(annotation -> !annotation.getNameAsString().equals("Valid") || @@ -1933,8 +1993,7 @@ public class SpringCodegenTest { Map files = generateFiles(codegen, "src/test/resources/bugs/issue_13365.yml"); - JavaFileAssert javaFileAssert = JavaFileAssert.assertThat(files.get("Alien.java")) - .printFileContent(); + JavaFileAssert javaFileAssert = JavaFileAssert.assertThat(files.get("Alien.java")); javaFileAssert.assertMethod("getName") .assertMethodAnnotations().anyMatch(annotation -> !annotation.getNameAsString().equals("NotNull")); javaFileAssert.hasNoImports("javax.validation.constraints.NotNull"); @@ -1950,7 +2009,6 @@ public class SpringCodegenTest { Map files = generateFiles(codegen, "src/test/resources/bugs/issue_14252.yaml"); JavaFileAssert.assertThat(files.get("MyResponse.java")) - .printFileContent() .hasImports("com.fasterxml.jackson.databind.annotation.JsonSerialize", "com.fasterxml.jackson.databind.ser.std.ToStringSerializer") .assertMethod("getMyPropTypeNumber") .assertMethodAnnotations() @@ -1977,8 +2035,7 @@ public class SpringCodegenTest { Map files = generateFiles(codegen, "src/test/resources/bugs/issue_13365.yml"); - JavaFileAssert javaFileAssert = JavaFileAssert.assertThat(files.get("Person.java")) - .printFileContent(); + JavaFileAssert javaFileAssert = JavaFileAssert.assertThat(files.get("Person.java")); javaFileAssert.assertMethod("getName").assertMethodAnnotations() .containsWithName("NotNull").containsWithName("Size").containsWithName("javax.validation.constraints.Email"); javaFileAssert @@ -2010,7 +2067,6 @@ public class SpringCodegenTest { .collect(Collectors.toMap(File::getName, Function.identity())); JavaFileAssert.assertThat(files.get("TestObject.java")) - .printFileContent() .assertMethod("equals") .bodyContainsLines("return equalsNullable(this.picture, testObject.picture);"); @@ -2041,7 +2097,6 @@ public class SpringCodegenTest { .collect(Collectors.toMap(File::getName, Function.identity())); JavaFileAssert.assertThat(files.get("TestObject.java")) - .printFileContent() .assertMethod("equals") .bodyContainsLines("return Arrays.equals(this.picture, testObject.picture);"); } @@ -2071,7 +2126,6 @@ public class SpringCodegenTest { .collect(Collectors.toMap(File::getName, Function.identity())); JavaFileAssert.assertThat(files.get("AddApi.java")) - .printFileContent() .assertMethod("addPost") .hasParameter("body") .assertParameterAnnotations() diff --git a/modules/openapi-generator/src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing-with-spring-pageable.yaml b/modules/openapi-generator/src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing-with-spring-pageable.yaml index 3d6ed2942c3..0d3f66f4ab1 100644 --- a/modules/openapi-generator/src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing-with-spring-pageable.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing-with-spring-pageable.yaml @@ -124,6 +124,34 @@ paths: - write:pets - read:pets x-spring-paginated: true + /pet/all: + get: + tags: + - pet + summary: List all pets + operationId: listAllPets + responses: + 200: + description: successful operation + content: + application/xml: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + 400: + description: Invalid status value + content: { } + security: + - petstore_auth: + - write:pets + - read:pets + x-spring-paginated: true /pet/findByTags: get: tags: diff --git a/modules/openapi-generator/src/test/resources/bugs/issue_15265.yaml b/modules/openapi-generator/src/test/resources/bugs/issue_15265.yaml new file mode 100644 index 00000000000..1691e2922d9 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/bugs/issue_15265.yaml @@ -0,0 +1,55 @@ +openapi: 3.0.1 +info: + title: TEST + description: |- + ## TEST + version: 1.0.0 + +servers: + - url: /v3 + description: Major version of service + +tags: + - name: consent-controller + description: Consent API + + +paths: + /paginated-with-params: + get: + tags: + - consent-controller + operationId: paginatedWithParams + x-spring-paginated: true + parameters: + - in: query + name: param1 + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ResponseAgreement' + /paginated: + get: + tags: + - consent-controller + operationId: paginated + x-spring-paginated: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ResponseAgreement' +components: + schemas: + ResponseAgreement: + type: object + properties: + agreementId: + type: string \ No newline at end of file diff --git a/samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8/src/main/java/org/openapitools/api/PetApi.java b/samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8/src/main/java/org/openapitools/api/PetApi.java index 0dc990e943e..f1c0830699b 100644 --- a/samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8/src/main/java/org/openapitools/api/PetApi.java +++ b/samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8/src/main/java/org/openapitools/api/PetApi.java @@ -217,6 +217,42 @@ public interface PetApi { } + /** + * GET /pet/all : List all pets + * + * @return successful operation (status code 200) + * or Invalid status value (status code 400) + */ + @ApiOperation( + tags = { "pet" }, + value = "List all pets", + nickname = "listAllPets", + notes = "", + response = Pet.class, + responseContainer = "List", + authorizations = { + @Authorization(value = "petstore_auth", scopes = { + @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), + @AuthorizationScope(scope = "read:pets", description = "read your pets") + }) + } + ) + @ApiResponses({ + @ApiResponse(code = 200, message = "successful operation", response = Pet.class, responseContainer = "List"), + @ApiResponse(code = 400, message = "Invalid status value") + }) + @RequestMapping( + method = RequestMethod.GET, + value = "/pet/all", + produces = { "application/xml", "application/json" } + ) + default ResponseEntity> listAllPets( + @ApiIgnore final Pageable pageable + ) { + return getDelegate().listAllPets(pageable); + } + + /** * PUT /pet : Update an existing pet * diff --git a/samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8/src/main/java/org/openapitools/api/PetApiDelegate.java b/samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8/src/main/java/org/openapitools/api/PetApiDelegate.java index ec9d4d2e743..85d69522958 100644 --- a/samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8/src/main/java/org/openapitools/api/PetApiDelegate.java +++ b/samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8/src/main/java/org/openapitools/api/PetApiDelegate.java @@ -141,6 +141,32 @@ public interface PetApiDelegate { } + /** + * GET /pet/all : List all pets + * + * @return successful operation (status code 200) + * or Invalid status value (status code 400) + * @see PetApi#listAllPets + */ + default ResponseEntity> listAllPets(final Pageable pageable) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "[ { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"default-name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }, { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"default-name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" } ]"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + String exampleString = " 123456789 123456789 aeiou doggie aeiou 123456789 aeiou aeiou "; + ApiUtil.setExampleResponse(request, "application/xml", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + /** * PUT /pet : Update an existing pet * diff --git a/samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8/src/main/resources/openapi.yaml b/samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8/src/main/resources/openapi.yaml index c1bde43b2e3..7a2cc752908 100644 --- a/samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8/src/main/resources/openapi.yaml +++ b/samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8/src/main/resources/openapi.yaml @@ -135,6 +135,37 @@ paths: x-accepts: application/json x-tags: - tag: pet + /pet/all: + get: + operationId: listAllPets + responses: + "200": + content: + application/xml: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + application/json: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + description: successful operation + "400": + content: {} + description: Invalid status value + security: + - petstore_auth: + - write:pets + - read:pets + summary: List all pets + tags: + - pet + x-spring-paginated: true + x-accepts: application/json + x-tags: + - tag: pet /pet/findByTags: get: deprecated: true diff --git a/samples/server/petstore/springboot-spring-pageable-delegatePattern/src/main/java/org/openapitools/api/PetApi.java b/samples/server/petstore/springboot-spring-pageable-delegatePattern/src/main/java/org/openapitools/api/PetApi.java index 0dc990e943e..f1c0830699b 100644 --- a/samples/server/petstore/springboot-spring-pageable-delegatePattern/src/main/java/org/openapitools/api/PetApi.java +++ b/samples/server/petstore/springboot-spring-pageable-delegatePattern/src/main/java/org/openapitools/api/PetApi.java @@ -217,6 +217,42 @@ public interface PetApi { } + /** + * GET /pet/all : List all pets + * + * @return successful operation (status code 200) + * or Invalid status value (status code 400) + */ + @ApiOperation( + tags = { "pet" }, + value = "List all pets", + nickname = "listAllPets", + notes = "", + response = Pet.class, + responseContainer = "List", + authorizations = { + @Authorization(value = "petstore_auth", scopes = { + @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), + @AuthorizationScope(scope = "read:pets", description = "read your pets") + }) + } + ) + @ApiResponses({ + @ApiResponse(code = 200, message = "successful operation", response = Pet.class, responseContainer = "List"), + @ApiResponse(code = 400, message = "Invalid status value") + }) + @RequestMapping( + method = RequestMethod.GET, + value = "/pet/all", + produces = { "application/xml", "application/json" } + ) + default ResponseEntity> listAllPets( + @ApiIgnore final Pageable pageable + ) { + return getDelegate().listAllPets(pageable); + } + + /** * PUT /pet : Update an existing pet * diff --git a/samples/server/petstore/springboot-spring-pageable-delegatePattern/src/main/java/org/openapitools/api/PetApiDelegate.java b/samples/server/petstore/springboot-spring-pageable-delegatePattern/src/main/java/org/openapitools/api/PetApiDelegate.java index ec9d4d2e743..85d69522958 100644 --- a/samples/server/petstore/springboot-spring-pageable-delegatePattern/src/main/java/org/openapitools/api/PetApiDelegate.java +++ b/samples/server/petstore/springboot-spring-pageable-delegatePattern/src/main/java/org/openapitools/api/PetApiDelegate.java @@ -141,6 +141,32 @@ public interface PetApiDelegate { } + /** + * GET /pet/all : List all pets + * + * @return successful operation (status code 200) + * or Invalid status value (status code 400) + * @see PetApi#listAllPets + */ + default ResponseEntity> listAllPets(final Pageable pageable) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "[ { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"default-name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }, { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"default-name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" } ]"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + String exampleString = " 123456789 123456789 aeiou doggie aeiou 123456789 aeiou aeiou "; + ApiUtil.setExampleResponse(request, "application/xml", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + /** * PUT /pet : Update an existing pet * diff --git a/samples/server/petstore/springboot-spring-pageable-delegatePattern/src/main/resources/openapi.yaml b/samples/server/petstore/springboot-spring-pageable-delegatePattern/src/main/resources/openapi.yaml index c1bde43b2e3..7a2cc752908 100644 --- a/samples/server/petstore/springboot-spring-pageable-delegatePattern/src/main/resources/openapi.yaml +++ b/samples/server/petstore/springboot-spring-pageable-delegatePattern/src/main/resources/openapi.yaml @@ -135,6 +135,37 @@ paths: x-accepts: application/json x-tags: - tag: pet + /pet/all: + get: + operationId: listAllPets + responses: + "200": + content: + application/xml: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + application/json: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + description: successful operation + "400": + content: {} + description: Invalid status value + security: + - petstore_auth: + - write:pets + - read:pets + summary: List all pets + tags: + - pet + x-spring-paginated: true + x-accepts: application/json + x-tags: + - tag: pet /pet/findByTags: get: deprecated: true diff --git a/samples/server/petstore/springboot-spring-pageable-without-j8/src/main/java/org/openapitools/api/PetApi.java b/samples/server/petstore/springboot-spring-pageable-without-j8/src/main/java/org/openapitools/api/PetApi.java index 5855396371c..c4582e407a7 100644 --- a/samples/server/petstore/springboot-spring-pageable-without-j8/src/main/java/org/openapitools/api/PetApi.java +++ b/samples/server/petstore/springboot-spring-pageable-without-j8/src/main/java/org/openapitools/api/PetApi.java @@ -268,6 +268,57 @@ public interface PetApi { } + /** + * GET /pet/all : List all pets + * + * @return successful operation (status code 200) + * or Invalid status value (status code 400) + */ + @ApiOperation( + tags = { "pet" }, + value = "List all pets", + nickname = "listAllPets", + notes = "", + response = Pet.class, + responseContainer = "List", + authorizations = { + @Authorization(value = "petstore_auth", scopes = { + @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), + @AuthorizationScope(scope = "read:pets", description = "read your pets") + }) + } + ) + @ApiResponses({ + @ApiResponse(code = 200, message = "successful operation", response = Pet.class, responseContainer = "List"), + @ApiResponse(code = 400, message = "Invalid status value") + }) + @RequestMapping( + method = RequestMethod.GET, + value = "/pet/all", + produces = { "application/xml", "application/json" } + ) + default ResponseEntity> listAllPets( + @ApiIgnore final Pageable pageable + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "[ { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"default-name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }, { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"default-name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" } ]"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + String exampleString = " 123456789 123456789 aeiou doggie aeiou 123456789 aeiou aeiou "; + ApiUtil.setExampleResponse(request, "application/xml", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + /** * PUT /pet : Update an existing pet * diff --git a/samples/server/petstore/springboot-spring-pageable-without-j8/src/main/resources/openapi.yaml b/samples/server/petstore/springboot-spring-pageable-without-j8/src/main/resources/openapi.yaml index c1bde43b2e3..7a2cc752908 100644 --- a/samples/server/petstore/springboot-spring-pageable-without-j8/src/main/resources/openapi.yaml +++ b/samples/server/petstore/springboot-spring-pageable-without-j8/src/main/resources/openapi.yaml @@ -135,6 +135,37 @@ paths: x-accepts: application/json x-tags: - tag: pet + /pet/all: + get: + operationId: listAllPets + responses: + "200": + content: + application/xml: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + application/json: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + description: successful operation + "400": + content: {} + description: Invalid status value + security: + - petstore_auth: + - write:pets + - read:pets + summary: List all pets + tags: + - pet + x-spring-paginated: true + x-accepts: application/json + x-tags: + - tag: pet /pet/findByTags: get: deprecated: true diff --git a/samples/server/petstore/springboot-spring-pageable/src/main/java/org/openapitools/api/PetApi.java b/samples/server/petstore/springboot-spring-pageable/src/main/java/org/openapitools/api/PetApi.java index 5855396371c..c4582e407a7 100644 --- a/samples/server/petstore/springboot-spring-pageable/src/main/java/org/openapitools/api/PetApi.java +++ b/samples/server/petstore/springboot-spring-pageable/src/main/java/org/openapitools/api/PetApi.java @@ -268,6 +268,57 @@ public interface PetApi { } + /** + * GET /pet/all : List all pets + * + * @return successful operation (status code 200) + * or Invalid status value (status code 400) + */ + @ApiOperation( + tags = { "pet" }, + value = "List all pets", + nickname = "listAllPets", + notes = "", + response = Pet.class, + responseContainer = "List", + authorizations = { + @Authorization(value = "petstore_auth", scopes = { + @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), + @AuthorizationScope(scope = "read:pets", description = "read your pets") + }) + } + ) + @ApiResponses({ + @ApiResponse(code = 200, message = "successful operation", response = Pet.class, responseContainer = "List"), + @ApiResponse(code = 400, message = "Invalid status value") + }) + @RequestMapping( + method = RequestMethod.GET, + value = "/pet/all", + produces = { "application/xml", "application/json" } + ) + default ResponseEntity> listAllPets( + @ApiIgnore final Pageable pageable + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "[ { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"default-name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }, { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"default-name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" } ]"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + String exampleString = " 123456789 123456789 aeiou doggie aeiou 123456789 aeiou aeiou "; + ApiUtil.setExampleResponse(request, "application/xml", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + /** * PUT /pet : Update an existing pet * diff --git a/samples/server/petstore/springboot-spring-pageable/src/main/resources/openapi.yaml b/samples/server/petstore/springboot-spring-pageable/src/main/resources/openapi.yaml index c1bde43b2e3..7a2cc752908 100644 --- a/samples/server/petstore/springboot-spring-pageable/src/main/resources/openapi.yaml +++ b/samples/server/petstore/springboot-spring-pageable/src/main/resources/openapi.yaml @@ -135,6 +135,37 @@ paths: x-accepts: application/json x-tags: - tag: pet + /pet/all: + get: + operationId: listAllPets + responses: + "200": + content: + application/xml: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + application/json: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + description: successful operation + "400": + content: {} + description: Invalid status value + security: + - petstore_auth: + - write:pets + - read:pets + summary: List all pets + tags: + - pet + x-spring-paginated: true + x-accepts: application/json + x-tags: + - tag: pet /pet/findByTags: get: deprecated: true