Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#isContainer}}{{^isPrimitiveType}}{{^isEnum}}
@field:Valid{{/isEnum}}{{/isPrimitiveType}}{{/isContainer}}{{!
{{#isContainer}}{{^isMap}}{{^isPrimitiveType}}{{^isEnum}}
@field:Valid{{/isEnum}}{{/isPrimitiveType}}{{/isMap}}{{/isContainer}}{{!
}}{{^isContainer}}{{^isPrimitiveType}}{{^isNumber}}{{^isUuid}}{{^isDateTime}}
@field:Valid{{/isDateTime}}{{/isUuid}}{{/isNumber}}{{/isPrimitiveType}}{{/isContainer}}
Original file line number Diff line number Diff line change
Expand Up @@ -6777,4 +6777,26 @@ public void schemaMappingWithNullableAllOfRendersNullableKotlinProperty() throws
String content = Files.readString(myObjectFile.toPath());
assertThat(content).contains("com.example.ExternalModel?");
}

@Test
public void mapPropertiesDoNotGetFieldValidAnnotation_HV000271() throws IOException {
// Hibernate Validator deprecated @Valid on Map containers (HV000271).
// @field:Valid must not be emitted for Map properties; it must still be emitted for List properties.
Map<String, File> files = generateFromContract(
"src/test/resources/3_0/spring/map-field-valid-hv000271.yaml",
new HashMap<>(Map.of(KotlinSpringServerCodegen.USE_BEANVALIDATION, "true"))
);

File containerFile = files.get("Container.kt");
assertThat(containerFile).isNotNull();

String content = Files.readString(containerFile.toPath());
assertThat(content).contains("val mapProp:");
assertThat(content).contains("val listProp:");

long fieldValidCount = content.lines().filter(line -> line.contains("@field:Valid")).count();
assertThat(fieldValidCount)
.as("@field:Valid must appear only on the list property, not on the map property (HV000271)")
.isEqualTo(1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
openapi: 3.0.0
info:
version: "1.0.0"
title: map-field-valid-hv000271
paths: {}
components:
schemas:
Item:
type: object
properties:
name:
type: string
Container:
type: object
properties:
mapProp:
type: object
additionalProperties:
$ref: '#/components/schemas/Item'
listProp:
type: array
items:
$ref: '#/components/schemas/Item'