Commit fd351f8
committed
fix(java): place bean-validation @Valid on the type argument instead of the container (HV000271)
Hibernate Validator 9.1+ (bundled with Spring Boot 4) logs HV000271 ("Using
@Valid on a container is deprecated. You should apply the annotation on the
type argument(s)") for every @Valid-annotated List/Set/Map — on both model
properties and API parameters.
This relocates @Valid from the container to its type argument — the
Bean-Validation-2.0 form (List<@Valid T>, Map<String, @Valid V>) — which
cascades identically but is not deprecated. Backward-compatible: element
validation is preserved, never dropped; single-object @Valid is untouched.
Verified on Spring Boot 3.3 (Spring 6.1) and 4.1 (Spring 7): a container
parameter carrying only the type-argument @Valid still triggers element
validation via method validation, with no HV000271.
Scope (Java family): spring, java client, JAX-RS (jersey, resteasy(+eap),
cxf(+extended/cdi), spec), java-camel, java-msf4j.
Models (property/getter): the container @Valid is moved to the type argument.
Map values are gated behind a new
AbstractJavaCodegen#useBeanValidationOnMapValueType() (default false; overridden
true in Spring/JavaClient/JAX-RS) so untouched generators don't silently gain
map-value validation. Arrays/sets already injected the type-argument form.
Parameters (@RequestBody/@RequestParam/@RequestPart): the redundant
container-level @Valid is dropped for container parameters; element validation
is driven by the type-argument @Valid. Single-object parameters keep @Valid.
Reactive Mono/Flux bodies are intentionally untouched (not Jakarta containers,
so no HV000271).
Regenerated all affected samples and added/updated codegen tests in
SpringCodegenTest, JavaClientCodegenTest, JavaJAXRSSpecServerCodegenTest and
JavaValidationArrayPrimitivesTest.1 parent 0f12a09 commit fd351f8
581 files changed
Lines changed: 1388 additions & 1354 deletions
File tree
- modules/openapi-generator/src
- main
- java/org/openapitools/codegen/languages
- resources
- JavaJaxRS
- cxf-ext
- cxf
- resteasy
- eap
- spec
- JavaSpring
- Java
- libraries/microprofile
- java-camel-server
- test/java/org/openapitools/codegen/java
- jaxrs
- spring
- samples
- client/petstore
- java
- jersey3-jackson3/src/main/java/org/openapitools/client/model
- jersey3/src/main/java/org/openapitools/client/model
- rest-assured-jackson/src/main/java/org/openapitools/client/model
- rest-assured/src/main/java/org/openapitools/client/model
- retrofit2-play26/src/main/java/org/openapitools/client/model
- spring-cloud-deprecated/src/main/java/org/openapitools
- api
- model
- spring-cloud-feign-without-url/src/main/java/org/openapitools
- api
- model
- spring-cloud-tags/src/main/java/org/openapitools
- api
- model
- spring-cloud/src/main/java/org/openapitools
- api
- model
- spring-http-interface-bean-validation/src/main/java/org/openapitools
- api
- model
- spring-http-interface-reactive-bean-validation/src/main/java/org/openapitools
- api
- model
- spring-http-interface-springboot-4/src/main/java/org/openapitools
- api
- model
- spring-http-interface-useHttpServiceProxyFactoryInterfacesConfigurator/src/main/java/org/openapitools
- api
- model
- openapi3
- client/petstore
- spring-cloud-3-with-optional/src/main/java/org/openapitools
- api
- model
- spring-cloud-3/src/main/java/org/openapitools
- api
- model
- spring-cloud-4-with-optional/src/main/java/org/openapitools
- api
- model
- spring-cloud-async/src/main/java/org/openapitools
- api
- model
- spring-cloud-http-basic/src/main/java/org/openapitools/model
- spring-cloud-oas3-fakeapi/src/main/java/org/openapitools
- api
- model
- spring-cloud-spring-pageable/src/main/java/org/openapitools
- api
- model
- spring-cloud/src/main/java/org/openapitools
- api
- model
- spring-stubs-skip-default-interface/src/main/java/org/openapitools
- api
- model
- spring-stubs/src/main/java/org/openapitools
- api
- model
- server/petstore
- spring-boot-springdoc/src/main/java/org/openapitools
- api
- model
- springboot-3-include-http-request-context/src/main/java/org/openapitools
- api
- model
- springboot-3/src/main/java/org/openapitools
- api
- model
- springboot-4-jspecify/src/main/java/org/openapitools/model
- springboot-4/src/main/java/org/openapitools
- api
- model
- springboot-delegate/src/main/java/org/openapitools
- api
- model
- springboot-implicitHeaders/src/main/java/org/openapitools
- api
- model
- springboot-source/src/main/java/org/openapitools
- api
- model
- springboot/src/main/java/org/openapitools
- api
- model
- server/petstore
- java-camel/src/main/java/org/openapitools/model
- java-msf4j/src/gen/java/org/openapitools/model
- jaxrs-cxf-annotated-base-path/src/gen/java/org/openapitools
- api
- model
- jaxrs-cxf-non-spring-app/src/gen/java/org/openapitools
- api
- model
- jaxrs-cxf/src/gen/java/org/openapitools
- api
- model
- jaxrs-datelib-j8/src/gen/java/org/openapitools
- api
- model
- jaxrs-jersey/src/gen/java/org/openapitools
- api
- model
- jaxrs-resteasy
- default/src/gen/java/org/openapitools
- api
- model
- eap-java8/src/gen/java/org/openapitools/api
- eap-joda/src/gen/java/org/openapitools/api
- eap/src/gen/java/org/openapitools/api
- java8/src/gen/java/org/openapitools
- api
- model
- joda/src/gen/java/org/openapitools
- api
- model
- jaxrs-spec-interface-response/src/gen/java/org/openapitools
- api
- model
- jaxrs-spec-interface/src/gen/java/org/openapitools
- api
- model
- jaxrs-spec-jakarta/src/gen/java/org/openapitools
- api
- model
- jaxrs-spec-microprofile-openapi-annotations/src/gen/java/org/openapitools
- api
- model
- jaxrs-spec-quarkus-mutiny/src/gen/java/org/openapitools
- api
- model
- jaxrs-spec-swagger-annotations/src/gen/java/org/openapitools
- api
- model
- jaxrs-spec-swagger-v3-annotations-jakarta/src/gen/java/org/openapitools
- api
- model
- jaxrs-spec-swagger-v3-annotations/src/gen/java/org/openapitools
- api
- model
- jaxrs-spec-withxml/src/gen/java/org/openapitools
- api
- model
- jaxrs-spec/src/gen/java/org/openapitools
- api
- model
- jaxrs
- jersey2-useTags/src/gen/java/org/openapitools
- api
- model
- jersey2/src/gen/java/org/openapitools
- api
- model
- jersey3/src/gen/java/org/openapitools
- api
- model
- spring-boot-defaultInterface-unhandledExcp/src/main/java/org/openapitools
- api
- model
- springboot-beanvalidation-no-nullable/src/main/java/org/openapitools
- api
- model
- springboot-beanvalidation/src/main/java/org/openapitools
- api
- model
- springboot-builtin-validation/src/main/java/org/openapitools
- api
- model
- springboot-delegate-j8/src/main/java/org/openapitools
- api
- model
- springboot-delegate-no-response-entity/src/main/java/org/openapitools
- api
- model
- springboot-delegate/src/main/java/org/openapitools
- api
- model
- springboot-implicitHeaders-annotationLibrary/src/main/java/org/openapitools
- api
- model
- springboot-implicitHeaders/src/main/java/org/openapitools
- api
- model
- springboot-include-http-request-context/src/main/java/org/openapitools
- api
- model
- springboot-lombok-data/src/main/java/org/openapitools/api
- springboot-lombok-tostring/src/main/java/org/openapitools/api
- springboot-paged-model/src/main/java/org/openapitools/model
- springboot-petstore-with-api-response-examples/src/main/java/org/openapitools
- api
- model
- springboot-reactive-noResponseEntity/src/main/java/org/openapitools
- api
- model
- springboot-reactive/src/main/java/org/openapitools
- api
- model
- springboot-spring-pageable-delegatePattern-without-j8/src/main/java/org/openapitools
- api
- model
- springboot-spring-pageable-delegatePattern/src/main/java/org/openapitools
- api
- model
- springboot-spring-pageable-without-j8/src/main/java/org/openapitools
- api
- model
- springboot-spring-pageable/src/main/java/org/openapitools
- api
- model
- springboot-spring-provide-args/src/main/java/org/openapitools/model
- springboot-useoptional/src/main/java/org/openapitools
- api
- model
- springboot-virtualan/src/main/java/org/openapitools/virtualan
- api
- model
- springboot-x-implements-skip/src/main/java/org/openapitools
- api
- model
- springboot/src/main/java/org/openapitools
- api
- model
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 37 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1097 | 1097 | | |
1098 | 1098 | | |
1099 | 1099 | | |
1100 | | - | |
| 1100 | + | |
1101 | 1101 | | |
1102 | 1102 | | |
1103 | 1103 | | |
| |||
1108 | 1108 | | |
1109 | 1109 | | |
1110 | 1110 | | |
1111 | | - | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
1112 | 1119 | | |
1113 | 1120 | | |
1114 | 1121 | | |
1115 | 1122 | | |
1116 | | - | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
1117 | 1148 | | |
1118 | 1149 | | |
1119 | 1150 | | |
| |||
1137 | 1168 | | |
1138 | 1169 | | |
1139 | 1170 | | |
1140 | | - | |
| 1171 | + | |
| 1172 | + | |
1141 | 1173 | | |
1142 | 1174 | | |
1143 | 1175 | | |
1144 | | - | |
| 1176 | + | |
1145 | 1177 | | |
1146 | 1178 | | |
1147 | 1179 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
135 | 143 | | |
136 | 144 | | |
137 | 145 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
204 | 212 | | |
205 | 213 | | |
206 | 214 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1555 | 1555 | | |
1556 | 1556 | | |
1557 | 1557 | | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
1558 | 1566 | | |
1559 | 1567 | | |
1560 | 1568 | | |
| |||
Lines changed: 0 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | 6 | | |
14 | 7 | | |
15 | 8 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
| 43 | + | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
0 commit comments