Skip to content

Commit f1889bf

Browse files
committed
(cherry picked from commit 29ecbdd)
1 parent 45eeac1 commit f1889bf

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/writer/java/BeanValidationFactory.kt

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,24 @@ open class BeanValidationFactory(
3030
}
3131

3232
fun validate(dataType: DataType, required: Boolean = false, parentHasValid: Boolean = false): BeanValidationInfo {
33-
return when (dataType) {
34-
is MappedCollectionDataTypePrimitive -> {
35-
// should not be handled as collection, we can't annotate the primitive type only the primitve array
36-
BeanValidationInfoSimple(dataType, collectAnnotations(dataType, required, parentHasValid))
37-
}
38-
is CollectionDataType -> {
39-
val (annotations, valid) = collectAnnotationsWithValid(dataType, required, parentHasValid)
40-
41-
BeanValidationInfoCollection(
42-
dataType,
43-
annotations,
44-
validate(dataType.item, parentHasValid = valid))
45-
}
46-
else -> {
47-
BeanValidationInfoSimple(dataType, collectAnnotations(dataType, required, parentHasValid))
48-
}
33+
if (dataType is CollectionDataType && shouldAnnotateCollectionItem(dataType)) {
34+
val (annotations, valid) = collectAnnotationsWithValid(dataType, required, parentHasValid)
35+
36+
return BeanValidationInfoCollection(
37+
dataType,
38+
annotations,
39+
validate(dataType.item, parentHasValid = valid))
4940
}
41+
42+
return BeanValidationInfoSimple(
43+
dataType,
44+
collectAnnotations(dataType, required, parentHasValid))
45+
}
46+
47+
private fun shouldAnnotateCollectionItem(dataType: DataType): Boolean {
48+
// a primitive array should not be handled as collection because we need to annotate the primitive array and
49+
// not the primitive
50+
return dataType !is MappedCollectionDataTypePrimitive
5051
}
5152

5253
private fun collectAnnotations(dataType: DataType, required: Boolean = false, parentHasValid: Boolean): List<Annotation> {

0 commit comments

Comments
 (0)