From 9d3de9c3f7ec85950c190510165a9fa56a6fe518 Mon Sep 17 00:00:00 2001 From: Tobias Fischer Date: Fri, 18 Nov 2022 12:03:51 +0100 Subject: [PATCH 1/2] [Java][Spring] remove 'size', 'page' and 'sort' query params if using 'x-spring-paginated' (#8315) --- docs/generators/java-camel.md | 2 +- docs/generators/spring.md | 2 +- .../openapitools/codegen/VendorExtension.java | 2 +- .../codegen/languages/SpringCodegen.java | 11 +++++++ ...dels-for-testing-with-spring-pageable.yaml | 25 +++++++++++++++ .../2_0/petstore-with-spring-pageable.yaml | 25 +++++++++++++++ .../java/org/openapitools/api/PetApi.java | 2 ++ .../java/org/openapitools/api/PetApi.java | 2 ++ .../java/org/openapitools/api/PetApi.java | 4 ++- .../org/openapitools/api/PetApiDelegate.java | 4 ++- .../src/main/resources/openapi.yaml | 32 +++++++++++++++++++ .../java/org/openapitools/api/PetApi.java | 4 ++- .../org/openapitools/api/PetApiDelegate.java | 4 ++- .../src/main/resources/openapi.yaml | 32 +++++++++++++++++++ .../java/org/openapitools/api/PetApi.java | 2 ++ .../src/main/resources/openapi.yaml | 32 +++++++++++++++++++ .../java/org/openapitools/api/PetApi.java | 2 ++ .../src/main/resources/openapi.yaml | 32 +++++++++++++++++++ 18 files changed, 212 insertions(+), 7 deletions(-) diff --git a/docs/generators/java-camel.md b/docs/generators/java-camel.md index c3cac83c15e3..57e4cf8f4628 100644 --- a/docs/generators/java-camel.md +++ b/docs/generators/java-camel.md @@ -112,7 +112,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |x-content-type|Specify custom value for 'Content-Type' header for operation|OPERATION|null |x-class-extra-annotation|List of custom annotations to be added to model|MODEL|null |x-field-extra-annotation|List of custom annotations to be added to property|FIELD|null -|x-spring-paginated|Add org.springframework.data.domain.Pageable to controller method. Can be used to handle page & size query parameters|OPERATION|false +|x-spring-paginated|Add `org.springframework.data.domain.Pageable` to controller method. Can be used to handle `page`, `size` and `sort` query parameters. If these query parameters are also specified in the operation spec, they will be removed from the controller method as their values can be obtained from the `Pageable` object.|OPERATION|false ## IMPORT MAPPING diff --git a/docs/generators/spring.md b/docs/generators/spring.md index 9d28e7915e76..e2fcbc448fe7 100644 --- a/docs/generators/spring.md +++ b/docs/generators/spring.md @@ -105,7 +105,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |x-content-type|Specify custom value for 'Content-Type' header for operation|OPERATION|null |x-class-extra-annotation|List of custom annotations to be added to model|MODEL|null |x-field-extra-annotation|List of custom annotations to be added to property|FIELD|null -|x-spring-paginated|Add org.springframework.data.domain.Pageable to controller method. Can be used to handle page & size query parameters|OPERATION|false +|x-spring-paginated|Add `org.springframework.data.domain.Pageable` to controller method. Can be used to handle `page`, `size` and `sort` query parameters. If these query parameters are also specified in the operation spec, they will be removed from the controller method as their values can be obtained from the `Pageable` object.|OPERATION|false ## IMPORT MAPPING diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/VendorExtension.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/VendorExtension.java index b662fe0006cc..03c93e0c0490 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/VendorExtension.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/VendorExtension.java @@ -6,7 +6,7 @@ public enum VendorExtension { X_IMPLEMENTS("x-implements", ExtensionLevel.MODEL, "Ability to specify interfaces that model must implements", "empty array"), - X_SPRING_PAGINATED("x-spring-paginated", ExtensionLevel.OPERATION, "Add org.springframework.data.domain.Pageable to controller method. Can be used to handle page & size query parameters", "false"), + X_SPRING_PAGINATED("x-spring-paginated", ExtensionLevel.OPERATION, "Add `org.springframework.data.domain.Pageable` to controller method. Can be used to handle `page`, `size` and `sort` query parameters. If these query parameters are also specified in the operation spec, they will be removed from the controller method as their values can be obtained from the `Pageable` object.", "false"), X_DISCRIMINATOR_VALUE("x-discriminator-value", ExtensionLevel.MODEL, "Used with model inheritance to specify value for discriminator that identifies current model", ""), X_SETTER_EXTRA_ANNOTATION("x-setter-extra-annotation", ExtensionLevel.FIELD, "Custom annotation that can be specified over java setter for specific field", "When field is array & uniqueItems, then this extension is used to add `@JsonDeserialize(as = LinkedHashSet.class)` over setter, otherwise no value"), X_WEBCLIENT_BLOCKING("x-webclient-blocking", ExtensionLevel.OPERATION, "Specifies if method for specific operation should be blocking or non-blocking(ex: return `Mono/Flux` or `return T/List/Set` & execute `.block()` inside generated method)", "false"), diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java index b43a9aa1c78d..1ea25c1d23fc 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java @@ -1075,6 +1075,8 @@ public Map postProcessAllModels(Map objs) * Add dynamic imports based on the parameters and vendor extensions of an operation. * The imports are expanded by the mustache {{import}} tag available to model and api * templates. + * + * #8315 Also handles removing 'size', 'page' and 'sort' query parameters if using 'x-spring-paginated'. */ @Override public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List servers) { @@ -1093,6 +1095,15 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation if (DocumentationProvider.SPRINGDOC.equals(getDocumentationProvider())) { codegenOperation.imports.add("ParameterObject"); } + + // #8315 Spring Data Web default query params recognized by Pageable + List defaultPageableQueryParams = new ArrayList<>( + Arrays.asList("page", "size", "sort") + ); + + // #8315 Remove matching Spring Data Web default query params if 'x-spring-paginated' with Pageable is used + codegenOperation.queryParams.removeIf(param -> defaultPageableQueryParams.contains(param.baseName)); + codegenOperation.allParams.removeIf(param -> param.isQueryParam && defaultPageableQueryParams.contains(param.baseName)); } if (reactive) { diff --git a/modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing-with-spring-pageable.yaml b/modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing-with-spring-pageable.yaml index 3f8a66e2a1bc..a2851e9f6e2a 100644 --- a/modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing-with-spring-pageable.yaml +++ b/modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing-with-spring-pageable.yaml @@ -137,6 +137,31 @@ paths: items: type: string collectionFormat: csv + - name: size + in: header + description: 'A test HeaderParam for issue #8315 - must NOT be removed when x-spring-paginated:true is used.' + required: false + type: string + - name: size + in: query + description: 'The number of items to return per page. Test QueryParam for issue #8315 - must be removed when x-spring-paginated:true is used.' + required: true + type: integer + minimum: 1 + default: 20 + - name: page + in: query + description: 'The page to return, starting with page 0. Test QueryParam for issue #8315 - must be removed when x-spring-paginated:true is used.' + required: true + type: integer + minimum: 0 + default: 0 + - name: sort + in: query + description: 'The sorting to apply to the Pageable object. Test QueryParam for issue #8315 - must be removed when x-spring-paginated:true is used.' + required: true + type: string + default: id,asc responses: '200': description: successful operation diff --git a/modules/openapi-generator/src/test/resources/2_0/petstore-with-spring-pageable.yaml b/modules/openapi-generator/src/test/resources/2_0/petstore-with-spring-pageable.yaml index 9a1152bb06ac..fbf17da64240 100644 --- a/modules/openapi-generator/src/test/resources/2_0/petstore-with-spring-pageable.yaml +++ b/modules/openapi-generator/src/test/resources/2_0/petstore-with-spring-pageable.yaml @@ -133,6 +133,31 @@ paths: items: type: string collectionFormat: csv + - name: size + in: header + description: 'A test HeaderParam for issue #8315 - must NOT be removed when x-spring-paginated:true is used.' + required: false + type: string + - name: size + in: query + description: 'The number of items to return per page. Test QueryParam for issue #8315 - must be removed when x-spring-paginated:true is used.' + required: true + type: integer + minimum: 1 + default: 20 + - name: page + in: query + description: 'The page to return, starting with page 0. Test QueryParam for issue #8315 - must be removed when x-spring-paginated:true is used.' + required: true + type: integer + minimum: 0 + default: 0 + - name: sort + in: query + description: 'The sorting to apply to the Pageable object. Test QueryParam for issue #8315 - must be removed when x-spring-paginated:true is used.' + required: true + type: string + default: id,asc responses: '200': description: successful operation diff --git a/samples/client/petstore/spring-cloud-spring-pageable/src/main/java/org/openapitools/api/PetApi.java b/samples/client/petstore/spring-cloud-spring-pageable/src/main/java/org/openapitools/api/PetApi.java index c6cd35b9961d..371cd01fcf9f 100644 --- a/samples/client/petstore/spring-cloud-spring-pageable/src/main/java/org/openapitools/api/PetApi.java +++ b/samples/client/petstore/spring-cloud-spring-pageable/src/main/java/org/openapitools/api/PetApi.java @@ -135,6 +135,7 @@ ResponseEntity> findPetsByStatus( * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * * @param tags Tags to filter by (required) + * @param size A test HeaderParam for issue #8315 - must NOT be removed when x-spring-paginated:true is used. (optional) * @return successful operation (status code 200) * or Invalid tag value (status code 400) * @deprecated @@ -165,6 +166,7 @@ ResponseEntity> findPetsByStatus( ) ResponseEntity> findPetsByTags( @NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) List tags, + @ApiParam(value = "A test HeaderParam for issue #8315 - must NOT be removed when x-spring-paginated:true is used.") @RequestHeader(value = "size", required = false) String size, @ApiIgnore final Pageable pageable ); diff --git a/samples/openapi3/client/petstore/spring-cloud-spring-pageable/src/main/java/org/openapitools/api/PetApi.java b/samples/openapi3/client/petstore/spring-cloud-spring-pageable/src/main/java/org/openapitools/api/PetApi.java index ea5537110469..c5670d541c3a 100644 --- a/samples/openapi3/client/petstore/spring-cloud-spring-pageable/src/main/java/org/openapitools/api/PetApi.java +++ b/samples/openapi3/client/petstore/spring-cloud-spring-pageable/src/main/java/org/openapitools/api/PetApi.java @@ -131,6 +131,7 @@ ResponseEntity> findPetsByStatus( * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * * @param tags Tags to filter by (required) + * @param size A test HeaderParam for issue #8315 - must NOT be removed when x-spring-paginated:true is used. (optional) * @return successful operation (status code 200) * or Invalid tag value (status code 400) * @deprecated @@ -158,6 +159,7 @@ ResponseEntity> findPetsByStatus( ) ResponseEntity> findPetsByTags( @NotNull @Parameter(name = "tags", description = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) List tags, + @Parameter(name = "size", description = "A test HeaderParam for issue #8315 - must NOT be removed when x-spring-paginated:true is used.") @RequestHeader(value = "size", required = false) String size, @ParameterObject final Pageable pageable ); 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 c1d022bbe331..96b5a62e3281 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 @@ -145,6 +145,7 @@ default ResponseEntity> findPetsByStatus( * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * * @param tags Tags to filter by (required) + * @param size A test HeaderParam for issue #8315 - must NOT be removed when x-spring-paginated:true is used. (optional) * @return successful operation (status code 200) * or Invalid tag value (status code 400) * @deprecated @@ -175,9 +176,10 @@ default ResponseEntity> findPetsByStatus( ) default ResponseEntity> findPetsByTags( @NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) List tags, + @ApiParam(value = "A test HeaderParam for issue #8315 - must NOT be removed when x-spring-paginated:true is used.") @RequestHeader(value = "size", required = false) String size, @ApiIgnore final Pageable pageable ) { - return getDelegate().findPetsByTags(tags, pageable); + return getDelegate().findPetsByTags(tags, size, pageable); } 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 e14cc23e791d..8d657e6b2e45 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 @@ -87,13 +87,15 @@ default ResponseEntity> findPetsByStatus(List status, final Pa * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * * @param tags Tags to filter by (required) + * @param size A test HeaderParam for issue #8315 - must NOT be removed when x-spring-paginated:true is used. (optional) * @return successful operation (status code 200) * or Invalid tag value (status code 400) * @deprecated * @see PetApi#findPetsByTags */ @Deprecated - default ResponseEntity> findPetsByTags(List tags, final Pageable pageable) { + default ResponseEntity> findPetsByTags(List tags, + String size, final Pageable pageable) { 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-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 e0a2517abd90..d711e92f27df 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 @@ -152,6 +152,38 @@ paths: type: string type: array style: form + - description: "A test HeaderParam for issue #8315 - must NOT be removed when\ + \ x-spring-paginated:true is used." + in: header + name: size + schema: + type: string + - description: "The number of items to return per page. Test QueryParam for\ + \ issue #8315 - must be removed when x-spring-paginated:true is used." + in: query + name: size + required: true + schema: + default: 20 + minimum: 1 + type: integer + - description: "The page to return, starting with page 0. Test QueryParam for\ + \ issue #8315 - must be removed when x-spring-paginated:true is used." + in: query + name: page + required: true + schema: + default: 0 + minimum: 0 + type: integer + - description: "The sorting to apply to the Pageable object. Test QueryParam\ + \ for issue #8315 - must be removed when x-spring-paginated:true is used." + in: query + name: sort + required: true + schema: + default: "id,asc" + type: string responses: "200": content: 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 c1d022bbe331..96b5a62e3281 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 @@ -145,6 +145,7 @@ default ResponseEntity> findPetsByStatus( * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * * @param tags Tags to filter by (required) + * @param size A test HeaderParam for issue #8315 - must NOT be removed when x-spring-paginated:true is used. (optional) * @return successful operation (status code 200) * or Invalid tag value (status code 400) * @deprecated @@ -175,9 +176,10 @@ default ResponseEntity> findPetsByStatus( ) default ResponseEntity> findPetsByTags( @NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) List tags, + @ApiParam(value = "A test HeaderParam for issue #8315 - must NOT be removed when x-spring-paginated:true is used.") @RequestHeader(value = "size", required = false) String size, @ApiIgnore final Pageable pageable ) { - return getDelegate().findPetsByTags(tags, pageable); + return getDelegate().findPetsByTags(tags, size, pageable); } 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 e14cc23e791d..8d657e6b2e45 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 @@ -87,13 +87,15 @@ default ResponseEntity> findPetsByStatus(List status, final Pa * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * * @param tags Tags to filter by (required) + * @param size A test HeaderParam for issue #8315 - must NOT be removed when x-spring-paginated:true is used. (optional) * @return successful operation (status code 200) * or Invalid tag value (status code 400) * @deprecated * @see PetApi#findPetsByTags */ @Deprecated - default ResponseEntity> findPetsByTags(List tags, final Pageable pageable) { + default ResponseEntity> findPetsByTags(List tags, + String size, final Pageable pageable) { 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-spring-pageable-delegatePattern/src/main/resources/openapi.yaml b/samples/server/petstore/springboot-spring-pageable-delegatePattern/src/main/resources/openapi.yaml index e0a2517abd90..d711e92f27df 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 @@ -152,6 +152,38 @@ paths: type: string type: array style: form + - description: "A test HeaderParam for issue #8315 - must NOT be removed when\ + \ x-spring-paginated:true is used." + in: header + name: size + schema: + type: string + - description: "The number of items to return per page. Test QueryParam for\ + \ issue #8315 - must be removed when x-spring-paginated:true is used." + in: query + name: size + required: true + schema: + default: 20 + minimum: 1 + type: integer + - description: "The page to return, starting with page 0. Test QueryParam for\ + \ issue #8315 - must be removed when x-spring-paginated:true is used." + in: query + name: page + required: true + schema: + default: 0 + minimum: 0 + type: integer + - description: "The sorting to apply to the Pageable object. Test QueryParam\ + \ for issue #8315 - must be removed when x-spring-paginated:true is used." + in: query + name: sort + required: true + schema: + default: "id,asc" + type: string responses: "200": content: 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 f6c886ac94c8..47681b17cea1 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 @@ -166,6 +166,7 @@ default ResponseEntity> findPetsByStatus( * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * * @param tags Tags to filter by (required) + * @param size A test HeaderParam for issue #8315 - must NOT be removed when x-spring-paginated:true is used. (optional) * @return successful operation (status code 200) * or Invalid tag value (status code 400) * @deprecated @@ -196,6 +197,7 @@ default ResponseEntity> findPetsByStatus( ) default ResponseEntity> findPetsByTags( @NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) List tags, + @ApiParam(value = "A test HeaderParam for issue #8315 - must NOT be removed when x-spring-paginated:true is used.") @RequestHeader(value = "size", required = false) String size, @ApiIgnore final Pageable pageable ) { getRequest().ifPresent(request -> { 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 e0a2517abd90..d711e92f27df 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 @@ -152,6 +152,38 @@ paths: type: string type: array style: form + - description: "A test HeaderParam for issue #8315 - must NOT be removed when\ + \ x-spring-paginated:true is used." + in: header + name: size + schema: + type: string + - description: "The number of items to return per page. Test QueryParam for\ + \ issue #8315 - must be removed when x-spring-paginated:true is used." + in: query + name: size + required: true + schema: + default: 20 + minimum: 1 + type: integer + - description: "The page to return, starting with page 0. Test QueryParam for\ + \ issue #8315 - must be removed when x-spring-paginated:true is used." + in: query + name: page + required: true + schema: + default: 0 + minimum: 0 + type: integer + - description: "The sorting to apply to the Pageable object. Test QueryParam\ + \ for issue #8315 - must be removed when x-spring-paginated:true is used." + in: query + name: sort + required: true + schema: + default: "id,asc" + type: string responses: "200": content: 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 f6c886ac94c8..47681b17cea1 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 @@ -166,6 +166,7 @@ default ResponseEntity> findPetsByStatus( * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * * @param tags Tags to filter by (required) + * @param size A test HeaderParam for issue #8315 - must NOT be removed when x-spring-paginated:true is used. (optional) * @return successful operation (status code 200) * or Invalid tag value (status code 400) * @deprecated @@ -196,6 +197,7 @@ default ResponseEntity> findPetsByStatus( ) default ResponseEntity> findPetsByTags( @NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) List tags, + @ApiParam(value = "A test HeaderParam for issue #8315 - must NOT be removed when x-spring-paginated:true is used.") @RequestHeader(value = "size", required = false) String size, @ApiIgnore final Pageable pageable ) { getRequest().ifPresent(request -> { 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 e0a2517abd90..d711e92f27df 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 @@ -152,6 +152,38 @@ paths: type: string type: array style: form + - description: "A test HeaderParam for issue #8315 - must NOT be removed when\ + \ x-spring-paginated:true is used." + in: header + name: size + schema: + type: string + - description: "The number of items to return per page. Test QueryParam for\ + \ issue #8315 - must be removed when x-spring-paginated:true is used." + in: query + name: size + required: true + schema: + default: 20 + minimum: 1 + type: integer + - description: "The page to return, starting with page 0. Test QueryParam for\ + \ issue #8315 - must be removed when x-spring-paginated:true is used." + in: query + name: page + required: true + schema: + default: 0 + minimum: 0 + type: integer + - description: "The sorting to apply to the Pageable object. Test QueryParam\ + \ for issue #8315 - must be removed when x-spring-paginated:true is used." + in: query + name: sort + required: true + schema: + default: "id,asc" + type: string responses: "200": content: From 2bb8b9f773d4062b49fee41446e7e8e107a2593d Mon Sep 17 00:00:00 2001 From: Lucy <30p87@30p87.de> Date: Wed, 9 Apr 2025 14:31:33 +0200 Subject: [PATCH 2/2] Properly implement samples, fixing build issues --- docs/generators/java-camel.md | 3 +- docs/generators/spring.md | 3 +- ...dels-for-testing-with-spring-pageable.yaml | 32 +++++++++++++++++++ .../spring/petstore-with-spring-pageable.yaml | 32 +++++++++++++++++++ .../java/org/openapitools/api/PetApi.java | 2 +- .../src/main/resources/openapi.yaml | 9 ++++++ .../src/main/resources/openapi.yaml | 9 ++++++ .../src/main/resources/openapi.yaml | 9 ++++++ .../src/main/resources/openapi.yaml | 9 ++++++ 9 files changed, 103 insertions(+), 5 deletions(-) diff --git a/docs/generators/java-camel.md b/docs/generators/java-camel.md index b5a54843b44f..6916e9defea9 100644 --- a/docs/generators/java-camel.md +++ b/docs/generators/java-camel.md @@ -127,10 +127,9 @@ These options may be applied as additional-properties (cli) or configOptions (pl |x-class-extra-annotation|List of custom annotations to be added to model|MODEL|null |x-field-extra-annotation|List of custom annotations to be added to property|FIELD, OPERATION_PARAMETER|null |x-operation-extra-annotation|List of custom annotations to be added to operation|OPERATION|null -|x-spring-paginated|Add org.springframework.data.domain.Pageable to controller method. Can be used to handle page & size query parameters|OPERATION|false +|x-spring-paginated|Add `org.springframework.data.domain.Pageable` to controller method. Can be used to handle `page`, `size` and `sort` query parameters. If these query parameters are also specified in the operation spec, they will be removed from the controller method as their values can be obtained from the `Pageable` object.|OPERATION|false |x-version-param|Marker property that tells that this parameter would be used for endpoint versioning. Applicable for headers & query params. true/false|OPERATION_PARAMETER|null |x-pattern-message|Add this property whenever you need to customize the invalidation error message for the regex pattern of a variable|FIELD, OPERATION_PARAMETER|null -|x-spring-paginated|Add `org.springframework.data.domain.Pageable` to controller method. Can be used to handle `page`, `size` and `sort` query parameters. If these query parameters are also specified in the operation spec, they will be removed from the controller method as their values can be obtained from the `Pageable` object.|OPERATION|false ## IMPORT MAPPING diff --git a/docs/generators/spring.md b/docs/generators/spring.md index 2f511abe8d02..36ac0bc26895 100644 --- a/docs/generators/spring.md +++ b/docs/generators/spring.md @@ -120,10 +120,9 @@ These options may be applied as additional-properties (cli) or configOptions (pl |x-class-extra-annotation|List of custom annotations to be added to model|MODEL|null |x-field-extra-annotation|List of custom annotations to be added to property|FIELD, OPERATION_PARAMETER|null |x-operation-extra-annotation|List of custom annotations to be added to operation|OPERATION|null -|x-spring-paginated|Add org.springframework.data.domain.Pageable to controller method. Can be used to handle page & size query parameters|OPERATION|false +|x-spring-paginated|Add `org.springframework.data.domain.Pageable` to controller method. Can be used to handle `page`, `size` and `sort` query parameters. If these query parameters are also specified in the operation spec, they will be removed from the controller method as their values can be obtained from the `Pageable` object.|OPERATION|false |x-version-param|Marker property that tells that this parameter would be used for endpoint versioning. Applicable for headers & query params. true/false|OPERATION_PARAMETER|null |x-pattern-message|Add this property whenever you need to customize the invalidation error message for the regex pattern of a variable|FIELD, OPERATION_PARAMETER|null -|x-spring-paginated|Add `org.springframework.data.domain.Pageable` to controller method. Can be used to handle `page`, `size` and `sort` query parameters. If these query parameters are also specified in the operation spec, they will be removed from the controller method as their values can be obtained from the `Pageable` object.|OPERATION|false ## IMPORT MAPPING 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 0d3f66f4ab11..ba52d9622c0b 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 @@ -171,6 +171,38 @@ paths: type: array items: type: string + - description: "A test HeaderParam for issue #8315 - must NOT be removed when\ + \ x-spring-paginated:true is used." + in: header + name: size + schema: + type: string + - description: "The number of items to return per page. Test QueryParam for\ + \ issue #8315 - must be removed when x-spring-paginated:true is used." + in: query + name: size + required: true + schema: + default: 20 + minimum: 1 + type: integer + - description: "The page to return, starting with page 0. Test QueryParam for\ + \ issue #8315 - must be removed when x-spring-paginated:true is used." + in: query + name: page + required: true + schema: + default: 0 + minimum: 0 + type: integer + - description: "The sorting to apply to the Pageable object. Test QueryParam\ + \ for issue #8315 - must be removed when x-spring-paginated:true is used." + in: query + name: sort + required: true + schema: + default: "id,asc" + type: string responses: 200: description: successful operation diff --git a/modules/openapi-generator/src/test/resources/3_0/spring/petstore-with-spring-pageable.yaml b/modules/openapi-generator/src/test/resources/3_0/spring/petstore-with-spring-pageable.yaml index bd045d282629..dcf0075a21f0 100644 --- a/modules/openapi-generator/src/test/resources/3_0/spring/petstore-with-spring-pageable.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/spring/petstore-with-spring-pageable.yaml @@ -136,6 +136,38 @@ paths: type: array items: type: string + - description: "A test HeaderParam for issue #8315 - must NOT be removed when\ + \ x-spring-paginated:true is used." + in: header + name: size + schema: + type: string + - description: "The number of items to return per page. Test QueryParam for\ + \ issue #8315 - must be removed when x-spring-paginated:true is used." + in: query + name: size + required: true + schema: + default: 20 + minimum: 1 + type: integer + - description: "The page to return, starting with page 0. Test QueryParam for\ + \ issue #8315 - must be removed when x-spring-paginated:true is used." + in: query + name: page + required: true + schema: + default: 0 + minimum: 0 + type: integer + - description: "The sorting to apply to the Pageable object. Test QueryParam\ + \ for issue #8315 - must be removed when x-spring-paginated:true is used." + in: query + name: sort + required: true + schema: + default: "id,asc" + type: string responses: 200: description: successful operation diff --git a/samples/openapi3/client/petstore/spring-cloud-spring-pageable/src/main/java/org/openapitools/api/PetApi.java b/samples/openapi3/client/petstore/spring-cloud-spring-pageable/src/main/java/org/openapitools/api/PetApi.java index 8fa6de298429..94a59908371c 100644 --- a/samples/openapi3/client/petstore/spring-cloud-spring-pageable/src/main/java/org/openapitools/api/PetApi.java +++ b/samples/openapi3/client/petstore/spring-cloud-spring-pageable/src/main/java/org/openapitools/api/PetApi.java @@ -169,7 +169,7 @@ ResponseEntity> findPetsByStatus( ResponseEntity> findPetsByTags( @NotNull @Parameter(name = "tags", description = "Tags to filter by", required = true, in = ParameterIn.QUERY) @Valid @RequestParam(value = "tags", required = true) List tags, - @Parameter(name = "size", description = "A test HeaderParam for issue #8315 - must NOT be removed when x-spring-paginated:true is used.") @RequestHeader(value = "size", required = false) String size, + @Parameter(name = "size", description = "A test HeaderParam for issue #8315 - must NOT be removed when x-spring-paginated:true is used.", in = ParameterIn.HEADER) @RequestHeader(value = "size", required = false) String size, @ParameterObject final Pageable pageable ); 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 b7b6db24fb3f..615aa861b548 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 @@ -191,12 +191,16 @@ paths: style: form - description: "A test HeaderParam for issue #8315 - must NOT be removed when\ \ x-spring-paginated:true is used." + explode: false in: header name: size + required: false schema: type: string + style: simple - description: "The number of items to return per page. Test QueryParam for\ \ issue #8315 - must be removed when x-spring-paginated:true is used." + explode: true in: query name: size required: true @@ -204,8 +208,10 @@ paths: default: 20 minimum: 1 type: integer + style: form - description: "The page to return, starting with page 0. Test QueryParam for\ \ issue #8315 - must be removed when x-spring-paginated:true is used." + explode: true in: query name: page required: true @@ -213,14 +219,17 @@ paths: default: 0 minimum: 0 type: integer + style: form - description: "The sorting to apply to the Pageable object. Test QueryParam\ \ for issue #8315 - must be removed when x-spring-paginated:true is used." + explode: true in: query name: sort required: true schema: default: "id,asc" type: string + style: form responses: "200": content: 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 b7b6db24fb3f..615aa861b548 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 @@ -191,12 +191,16 @@ paths: style: form - description: "A test HeaderParam for issue #8315 - must NOT be removed when\ \ x-spring-paginated:true is used." + explode: false in: header name: size + required: false schema: type: string + style: simple - description: "The number of items to return per page. Test QueryParam for\ \ issue #8315 - must be removed when x-spring-paginated:true is used." + explode: true in: query name: size required: true @@ -204,8 +208,10 @@ paths: default: 20 minimum: 1 type: integer + style: form - description: "The page to return, starting with page 0. Test QueryParam for\ \ issue #8315 - must be removed when x-spring-paginated:true is used." + explode: true in: query name: page required: true @@ -213,14 +219,17 @@ paths: default: 0 minimum: 0 type: integer + style: form - description: "The sorting to apply to the Pageable object. Test QueryParam\ \ for issue #8315 - must be removed when x-spring-paginated:true is used." + explode: true in: query name: sort required: true schema: default: "id,asc" type: string + style: form responses: "200": content: 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 b7b6db24fb3f..615aa861b548 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 @@ -191,12 +191,16 @@ paths: style: form - description: "A test HeaderParam for issue #8315 - must NOT be removed when\ \ x-spring-paginated:true is used." + explode: false in: header name: size + required: false schema: type: string + style: simple - description: "The number of items to return per page. Test QueryParam for\ \ issue #8315 - must be removed when x-spring-paginated:true is used." + explode: true in: query name: size required: true @@ -204,8 +208,10 @@ paths: default: 20 minimum: 1 type: integer + style: form - description: "The page to return, starting with page 0. Test QueryParam for\ \ issue #8315 - must be removed when x-spring-paginated:true is used." + explode: true in: query name: page required: true @@ -213,14 +219,17 @@ paths: default: 0 minimum: 0 type: integer + style: form - description: "The sorting to apply to the Pageable object. Test QueryParam\ \ for issue #8315 - must be removed when x-spring-paginated:true is used." + explode: true in: query name: sort required: true schema: default: "id,asc" type: string + style: form responses: "200": content: 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 b7b6db24fb3f..615aa861b548 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 @@ -191,12 +191,16 @@ paths: style: form - description: "A test HeaderParam for issue #8315 - must NOT be removed when\ \ x-spring-paginated:true is used." + explode: false in: header name: size + required: false schema: type: string + style: simple - description: "The number of items to return per page. Test QueryParam for\ \ issue #8315 - must be removed when x-spring-paginated:true is used." + explode: true in: query name: size required: true @@ -204,8 +208,10 @@ paths: default: 20 minimum: 1 type: integer + style: form - description: "The page to return, starting with page 0. Test QueryParam for\ \ issue #8315 - must be removed when x-spring-paginated:true is used." + explode: true in: query name: page required: true @@ -213,14 +219,17 @@ paths: default: 0 minimum: 0 type: integer + style: form - description: "The sorting to apply to the Pageable object. Test QueryParam\ \ for issue #8315 - must be removed when x-spring-paginated:true is used." + explode: true in: query name: sort required: true schema: default: "id,asc" type: string + style: form responses: "200": content: