Skip to content

Commit 979c44b

Browse files
PicazsooCopilot
andauthored
[JAVA-SPRING;KOTLIN-SPRING] improvement: Allow autoXSpringPaginated for endpoints without sort (#24863)
* Allow autoXSpringPaginated for endpoints without sort Change autoXSpringPaginated from a boolean switch into a string-enum option with three canonical values: - none: disable auto-detection (default) - page-size-sort: require page, size, and sort query parameters (identical to the previous true behavior) - page-size: require only page and size; sort may be absent (new) The legacy true/false values are still accepted as deprecated aliases for page-size-sort/none respectively. A deprecation warning is logged once via the generator logger only when the option is explicitly set to true/false; leaving the option unset keeps the silent none default with no warning. - Add SpringPageableScanUtils.AutoPaginationMode enum and resolveAutoPaginationMode() to centralize parsing/validation/deprecation warnings shared by SpringCodegen and KotlinSpringServerCodegen. - Update willBePageable, applyAutoXSpringPaginatedIfNeeded, and the scanSortValidationEnums/scanPageableDefaults/scanPageableConstraints/ scanAll methods to take AutoPaginationMode instead of boolean. - Replace the boolean CLI switch with a documented string-enum CLI option in SpringCodegen and KotlinSpringServerCodegen (JavaCamelServerCodegen inherits the behavior since it extends SpringCodegen). - Update existing tests to use the new enum where internal signatures changed; add new tests for page-size mode detection, deprecation warnings (once when explicit, never when unset), and invalid values. - Regenerate docs/generators/{spring,kotlin-spring,java-camel}.md. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Restore autoXSpringPaginated setter compatibility Preserve public string and deprecated boolean setter APIs for Spring and Kotlin Spring generators. Keep Kotlin autoXSpringPaginated absent from additionalProperties when it is unset, matching Spring behavior. Replace binding-dependent logback test capture with direct setter and option-state assertions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Centralize autoXSpringPaginated option values Share the immutable auto-pagination CLI enum map from SpringPageableScanUtils so Spring and Kotlin Spring generators cannot diverge. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix pageable scanAll Javadoc reference Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * remove sample file * Revert "remove sample file" This reverts commit c6bcdb2. * Fix PR review findings in SpringPageableScanUtils - Filter resolved parameters to in:query before checking required names in willBePageable(), so non-query parameters named 'page'/ 'size' no longer cause PAGE_SIZE auto-detection false positives. - Guard the legacy true/false deprecation warning in SpringCodegen/KotlinSpringServerCodegen's setAutoXSpringPaginated setters with a per-instance flag, so repeated setter/option- processing calls only log the warning once. - Add regression test for path/header parameters named page/size not triggering PAGE_SIZE auto-detection. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Restore deprecation-warning tests and add missing regression coverage - Restore logback ListAppender tests in SpringCodegenTest and KotlinSpringServerCodegenTest asserting the legacy true/false deprecation warning is logged exactly once when explicitly set and not at all when unset, plus a new test proving the setter's once-only guard suppresses a second warning when invoked twice with the same legacy value. - Add willBePageable_pageSizeSortMode_doesNotDetectPathParamNamedSort to lock in the query-location filter for PAGE_SIZE_SORT (previously only regression-tested for PAGE_SIZE). - Add .in("query") to the page/size params in applyAutoXSpringPaginatedIfNeeded_autoDisabled_doesNotSetExtension and applyAutoXSpringPaginatedIfNeeded_explicitlyFalse_returnsFalseAndIsNotOverridden so they exercise real auto-detection instead of passing trivially. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Filter ListAppender events by thread in deprecation-warning tests Surefire runs test classes in parallel (parallel=classes, threadCountClasses=3), and SpringCodegen/KotlinSpringServerCodegen log through a shared per-class-name logback Logger inherited by all subclasses. A ListAppender attached to that logger during these tests could capture log events emitted by concurrently-running test classes on other threads, causing flaky/incorrect exactly-once and no-warning assertions. Filter captured events to the current test thread before asserting. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Snapshot ListAppender events under the appender lock in deprecation-warning tests ListAppender.list is a plain ArrayList that concurrently-running test classes may still append to. Copy it while holding the appender monitor (the same lock AppenderBase.doAppend uses) before filtering by thread. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * update samples * Validate autoXSpringPaginated for all libraries and dedupe warn-once logic - Resolve and validate an explicitly supplied autoXSpringPaginated value in SpringCodegen and KotlinSpringServerCodegen regardless of library, so invalid values are no longer silently ignored for spring-http-interface / spring-declarative-http-interface. Write-back and usage remain gated by isPageableSupported(). - Move the once-only deprecation-warning guard into SpringPageableScanUtils.warnOnce(Consumer) shared by both generators. - Extract a countDeprecationWarnings(Runnable) helper in the Spring and Kotlin Spring codegen tests, and add regression tests for validation on unsupported libraries and for warnOnce. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Extract shared log-capture helper into TestUtils Move the ListAppender attach/detach, monitor-guarded snapshot and current-thread filtering duplicated in SpringCodegenTest and KotlinSpringServerCodegenTest into TestUtils.captureLogMessages, leaving a thin per-class countDeprecationWarnings wrapper. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Simplify autoXSpringPaginated deprecation warning The setter is only called once per generation (from processOpts), so the warn-once machinery guarded a case that never occurs in practice. - Make SpringPageableScanUtils.resolveAutoPaginationMode(String) pure. - Add package-private warnIfDeprecatedAutoPaginationValue, called once from processOpts in SpringCodegen and KotlinSpringServerCodegen; it shares value normalization with resolve. - Remove warnOnce and the per-generator guard fields. - Adapt tests and drop the ones made redundant by the processOpts-logs-exactly-once tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix archunit violation * Fix static-context compile error by making warnIfDeprecatedAutoPaginationValue instance method LOGGER in SpringPageableScanUtils is intentionally a non-static instance field (enforced by ArchUnitRulesTest to limit memory use across generator instances), so it cannot be referenced from a static method. Change warnIfDeprecatedAutoPaginationValue from static to instance scope and call it via the existing pageableUtils instance in SpringCodegen and KotlinSpringServerCodegen. Update the corresponding unit tests to invoke it on a SpringPageableScanUtils instance. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d7dd6d0 commit 979c44b

10 files changed

Lines changed: 649 additions & 84 deletions

File tree

‎docs/generators/java-camel.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
3131
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
3232
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename. If not provided, uses the version from the OpenAPI specification file. If that's also not present, uses the default value of the artifactVersion option.| |1.0.0|
3333
|async|use async Callable controllers| |false|
34-
|autoXSpringPaginated|Automatically add x-spring-paginated to operations that have 'page', 'size', and 'sort' query parameters. When enabled, operations with all three parameters will have Pageable support automatically applied. Operations with x-spring-paginated explicitly set to false will not be auto-detected. Only applies when library is spring-boot or spring-cloud.| |false|
34+
|autoXSpringPaginated|Automatically add x-spring-paginated to operations that have the given set of pagination query parameters. 'page-size-sort' requires 'page', 'size', and 'sort'; 'page-size' requires only 'page' and 'size' (sort may be absent). Operations with x-spring-paginated explicitly set to false will not be auto-detected. Only applies when library is spring-boot or spring-cloud. The legacy values 'true' (alias for 'page-size-sort') and 'false' (alias for 'none') are deprecated and will be removed in a future release.|<dl><dt>**none**</dt><dd>Disable auto-detection.</dd><dt>**page-size-sort**</dt><dd>Require 'page', 'size', and 'sort' query parameters.</dd><dt>**page-size**</dt><dd>Require only 'page' and 'size' query parameters.</dd><dt>**true**</dt><dd>(deprecated) alias for 'page-size-sort'.</dd><dt>**false**</dt><dd>(deprecated) alias for 'none'.</dd></dl>|none|
3535
|basePackage|base package (invokerPackage) for generated code| |org.openapitools|
3636
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
3737
|booleanGetterPrefix|Set booleanGetterPrefix| |get|

‎docs/generators/kotlin-spring.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
2424
|apiPackage|api package for generated code| |org.openapitools.api|
2525
|artifactId|Generated artifact id (name of jar).| |openapi-spring|
2626
|artifactVersion|Generated artifact's package version.| |1.0.0|
27-
|autoXSpringPaginated|Automatically add x-spring-paginated to operations that have 'page', 'size', and 'sort' query parameters. When enabled, operations with all three parameters will have Pageable support automatically applied. Operations with x-spring-paginated explicitly set to false will not be auto-detected.| |false|
27+
|autoXSpringPaginated|Automatically add x-spring-paginated to operations that have the given set of pagination query parameters. 'page-size-sort' requires 'page', 'size', and 'sort'; 'page-size' requires only 'page' and 'size' (sort may be absent). Operations with x-spring-paginated explicitly set to false will not be auto-detected. The legacy values 'true' (alias for 'page-size-sort') and 'false' (alias for 'none') are deprecated and will be removed in a future release.|<dl><dt>**none**</dt><dd>Disable auto-detection.</dd><dt>**page-size-sort**</dt><dd>Require 'page', 'size', and 'sort' query parameters.</dd><dt>**page-size**</dt><dd>Require only 'page' and 'size' query parameters.</dd><dt>**true**</dt><dd>(deprecated) alias for 'page-size-sort'.</dd><dt>**false**</dt><dd>(deprecated) alias for 'none'.</dd></dl>|none|
2828
|basePackage|base package (invokerPackage) for generated code| |org.openapitools|
2929
|beanQualifiers|Whether to add fully-qualifier class names as bean qualifiers in @Component and @RestController annotations. May be used to prevent bean names clash if multiple generated libraries (contexts) added to single project.| |false|
3030
|companionObject|Whether to generate companion objects in data classes, enabling companion extensions.| |false|

‎docs/generators/spring.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
3131
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
3232
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename. If not provided, uses the version from the OpenAPI specification file. If that's also not present, uses the default value of the artifactVersion option.| |1.0.0|
3333
|async|use async Callable controllers| |false|
34-
|autoXSpringPaginated|Automatically add x-spring-paginated to operations that have 'page', 'size', and 'sort' query parameters. When enabled, operations with all three parameters will have Pageable support automatically applied. Operations with x-spring-paginated explicitly set to false will not be auto-detected. Only applies when library is spring-boot or spring-cloud.| |false|
34+
|autoXSpringPaginated|Automatically add x-spring-paginated to operations that have the given set of pagination query parameters. 'page-size-sort' requires 'page', 'size', and 'sort'; 'page-size' requires only 'page' and 'size' (sort may be absent). Operations with x-spring-paginated explicitly set to false will not be auto-detected. Only applies when library is spring-boot or spring-cloud. The legacy values 'true' (alias for 'page-size-sort') and 'false' (alias for 'none') are deprecated and will be removed in a future release.|<dl><dt>**none**</dt><dd>Disable auto-detection.</dd><dt>**page-size-sort**</dt><dd>Require 'page', 'size', and 'sort' query parameters.</dd><dt>**page-size**</dt><dd>Require only 'page' and 'size' query parameters.</dd><dt>**true**</dt><dd>(deprecated) alias for 'page-size-sort'.</dd><dt>**false**</dt><dd>(deprecated) alias for 'none'.</dd></dl>|none|
3535
|basePackage|base package (invokerPackage) for generated code| |org.openapitools|
3636
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
3737
|booleanGetterPrefix|Set booleanGetterPrefix| |get|

‎modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinSpringServerCodegen.java‎

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,27 @@ public enum RequestMappingMode {
176176
@Setter private boolean beanQualifiers = false;
177177
@Setter private DeclarativeInterfaceReactiveMode declarativeInterfaceReactiveMode = DeclarativeInterfaceReactiveMode.coroutines;
178178
@Setter private boolean useResponseEntity = true;
179-
@Setter private boolean autoXSpringPaginated = false;
179+
@Getter private String autoXSpringPaginated = SpringPageableScanUtils.AUTO_PAGINATION_MODE_NONE;
180+
@Getter private SpringPageableScanUtils.AutoPaginationMode autoXSpringPaginatedMode = SpringPageableScanUtils.AutoPaginationMode.NONE;
181+
/**
182+
* Configures automatic Spring Pageable detection using a canonical mode or legacy boolean alias.
183+
*
184+
* @param autoXSpringPaginated the configured mode
185+
*/
186+
public void setAutoXSpringPaginated(String autoXSpringPaginated) {
187+
autoXSpringPaginatedMode = SpringPageableScanUtils.resolveAutoPaginationMode(autoXSpringPaginated);
188+
this.autoXSpringPaginated = autoXSpringPaginatedMode.getCanonicalValue();
189+
}
190+
191+
/**
192+
* @deprecated Use {@link #setAutoXSpringPaginated(String)} with {@code page-size-sort} or
193+
* {@code none}.
194+
*/
195+
@Deprecated
196+
public void setAutoXSpringPaginated(boolean autoXSpringPaginated) {
197+
setAutoXSpringPaginated(Boolean.toString(autoXSpringPaginated));
198+
}
199+
180200
@Setter private boolean generateSortValidation = false;
181201
@Setter private boolean generatePageableConstraintValidation = false;
182202
@Setter private boolean substituteGenericPagedModel = false;
@@ -313,7 +333,13 @@ public KotlinSpringServerCodegen() {
313333
addOption(X_KOTLIN_IMPLEMENTS_FIELDS_SKIP, "A list of fields per schema name that should NOT be created with `override` keyword despite their presence in vendor extension `x-kotlin-implements-fields` for the schema. Example: yaml `xKotlinImplementsFieldsSkip: Pet: [photoUrls]` skips `override` for `photoUrls` in schema `Pet`", "empty map");
314334
addOption(SCHEMA_IMPLEMENTS, "A map of single interface or a list of interfaces per schema name that should be implemented (serves similar purpose as `x-kotlin-implements`, but is fully decoupled from the api spec). Example: yaml `schemaImplements: {Pet: com.some.pack.WithId, Category: [com.some.pack.CategoryInterface], Dog: [com.some.pack.Canine, com.some.pack.OtherInterface]}` implements interfaces in schemas `Pet` (interface `com.some.pack.WithId`), `Category` (interface `com.some.pack.CategoryInterface`), `Dog`(interfaces `com.some.pack.Canine`, `com.some.pack.OtherInterface`)", "empty map");
315335
addOption(SCHEMA_IMPLEMENTS_FIELDS, "A map of single field or a list of fields per schema name that should be prepended with `override` (serves similar purpose as `x-kotlin-implements-fields`, but is fully decoupled from the api spec). Example: yaml `schemaImplementsFields: {Pet: id, Category: [name, id], Dog: [bark, breed]}` marks fields to be prepended with `override` in schemas `Pet` (field `id`), `Category` (fields `name`, `id`) and `Dog` (fields `bark`, `breed`)", "empty map");
316-
addSwitch(AUTO_X_SPRING_PAGINATED, "Automatically add x-spring-paginated to operations that have 'page', 'size', and 'sort' query parameters. When enabled, operations with all three parameters will have Pageable support automatically applied. Operations with x-spring-paginated explicitly set to false will not be auto-detected.", autoXSpringPaginated);
336+
addOption(AUTO_X_SPRING_PAGINATED,
337+
"Automatically add x-spring-paginated to operations that have the given set of pagination query "
338+
+ "parameters. 'page-size-sort' requires 'page', 'size', and 'sort'; 'page-size' requires only "
339+
+ "'page' and 'size' (sort may be absent). Operations with x-spring-paginated explicitly set to "
340+
+ "false will not be auto-detected. The legacy values 'true' (alias for 'page-size-sort') and "
341+
+ "'false' (alias for 'none') are deprecated and will be removed in a future release.",
342+
autoXSpringPaginated, SpringPageableScanUtils.getAutoPaginationModeEnumValues());
317343
addSwitch(GENERATE_SORT_VALIDATION, "Generate a @ValidSort annotation and SortValidator class, and apply @ValidSort to the injected Pageable parameter of operations whose 'sort' parameter has enum values. The annotation validates that sort values in the Pageable object match the allowed enum values from the spec. Requires useBeanValidation=true and library is spring-boot or spring-cloud.", generateSortValidation);
318344
addSwitch(GENERATE_PAGEABLE_CONSTRAINT_VALIDATION, "Generate a @ValidPageable annotation and PageableConstraintValidator class, and apply @ValidPageable to the injected Pageable parameter of operations whose 'page' or 'size' parameter specifies a maximum constraint. The annotation enforces those constraints on the Pageable object that replaces the individual page/size query parameters. Requires useBeanValidation=true and library is spring-boot or spring-cloud.", generatePageableConstraintValidation);
319345
addSwitch(SUBSTITUTE_GENERIC_PAGED_MODEL,
@@ -830,10 +856,16 @@ public void processOpts() {
830856
if (additionalProperties.containsKey(USE_TAGS)) {
831857
this.setUseTags(Boolean.parseBoolean(additionalProperties.get(USE_TAGS).toString()));
832858
}
833-
if (additionalProperties.containsKey(AUTO_X_SPRING_PAGINATED) && isPageableSupported()) {
834-
this.setAutoXSpringPaginated(convertPropertyToBoolean(AUTO_X_SPRING_PAGINATED));
859+
// Validate an explicitly supplied value for every library so typos are not silently ignored;
860+
// the resolved mode is only used (and written back) when Pageable is supported.
861+
if (additionalProperties.containsKey(AUTO_X_SPRING_PAGINATED)) {
862+
String rawAutoXSpringPaginated = String.valueOf(additionalProperties.get(AUTO_X_SPRING_PAGINATED));
863+
pageableUtils.warnIfDeprecatedAutoPaginationValue(rawAutoXSpringPaginated);
864+
setAutoXSpringPaginated(rawAutoXSpringPaginated);
865+
if (isPageableSupported()) {
866+
writePropertyBack(AUTO_X_SPRING_PAGINATED, autoXSpringPaginated);
867+
}
835868
}
836-
writePropertyBack(AUTO_X_SPRING_PAGINATED, autoXSpringPaginated);
837869
if (additionalProperties.containsKey(GENERATE_SORT_VALIDATION) && isPageableSupported()) {
838870
this.setGenerateSortValidation(convertPropertyToBoolean(GENERATE_SORT_VALIDATION));
839871
}
@@ -1173,7 +1205,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
11731205
// Only for libraries that support Pageable; respect manual x-spring-paginated: false override.
11741206
if (isPageableSupported()) {
11751207
SpringPageableScanUtils.applyAutoXSpringPaginatedIfNeeded(
1176-
openAPI, operation, autoXSpringPaginated);
1208+
openAPI, operation, autoXSpringPaginatedMode);
11771209
}
11781210

11791211
CodegenOperation codegenOperation = super.fromOperation(path, httpMethod, operation, servers);
@@ -1253,7 +1285,7 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
12531285
}
12541286

12551287
if (isPageableSupported()) {
1256-
pageableUtils.scanAll(openAPI, autoXSpringPaginated);
1288+
pageableUtils.scanAll(openAPI, autoXSpringPaginatedMode);
12571289

12581290
if (generateSortValidation && useBeanValidation && !pageableUtils.sortValidationEnums.isEmpty()) {
12591291
importMapping.putIfAbsent("ValidSort", configPackage + ".ValidSort");

‎modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java‎

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,27 @@ public enum RequestMappingMode {
208208
@Getter @Setter
209209
protected boolean additionalNotNullAnnotations = false;
210210
@Setter boolean useHttpServiceProxyFactoryInterfacesConfigurator = false;
211-
@Setter protected boolean autoXSpringPaginated = false;
211+
@Getter protected String autoXSpringPaginated = SpringPageableScanUtils.AUTO_PAGINATION_MODE_NONE;
212+
@Getter private SpringPageableScanUtils.AutoPaginationMode autoXSpringPaginatedMode = SpringPageableScanUtils.AutoPaginationMode.NONE;
213+
/**
214+
* Configures automatic Spring Pageable detection using a canonical mode or legacy boolean alias.
215+
*
216+
* @param autoXSpringPaginated the configured mode
217+
*/
218+
public void setAutoXSpringPaginated(String autoXSpringPaginated) {
219+
autoXSpringPaginatedMode = SpringPageableScanUtils.resolveAutoPaginationMode(autoXSpringPaginated);
220+
this.autoXSpringPaginated = autoXSpringPaginatedMode.getCanonicalValue();
221+
}
222+
223+
/**
224+
* @deprecated Use {@link #setAutoXSpringPaginated(String)} with {@code page-size-sort} or
225+
* {@code none}.
226+
*/
227+
@Deprecated
228+
public void setAutoXSpringPaginated(boolean autoXSpringPaginated) {
229+
setAutoXSpringPaginated(Boolean.toString(autoXSpringPaginated));
230+
}
231+
212232
@Setter protected boolean generateSortValidation = false;
213233
@Setter protected boolean generatePageableConstraintValidation = false;
214234
@Setter protected boolean substituteGenericPagedModel = false;
@@ -409,12 +429,16 @@ public SpringCodegen() {
409429
cliOptions.add(CliOption.newBoolean(ADDITIONAL_NOT_NULL_ANNOTATIONS,
410430
"Add @NotNull to path variables (required by default) and requestBody.",
411431
additionalNotNullAnnotations));
412-
cliOptions.add(CliOption.newBoolean(AUTO_X_SPRING_PAGINATED,
413-
"Automatically add x-spring-paginated to operations that have 'page', 'size', and 'sort' query parameters. "
414-
+ "When enabled, operations with all three parameters will have Pageable support automatically applied. "
415-
+ "Operations with x-spring-paginated explicitly set to false will not be auto-detected. "
416-
+ "Only applies when library is spring-boot or spring-cloud.",
417-
autoXSpringPaginated));
432+
final CliOption autoXSpringPaginatedOption = new CliOption(AUTO_X_SPRING_PAGINATED,
433+
"Automatically add x-spring-paginated to operations that have the given set of pagination query "
434+
+ "parameters. 'page-size-sort' requires 'page', 'size', and 'sort'; 'page-size' requires only "
435+
+ "'page' and 'size' (sort may be absent). Operations with x-spring-paginated explicitly set to "
436+
+ "false will not be auto-detected. Only applies when library is spring-boot or spring-cloud. "
437+
+ "The legacy values 'true' (alias for 'page-size-sort') and 'false' (alias for 'none') are "
438+
+ "deprecated and will be removed in a future release.")
439+
.defaultValue(autoXSpringPaginated);
440+
autoXSpringPaginatedOption.setEnum(SpringPageableScanUtils.getAutoPaginationModeEnumValues());
441+
cliOptions.add(autoXSpringPaginatedOption);
418442
cliOptions.add(CliOption.newBoolean(GENERATE_SORT_VALIDATION,
419443
"Generate a @ValidSort annotation and SortValidator class, and apply @ValidSort to "
420444
+ "the injected Pageable parameter of operations whose 'sort' parameter has enum values. "
@@ -694,8 +718,17 @@ public void processOpts() {
694718
convertPropertyToBooleanAndWriteBack(SUBSTITUTE_GENERIC_PAGED_MODEL, this::setSubstituteGenericPagedModel);
695719
convertPropertyToBooleanAndWriteBack(CodegenConstants.USE_ENUM_VALUE_INTERFACE, this::setUseEnumValueInterface);
696720

721+
// Validate an explicitly supplied value for every library so typos are not silently ignored;
722+
// the resolved mode is only used (and written back) when Pageable is supported.
723+
if (additionalProperties.containsKey(AUTO_X_SPRING_PAGINATED)) {
724+
String rawAutoXSpringPaginated = String.valueOf(additionalProperties.get(AUTO_X_SPRING_PAGINATED));
725+
pageableUtils.warnIfDeprecatedAutoPaginationValue(rawAutoXSpringPaginated);
726+
setAutoXSpringPaginated(rawAutoXSpringPaginated);
727+
}
697728
if (isPageableSupported()) {
698-
convertPropertyToBooleanAndWriteBack(AUTO_X_SPRING_PAGINATED, this::setAutoXSpringPaginated);
729+
if (additionalProperties.containsKey(AUTO_X_SPRING_PAGINATED)) {
730+
writePropertyBack(AUTO_X_SPRING_PAGINATED, this.autoXSpringPaginated);
731+
}
699732
convertPropertyToBooleanAndWriteBack(GENERATE_SORT_VALIDATION, this::setGenerateSortValidation);
700733
convertPropertyToBooleanAndWriteBack(GENERATE_PAGEABLE_CONSTRAINT_VALIDATION, this::setGeneratePageableConstraintValidation);
701734
}
@@ -989,7 +1022,7 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
9891022
}
9901023

9911024
if (isPageableSupported()) {
992-
pageableUtils.scanAll(openAPI, autoXSpringPaginated);
1025+
pageableUtils.scanAll(openAPI, autoXSpringPaginatedMode);
9931026

9941027
if (generateSortValidation && useBeanValidation && !pageableUtils.sortValidationEnums.isEmpty()) {
9951028
importMapping.putIfAbsent("ValidSort", configPackage + ".ValidSort");
@@ -1480,14 +1513,14 @@ protected boolean isConstructorWithAllArgsAllowed(CodegenModel codegenModel) {
14801513
@Override
14811514
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
14821515

1483-
// Auto-detect pagination parameters and set x-spring-paginated if autoXSpringPaginated is enabled.
1516+
// Auto-detect pagination parameters and set x-spring-paginated if autoXSpringPaginated auto-detection is enabled.
14841517
// Must be done BEFORE super.fromOperation() so that the base codegen populates
14851518
// codegenOperation.vendorExtensions from the extension we just set on 'operation'.
14861519
// Only for libraries that support Pageable (spring-boot, spring-cloud);
14871520
// respect manual x-spring-paginated: false override.
14881521
if (isPageableSupported()) {
14891522
SpringPageableScanUtils.applyAutoXSpringPaginatedIfNeeded(
1490-
openAPI, operation, autoXSpringPaginated);
1523+
openAPI, operation, autoXSpringPaginatedMode);
14911524
}
14921525

14931526
// add Pageable import only if x-spring-paginated explicitly used AND it's a pageable-supporting library.

0 commit comments

Comments
 (0)