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

Closed
FA
5mo ago
+47-2

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 emitting @field:Valid on Map properties in Kotlin Spring codegen to prevent HV000271 warnings with Hibernate Validator 9.1. Lists/Sets/arrays are unchanged.

  • Bug Fixes
    • Updated kotlin-spring/beanValidation.mustache to apply @field:Valid only when isContainer && !isMap.
    • Added a test to ensure only the list property gets @field:Valid; regenerated samples with no changes.