Skip to content

[Java][Spring] remove 'size', 'page' and 'sort' query params if using 'x-spring-paginated' (#8315) #14064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/generators/java-camel.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/generators/spring.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>/Flux<T>` or `return T/List<T>/Set<T>` & execute `.block()` inside generated method)", "false"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,8 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> 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<Server> servers) {
Expand All @@ -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<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ ResponseEntity<List<Pet>> 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
Expand Down Expand Up @@ -165,6 +166,7 @@ ResponseEntity<List<Pet>> findPetsByStatus(
)
ResponseEntity<List<Pet>> findPetsByTags(
@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) List<String> 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
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ ResponseEntity<List<Pet>> 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
Expand Down Expand Up @@ -158,6 +159,7 @@ ResponseEntity<List<Pet>> findPetsByStatus(
)
ResponseEntity<List<Pet>> findPetsByTags(
@NotNull @Parameter(name = "tags", description = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) List<String> 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
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ default ResponseEntity<List<Pet>> 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
Expand Down Expand Up @@ -175,9 +176,10 @@ default ResponseEntity<List<Pet>> findPetsByStatus(
)
default ResponseEntity<List<Pet>> findPetsByTags(
@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) List<String> 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);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ default ResponseEntity<List<Pet>> findPetsByStatus(List<String> 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<List<Pet>> findPetsByTags(List<String> tags, final Pageable pageable) {
default ResponseEntity<List<Pet>> findPetsByTags(List<String> tags,
String size, final Pageable pageable) {
getRequest().ifPresent(request -> {
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ default ResponseEntity<List<Pet>> 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
Expand Down Expand Up @@ -175,9 +176,10 @@ default ResponseEntity<List<Pet>> findPetsByStatus(
)
default ResponseEntity<List<Pet>> findPetsByTags(
@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) List<String> 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);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ default ResponseEntity<List<Pet>> findPetsByStatus(List<String> 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<List<Pet>> findPetsByTags(List<String> tags, final Pageable pageable) {
default ResponseEntity<List<Pet>> findPetsByTags(List<String> tags,
String size, final Pageable pageable) {
getRequest().ifPresent(request -> {
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ default ResponseEntity<List<Pet>> 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
Expand Down Expand Up @@ -196,6 +197,7 @@ default ResponseEntity<List<Pet>> findPetsByStatus(
)
default ResponseEntity<List<Pet>> findPetsByTags(
@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) List<String> 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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ default ResponseEntity<List<Pet>> 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
Expand Down Expand Up @@ -196,6 +197,7 @@ default ResponseEntity<List<Pet>> findPetsByStatus(
)
default ResponseEntity<List<Pet>> findPetsByTags(
@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) List<String> 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 -> {
Expand Down
Loading