Conversation
… (HV000271) Follow-up to OpenAPITools#24176. A single model wrapped in Optional (useOptional) or JsonNullable (openApiNullable) still received a member/parameter-level @Valid, which Hibernate Validator 9.1+ reports as HV000271 because both wrappers are containers (JsonNullable via the ValueExtractor registered by jackson-databind-nullable). - Model fields/getters: Optional<@Valid Model> / JsonNullable<@Valid Model> instead of a member-level @Valid. - Optional query/form/body parameters: Optional<@Valid Model>; optional scalar bodies no longer get a parameter-level @Valid (as OpenAPITools#24176 did for scalar query/form params). - Only models get the type-argument @Valid; wrapped scalars have nothing to cascade into. - New typeUseAnnotations lambda places type-use annotations after the package qualifier of fully qualified types (JsonNullable<com.example.@Valid ExternalModel>), required to compile. Adds tests for each case and regenerates affected samples. Fixes OpenAPITools#25097
This branch has not been deployed
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.
Fixes #25097. Follow-up to #24176.
#24176 moved
@ValidfromList/Set/Mapcontainers to their type argument. The Java Spring generator still emits a member- or parameter-level@Validwhen a single model is wrapped inOptional(useOptional) orJsonNullable(openApiNullable). Hibernate Validator 9.1+ treats both wrappers as containers (JsonNullablethrough theValueExtractorregistered byjackson-databind-nullable), so this still logs HV000271.Changes
useOptional@Valid Optional<Item> getSingleItem()Optional<@Valid Item> getSingleItem()openApiNullable@Valid JsonNullable<Item> getX()JsonNullable<@Valid Item> getX()deepObject) / multipart / body model param@Valid ... Optional<Item> item... Optional<@Valid Item> item@Valid @RequestBody(required = false) Optional<String> body@RequestBody(required = false) Optional<String> body@Valid. Wrapped scalars (Optional<BigDecimal>,JsonNullable<String>…) have nothing to cascade into, so they get none. This matches what fix(java): place bean-validation @Valid on the type argument instead of the container (HV000271) #24176 did for scalar query/form params.@Valid.typeUseAnnotationsMustache lambda (AbstractJavaCodegen#placeTypeUseAnnotations) places type-use annotations after the package qualifier of fully qualified types, e.g.JsonNullable<com.example.@Valid ExternalModel>. The form<@Valid com.example.ExternalModel>does not compile (seen withschemaMappingand withResource/Instanttypes).Tests
SpringCodegenTest: new tests on3_0/spring/issue_25097_valid_container.yamlcovering the model getters/fields (Optional,JsonNullable, Lombok), optional query/form/body params, FQN types, and regression guards for the cases fixed in fix(java): place bean-validation @Valid on the type argument instead of the container (HV000271) #24176 (list/map params, DTO getters, composed array items, nested maps). Three existing expectations were updated to the new output (Optional<@Valid Zebra>,JsonNullable<com.example.@Valid ExternalModel>).JavaClientCodegenTest: regression guard for container DTO getters (resttemplate/native/webclient).AbstractJavaCodegenTest: unit test forplaceTypeUseAnnotations.ParameterAssert#hasAnnotatedType: new assertion that keeps type-use annotations. The existinghasTypeignores them.org.openapitools.codegen.java.**passes: 1267 tests, 0 failures.ExecutableValidator) with Hibernate Validator 9.1.3.Final, using invalid nested payloads. HV000271 is gone, and nested violations are still reported with no duplicates.PR checklist
bin/configs/spring*.yamlandbin/configs/java-camel*.yaml, the only generators using the changedJavaSpringtemplates. All changed sample projects compile.Summary by cubic
Fixes HV000271 by placing
@Validon the type argument ofOptional/JsonNullable-wrapped models instead of the member or parameter, so generated code now emitsOptional<@Valid Item>.@Validon the type argument; wrapped scalars get none, and required or unwrapped models keep their member/parameter-level@Valid.JsonNullable<com.example.@Valid ExternalModel>), the only form that compiles.Written for commit 07b96a7. Summary will update on new commits.