[JAVA-SPRING,KOTLIN-SPRING] - feature: validate Pageable params [size, page, sort] and preserve defaults; add PagedModel<T> support; Add 'autoXSpringPaginated' to java-spring#23575
Merged
wing328 merged 48 commits intoOpenAPITools:masterfrom Apr 21, 2026
Merged
Conversation
Calling getPageSize()/getPageNumber() on Pageable.unpaged() throws UnsupportedOperationException. Add an isPaged() check so unpaged requests pass validation without error.
…pageable' into feature/add-enum-validation-for-pageable
…lace with generic
…lace with generic
…annotation for springdoc
6 tasks
…aged-model # Conflicts: # modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/buildGradle-sb3-Kts.mustache # samples/server/petstore/kotlin-spring-sealed-interfaces/build.gradle.kts # samples/server/petstore/kotlin-springboot-3-no-response-entity/build.gradle.kts # samples/server/petstore/kotlin-springboot-3/build.gradle.kts # samples/server/petstore/kotlin-springboot-additionalproperties/build.gradle.kts # samples/server/petstore/kotlin-springboot-delegate-nodefaults/build.gradle.kts # samples/server/petstore/kotlin-springboot-integer-enum/build.gradle.kts # samples/server/petstore/kotlin-springboot-request-cookie/build.gradle.kts
This was referenced Apr 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The idea behind this PR is the fact that currently when
page,size,sortare substituted withPageable, then the default values forpage,size,sortare lost andPageabledefaults toglobal spring defaults(size = 10; page = 0). The native spring annotation@PageableDefaultmakes it possible to respect the defaults specified in the api spec. Native spring annotation@SortDefault.SortDefaults(...)on the other hand preserves the sort default value if it exists.Another issue stemming from conversion of
page,size,sorttoPageableis the loss of query param validations. This PR implements two custom validators (@ValidPageableand@ValidSort) that verify the validity of the passed values and fail if the values are out of spec. These validators should be easily replaceable with custom implementations viaimportMapping- this might be useful if one has some non-standard sort params and wants to handle the validation in a specific way.So all together this PR makes sure that the convenience provided by conversion from separate query params
page,size,sorttoPageabledoes not result in less strict contract in the generated api.Some of the logic is extracted to separate class on purpose. Since I would like to implement this also in java-spring generator for feature parity.
Edit: This PR now supports java-spring as well. For feature parity I also added the
autoXSpringPaginated, which can automatically convert all cases ofpage,size,sortparams to a singlePageable(and can be disabled per operation by settingx-spring-paginated: falseEdit2: This PR now also supports replacement of DTOs matching
PagedModelshape like:{ "content": [], "page": { "size": 10, "number": 0, "totalElements": 1, "totalPages": 1 } }to generic version of the
PagedModel<type-of-content-array>in both java-spring and kotlin-spring generatorEverything besides @PageableDefault in this PR is opt-in
This is a version of #23518 with the PagedModel functionality added.
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)Summary by cubic
Adds opt‑in validation for Spring
Pageableandsortparams, auto‑detects paginated endpoints, preserves defaults via@PageableDefault, and substitutes genericPagedModel<T>for paged responses inspringandkotlin-spring.New Features
@ValidPageableto enforcepage/sizemax constraints from the OpenAPI schema (generatePageableConstraintValidation), safely skippingPageable.unpaged().@ValidSortto validatesortvalues against an enum, supporting exploded and non‑exploded array styles (generateSortValidation).x-spring-paginatedwhenpage+size+sortare present (autoXSpringPaginated), respecting per‑operation opt‑out (x-spring-paginated: false) and available injava-spring.PagedModel<T>via schema scanning (substituteGenericPagedModel), preserving the original schema when needed for@ApiResponse/springdoc.@PageableDefaultwhen defaults are defined forpage/size.Migration
useBeanValidationinstead of deprecatedbeanValidations; docs and samples updated.useBeanValidation=true, addorg.springframework.boot:spring-boot-starter-validationin Kotlin Spring Boot templates.3.3.13.Written for commit 8aefea4. Summary will update on new commits.