fix(kotlin-spring): skip @field:Valid on Map container properties (HV000271)

Closed
FA
5mo ago
+0-0

Description

Hibernate Validator 9.1 deprecated placing @Valid directly on a Map container, emitting a HV000271 warning at startup:

Using @Valid on a container (java.util.Map) is deprecated. You should apply the annotation on the type argument(s).

The beanValidation.mustache template adds @field:Valid to all container properties (List, Map, …) whose items are not primitives. For Map properties the correct fix is to omit @field:Valid entirely — annotating a type argument of Map<K, Any> or Map<K, SomeModel> with @Valid would require type-use annotations, which the current codegen does not support, and for untyped maps (Any values) there is nothing to validate anyway.

Change

Add a {{^isMap}} guard to the container branch of beanValidation.mustache so that only List/Set/array-typed properties still get @field:Valid. Map-typed properties are left unannotated.

Testing

  • Added a new @Test in KotlinSpringServerCodegenTest: generates a model with one Map<String, Item> property and one List<Item> property, then asserts that exactly one @field:Valid annotation is present in the generated file (for the list only).
  • All existing kotlin-spring sample outputs regenerated — no diff (none of the petstore samples have Map<String, ComplexType> properties).

Summary by cubic

Skip @field:Valid on Map-typed properties in Kotlin Spring models to suppress Hibernate Validator’s HV000271 warning. Lists/Sets/arrays still get @field:Valid; Maps are left unannotated.

  • Bug Fixes
    • Add {{^isMap}} guard in kotlin-spring/beanValidation.mustache so container validation applies only to non-Map containers.
    • Add test ensuring a model with Map and List adds @field:Valid only to the List.