Skip to content
Draft
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 @@ -31,7 +31,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|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|
|async|use async Callable controllers| |false|
|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|
|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|
|basePackage|base package (invokerPackage) for generated code| |org.openapitools|
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
Expand Down
2 changes: 1 addition & 1 deletion docs/generators/kotlin-spring.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|apiPackage|api package for generated code| |org.openapitools.api|
|artifactId|Generated artifact id (name of jar).| |openapi-spring|
|artifactVersion|Generated artifact's package version.| |1.0.0|
|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|
|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|
|basePackage|base package (invokerPackage) for generated code| |org.openapitools|
|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|
|companionObject|Whether to generate companion objects in data classes, enabling companion extensions.| |false|
Expand Down
2 changes: 1 addition & 1 deletion docs/generators/spring.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|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|
|async|use async Callable controllers| |false|
|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|
|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|
|basePackage|base package (invokerPackage) for generated code| |org.openapitools|
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,29 @@ public enum RequestMappingMode {
@Setter private boolean beanQualifiers = false;
@Setter private DeclarativeInterfaceReactiveMode declarativeInterfaceReactiveMode = DeclarativeInterfaceReactiveMode.coroutines;
@Setter private boolean useResponseEntity = true;
@Setter private boolean autoXSpringPaginated = false;
@Getter private String autoXSpringPaginated = SpringPageableScanUtils.AUTO_PAGINATION_MODE_NONE;
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
@Getter private SpringPageableScanUtils.AutoPaginationMode autoXSpringPaginatedMode = SpringPageableScanUtils.AutoPaginationMode.NONE;

/**
* Configures automatic Spring Pageable detection using a canonical mode or legacy boolean alias.
*
* @param autoXSpringPaginated the configured mode
*/
public void setAutoXSpringPaginated(String autoXSpringPaginated) {
autoXSpringPaginatedMode =
SpringPageableScanUtils.resolveAutoPaginationMode(autoXSpringPaginated, LOGGER::warn);
this.autoXSpringPaginated = autoXSpringPaginatedMode.getCanonicalValue();
}

/**
* @deprecated Use {@link #setAutoXSpringPaginated(String)} with {@code page-size-sort} or
* {@code none}.
*/
@Deprecated
public void setAutoXSpringPaginated(boolean autoXSpringPaginated) {
setAutoXSpringPaginated(Boolean.toString(autoXSpringPaginated));
}

@Setter private boolean generateSortValidation = false;
@Setter private boolean generatePageableConstraintValidation = false;
@Setter private boolean substituteGenericPagedModel = false;
Expand Down Expand Up @@ -311,7 +333,13 @@ public KotlinSpringServerCodegen() {
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");
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");
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");
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);
addOption(AUTO_X_SPRING_PAGINATED,
"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.",
autoXSpringPaginated, SpringPageableScanUtils.getAutoPaginationModeEnumValues());
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);
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);
addSwitch(SUBSTITUTE_GENERIC_PAGED_MODEL,
Expand Down Expand Up @@ -824,9 +852,10 @@ public void processOpts() {
this.setUseTags(Boolean.parseBoolean(additionalProperties.get(USE_TAGS).toString()));
}
if (additionalProperties.containsKey(AUTO_X_SPRING_PAGINATED) && isPageableSupported()) {
this.setAutoXSpringPaginated(convertPropertyToBoolean(AUTO_X_SPRING_PAGINATED));
String rawAutoXSpringPaginated = String.valueOf(additionalProperties.get(AUTO_X_SPRING_PAGINATED));
setAutoXSpringPaginated(rawAutoXSpringPaginated);
writePropertyBack(AUTO_X_SPRING_PAGINATED, autoXSpringPaginated);
}
writePropertyBack(AUTO_X_SPRING_PAGINATED, autoXSpringPaginated);
if (additionalProperties.containsKey(GENERATE_SORT_VALIDATION) && isPageableSupported()) {
this.setGenerateSortValidation(convertPropertyToBoolean(GENERATE_SORT_VALIDATION));
}
Expand Down Expand Up @@ -1138,7 +1167,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
// Only for libraries that support Pageable; respect manual x-spring-paginated: false override.
if (isPageableSupported()) {
SpringPageableScanUtils.applyAutoXSpringPaginatedIfNeeded(
openAPI, operation, autoXSpringPaginated);
openAPI, operation, autoXSpringPaginatedMode);
}

CodegenOperation codegenOperation = super.fromOperation(path, httpMethod, operation, servers);
Expand Down Expand Up @@ -1218,7 +1247,7 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
}

