Skip to content

Commit 91fa74a

Browse files
PicazsooCopilot
andauthored
[JAVA-SPRING,KOTLIN-SPRING] - Enhance pageable validation by adding minSize and minPage constraints; Search also allOf references for constraints; fix PagedModel<T> substitution with 'modelNameSuffix' or 'modelNamePrefix'; add ValuedEnum<T> interface (#23694)
* Enhance pageable validation by adding minSize and minPage constraints. Search also allOf references for constraints and defaults * update samples * fix test * use ModelUtils in SpringPageableScanUtils * update tests in samples * move reusable code to shared ModelUtils.java * add tests * fix CR suggestion and add tests * suppress paged schemas correctly when modelNameSuffix/Prefix is set * refactor: enhance pageable constraints handling with exclusive bounds support * DRY code * refactor: improve resolution of nested allOf constraints for maximum and minimum bounds * re-enable test * test: fix implementation and add unit test for resolving default in nested allOf schemas * add comment to explain that behavior around default is undefined in open api spec * pageable-scan-resolve-allof-constraints refactor: streamline pageable handling and enhance annotation application logic * feat: add support for ValuedEnum interface in code generation for enums * fix: remove Pageable support for non-spring-boot libraries and update related documentation * update documentation * fix: update default resolution logic for allOf schemas to last-writer-wins semantics * fix: ensure correct parent reference ordering in allOf for default resolution * DRY code * DRY code * revert default-resolution related changes as the behavior is unspecified and therefore dangerous * add missing PetApiController implementations and validation tests for allOf-resolved constraints * fix(kotlin-spring): container inline enums must not get `override val value` EnumValueInterfaceUtils.injectInPostProcessModelsEnum() adds ValuedEnum<...> to x-kotlin-implements only for `var.isEnum && !var.isContainer`, but dataClass.mustache emitted the `override` keyword for every enum whenever useEnumValueInterface=true. Container inline enums therefore produced uncompilable Kotlin (`overrides nothing`) since the enum class did not actually implement any interface to override. Gating the `override` token on `^isContainer` keeps the template in sync with the util. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * feat(kotlin-spring and java-spring): add ValuedEnum interface and update related configurations to verify compilation success for both javax and jakarta setups in kotlin and java spring * update samples * update samples --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 7ee4a73 commit 91fa74a

125 files changed

Lines changed: 3742 additions & 960 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bin/configs/kotlin-spring-boot-integer-enum.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ additionalProperties:
1111
annotationLibrary: none
1212
documentationProvider: none
1313
enumPropertyNaming: UPPERCASE
14+
useEnumValueInterface: "true"

bin/configs/kotlin-spring-boot.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ additionalProperties:
1111
serializableModel: "true"
1212
useBeanValidation: "true"
1313
requestMappingMode: controller
14+
useEnumValueInterface: "true"
15+
useSpringBoot3: "false"

bin/configs/spring-boot-3-include-http-request-context.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ additionalProperties:
1515
generateBuilders: true
1616
includeHttpRequestContext: "true"
1717
delegatePattern: true
18+
useEnumValueInterface: "true"

bin/configs/spring-boot-4.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ additionalProperties:
1515
generateConstructorWithAllArgs: true
1616
generateBuilders: true
1717
openApiNullable: false
18+
useEnumValueInterface: "true"

bin/configs/spring-boot-sort-validation.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ additionalProperties:
1818
generatePageableConstraintValidation: "true"
1919
useTags: "true"
2020
requestMappingMode: api_interface
21+
useEnumValueInterface: "true"

bin/configs/spring-boot.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ additionalProperties:
99
hideGenerationTimestamp: "true"
1010
camelCaseDollarSign: "true"
1111
modelNameSuffix: 'Dto'
12+
useEnumValueInterface: "true"
13+
useSpringBoot3: "false"

docs/generators/java-camel.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
112112
|useBeanValidation|Use BeanValidation API annotations| |true|
113113
|useDeductionForOneOfInterfaces|Annotate discriminator-free oneOf interfaces with Jackson's @JsonTypeInfo(use = Id.DEDUCTION) and @JsonSubTypes so the concrete subtype is resolved from the JSON field set rather than a type-tag property. Has no effect when a discriminator is present (name-based resolution is used instead). Requires subtypes to have structurally distinct sets of properties.| |false|
114114
|useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false|
115+
|useEnumValueInterface|Generate a ValuedEnum&lt;T&gt; interface in the config package and make all generated enums implement it, providing a common typed way to access the underlying enum value. Use `importMappings.ValuedEnum` to substitute a custom/library-provided interface instead of generating one.| |false|
115116
|useFeignClientContextId|Whether to generate Feign client with contextId parameter.| |true|
116117
|useFeignClientUrl|Whether to generate Feign client with url parameter.| |true|
117118
|useHttpServiceProxyFactoryInterfacesConfigurator|Generate HttpInterfacesAbstractConfigurator based on an HttpServiceProxyFactory instance (as opposed to a WebClient instance, when disabled) for generating Spring HTTP interfaces.| |false|
@@ -145,7 +146,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
145146
|x-class-extra-annotation|List of custom annotations to be added to model|MODEL|null
146147
|x-field-extra-annotation|List of custom annotations to be added to property|FIELD, OPERATION_PARAMETER|null
147148
|x-operation-extra-annotation|List of custom annotations to be added to operation|OPERATION|null
148-
|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
149+
|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. Only applies when `library=spring-boot`; ignored for client libraries (spring-cloud, spring-declarative-http-interface).|OPERATION|false
149150
|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
150151
|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
151152
|x-size-message|Add this property whenever you need to customize the invalidation error message for the size or length of a variable|FIELD, OPERATION_PARAMETER|null

docs/generators/kotlin-spring.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
6363
|title|server title name or client service name| |OpenAPI Kotlin Spring|
6464
|useBeanValidation|Use BeanValidation API annotations to validate data types| |true|
6565
|useDeductionForOneOfInterfaces|Annotate discriminator-free oneOf interfaces with Jackson's @JsonTypeInfo(use = Id.DEDUCTION) and @JsonSubTypes so the concrete subtype is resolved from the JSON field set rather than a type-tag property. Has no effect when a discriminator is present (name-based resolution is used instead). Requires subtypes to have structurally distinct sets of properties.| |false|
66+
|useEnumValueInterface|Generate a ValuedEnum&lt;T&gt; interface in the config package and make all generated enums implement it, providing a common typed way to access the underlying enum value. Use `importMappings.ValuedEnum` to substitute a custom/library-provided interface instead of generating one.| |false|
6667
|useFeignClientUrl|Whether to generate Feign client with url parameter.| |true|
6768
|useFlowForArrayReturnType|Whether to use Flow for array/collection return types when reactive is enabled. If false, will use List instead.| |true|
6869
|useJackson3|Use Jackson 3 dependencies (tools.jackson package). Only available with `useSpringBoot4`. Defaults to true when `useSpringBoot4` is enabled.| |false|
@@ -91,7 +92,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
9192
|x-maximum-message|Add this property whenever you need to customize the invalidation error message for the maximum value of a variable|FIELD, OPERATION_PARAMETER|null
9293
|x-kotlin-implements|Ability to specify interfaces that model must implement|MODEL|empty array
9394
|x-kotlin-implements-fields|Specify attributes that are implemented by the interface(s) added via `x-kotlin-implements`|MODEL|empty array
94-
|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
95+
|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. Only applies when `library=spring-boot`; ignored for client libraries (spring-cloud, spring-declarative-http-interface).|OPERATION|false
9596

9697

9798
## IMPORT MAPPING

docs/generators/spring.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
105105
|useBeanValidation|Use BeanValidation API annotations| |true|
106106
|useDeductionForOneOfInterfaces|Annotate discriminator-free oneOf interfaces with Jackson's @JsonTypeInfo(use = Id.DEDUCTION) and @JsonSubTypes so the concrete subtype is resolved from the JSON field set rather than a type-tag property. Has no effect when a discriminator is present (name-based resolution is used instead). Requires subtypes to have structurally distinct sets of properties.| |false|
107107
|useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false|
108+
|useEnumValueInterface|Generate a ValuedEnum&lt;T&gt; interface in the config package and make all generated enums implement it, providing a common typed way to access the underlying enum value. Use `importMappings.ValuedEnum` to substitute a custom/library-provided interface instead of generating one.| |false|
108109
|useFeignClientContextId|Whether to generate Feign client with contextId parameter.| |true|
109110
|useFeignClientUrl|Whether to generate Feign client with url parameter.| |true|
110111
|useHttpServiceProxyFactoryInterfacesConfigurator|Generate HttpInterfacesAbstractConfigurator based on an HttpServiceProxyFactory instance (as opposed to a WebClient instance, when disabled) for generating Spring HTTP interfaces.| |false|
@@ -138,7 +139,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
138139
|x-class-extra-annotation|List of custom annotations to be added to model|MODEL|null
139140
|x-field-extra-annotation|List of custom annotations to be added to property|FIELD, OPERATION_PARAMETER|null
140141
|x-operation-extra-annotation|List of custom annotations to be added to operation|OPERATION|null
141-
|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
142+
|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. Only applies when `library=spring-boot`; ignored for client libraries (spring-cloud, spring-declarative-http-interface).|OPERATION|false
142143
|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
143144
|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
144145
|x-size-message|Add this property whenever you need to customize the invalidation error message for the size or length of a variable|FIELD, OPERATION_PARAMETER|null

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,13 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,
490490
public static final String X_MODEL_IS_MUTABLE = "x-model-is-mutable";
491491
public static final String X_IMPLEMENTS = "x-implements";
492492
public static final String X_IS_ONE_OF_INTERFACE = "x-is-one-of-interface";
493+
public static final String USE_ENUM_VALUE_INTERFACE = "useEnumValueInterface";
494+
public static final String USE_ENUM_VALUE_INTERFACE_DESC =
495+
"Generate a ValuedEnum<T> interface in the config package and make all generated enums " +
496+
"implement it, providing a common typed way to access the underlying enum value. " +
497+
"Use `importMappings.ValuedEnum` to substitute a custom/library-provided interface " +
498+
"instead of generating one.";
499+
493500
public static final String USE_DEDUCTION_FOR_ONE_OF_INTERFACES = "useDeductionForOneOfInterfaces";
494501
public static final String USE_DEDUCTION_FOR_ONE_OF_INTERFACES_DESC =
495502
"Annotate discriminator-free oneOf interfaces with Jackson's " +

0 commit comments

Comments
 (0)