Skip to content
This repository was archived by the owner on Mar 16, 2025. It is now read-only.

Commit d7571c8

Browse files
committed
id/type split (mapped collection & validation), #65
1 parent dd65466 commit d7571c8

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ open class BeanValidationFactory {
1515

1616
fun validate(dataType: DataType, required: Boolean = false): BeanValidationInfo {
1717
return BeanValidationInfo(
18-
annotateGenericItem(dataType),
18+
dataType,
1919
collectImports(dataType, required),
2020
collectAnnotations(dataType, required)
2121
)
@@ -81,13 +81,6 @@ open class BeanValidationFactory {
8181
return annotations
8282
}
8383

84-
private fun annotateGenericItem(dataType: DataType): String {
85-
if (!dataType.isCollectionOfModel())
86-
return dataType.getName()
87-
88-
return (dataType as MappedCollectionDataType).getName(BeanValidation.VALID.annotation)
89-
}
90-
9184
private fun requiresValidImport(dataType: DataType): Boolean {
9285
if (dataType.isModel())
9386
return true
@@ -156,13 +149,6 @@ private fun DataType.isArrayOfModel(): Boolean {
156149
return item.isModel()
157150
}
158151

159-
private fun DataType.isCollectionOfModel(): Boolean {
160-
if (this !is MappedCollectionDataType)
161-
return false
162-
163-
return item.isModel()
164-
}
165-
166152
private fun DataType.isString(): Boolean = this is StringDataType
167153

168154
private fun DataType.isCollection(): Boolean =

src/main/kotlin/io/openapiprocessor/core/writer/java/BeanValidationInfo.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,28 @@
55

66
package io.openapiprocessor.core.writer.java
77

8+
import io.openapiprocessor.core.model.datatypes.DataType
9+
import io.openapiprocessor.core.model.datatypes.MappedCollectionDataType
10+
import io.openapiprocessor.core.model.datatypes.ModelDataType
11+
812
class BeanValidationInfo(
9-
val typeName: String,
13+
val dataType: DataType,
1014
val imports: Set<String>,
1115
val annotations: List<String>
1216
) {
17+
val typeName: String
18+
get() {
19+
// no collection or array
20+
if (dataType !is MappedCollectionDataType)
21+
return dataType.getTypeName()
22+
23+
if (dataType.item !is ModelDataType)
24+
return dataType.getTypeName()
25+
26+
return dataType.getTypeNameWithAnnotatedItem(BeanValidation.VALID.annotation)
27+
}
28+
1329
val hasAnnotations
1430
get() = annotations.isNotEmpty()
31+
1532
}

0 commit comments

Comments
 (0)