if (isPageableSupported()) {
pageableUtils.scanAll(openAPI, autoXSpringPaginated);
pageableUtils.scanAll(openAPI, autoXSpringPaginatedMode);

if (generateSortValidation && useBeanValidation && !pageableUtils.sortValidationEnums.isEmpty()) {
importMapping.putIfAbsent("ValidSort", configPackage + ".ValidSort");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,29 @@ public enum RequestMappingMode {
@Getter @Setter
protected boolean additionalNotNullAnnotations = false;
@Setter boolean useHttpServiceProxyFactoryInterfacesConfigurator = false;
@Setter protected boolean autoXSpringPaginated = false;
@Getter protected String autoXSpringPaginated = SpringPageableScanUtils.AUTO_PAGINATION_MODE_NONE;
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
@Getter private SpringPageableScanUtils.AutoPaginationMode autoXSpringPaginatedMode = SpringPageableScanUtils.AutoPaginationMode.NONE;

/**
* Configures automatic Spring Pageable detection using a canonical mode or legacy boolean alias.
*
* @param autoXSpringPaginated the configured mode
*/
public void setAutoXSpringPaginated(String autoXSpringPaginated) {
autoXSpringPaginatedMode =
SpringPageableScanUtils.resolveAutoPaginationMode(autoXSpringPaginated, LOGGER::warn);
this.autoXSpringPaginated = autoXSpringPaginatedMode.getCanonicalValue();
}

/**
* @deprecated Use {@link #setAutoXSpringPaginated(String)} with {@code page-size-sort} or
* {@code none}.
*/
@Deprecated
public void setAutoXSpringPaginated(boolean autoXSpringPaginated) {
setAutoXSpringPaginated(Boolean.toString(autoXSpringPaginated));
}

@Setter protected boolean generateSortValidation = false;
@Setter protected boolean generatePageableConstraintValidation = false;
@Setter protected boolean substituteGenericPagedModel = false;
Expand Down Expand Up @@ -402,12 +424,16 @@ public SpringCodegen() {
cliOptions.add(CliOption.newBoolean(ADDITIONAL_NOT_NULL_ANNOTATIONS,
"Add @NotNull to path variables (required by default) and requestBody.",
additionalNotNullAnnotations));
cliOptions.add(CliOption.newBoolean(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. "
+ "Only applies when library is spring-boot or spring-cloud.",
autoXSpringPaginated));
final CliOption autoXSpringPaginatedOption = new CliOption(AUTO_X_SPRING_PAGINATED,
"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.")
.defaultValue(autoXSpringPaginated);
autoXSpringPaginatedOption.setEnum(SpringPageableScanUtils.getAutoPaginationModeEnumValues());
cliOptions.add(autoXSpringPaginatedOption);
cliOptions.add(CliOption.newBoolean(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. "
Expand Down Expand Up @@ -683,7 +709,11 @@ public void processOpts() {
convertPropertyToBooleanAndWriteBack(CodegenConstants.USE_ENUM_VALUE_INTERFACE, this::setUseEnumValueInterface);

if (isPageableSupported()) {
convertPropertyToBooleanAndWriteBack(AUTO_X_SPRING_PAGINATED, this::setAutoXSpringPaginated);
if (additionalProperties.containsKey(AUTO_X_SPRING_PAGINATED)) {
String rawAutoXSpringPaginated = String.valueOf(additionalProperties.get(AUTO_X_SPRING_PAGINATED));
setAutoXSpringPaginated(rawAutoXSpringPaginated);
writePropertyBack(AUTO_X_SPRING_PAGINATED, this.autoXSpringPaginated);
}
convertPropertyToBooleanAndWriteBack(GENERATE_SORT_VALIDATION, this::setGenerateSortValidation);
convertPropertyToBooleanAndWriteBack(GENERATE_PAGEABLE_CONSTRAINT_VALIDATION, this::setGeneratePageableConstraintValidation);
}
Expand Down Expand Up @@ -947,7 +977,7 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
}

if (isPageableSupported()) {
pageableUtils.scanAll(openAPI, autoXSpringPaginated);
pageableUtils.scanAll(openAPI, autoXSpringPaginatedMode);

if (generateSortValidation && useBeanValidation && !pageableUtils.sortValidationEnums.isEmpty()) {
importMapping.putIfAbsent("ValidSort", configPackage + ".ValidSort");
Expand Down Expand Up @@ -1438,14 +1468,14 @@ protected boolean isConstructorWithAllArgsAllowed(CodegenModel codegenModel) {
@Override
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {

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

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