|
5 | 5 |
|
6 | 6 | package io.openapiprocessor.core.writer.java |
7 | 7 |
|
8 | | -import io.openapiprocessor.core.model.datatypes.DataType |
9 | | -import io.openapiprocessor.core.model.datatypes.MappedCollectionDataType |
10 | | -import io.openapiprocessor.core.model.datatypes.ModelDataType |
| 8 | +import io.openapiprocessor.core.model.datatypes.* |
| 9 | + |
| 10 | +data class BeanValidationValue( |
| 11 | + val dataTypeValue: String, |
| 12 | + val imports: Set<String>, |
| 13 | + val annotations: List<String>) |
11 | 14 |
|
12 | 15 | interface BeanValidationInfo { |
13 | 16 | val dataType: DataType |
14 | 17 | val imports: Set<String> |
15 | 18 | val annotations: List<String> |
16 | 19 |
|
17 | | - val typeName: String |
18 | | - get() { |
19 | | - return dataType.getTypeName() |
20 | | - } |
21 | | - |
22 | | - val hasAnnotations |
23 | | - get() = annotations.isNotEmpty() |
24 | | - |
| 20 | + val prop: BeanValidationValue |
| 21 | + val inout: BeanValidationValue |
25 | 22 | } |
26 | 23 |
|
27 | | -class BeanValidationInfoObject( |
| 24 | +class BeanValidationInfoSimple( |
28 | 25 | override val dataType: DataType, |
29 | 26 | override val imports: Set<String>, |
30 | 27 | override val annotations: List<String> |
31 | | -): BeanValidationInfo |
| 28 | +): BeanValidationInfo { |
| 29 | + |
| 30 | + override val prop: BeanValidationValue |
| 31 | + get() { |
| 32 | + return BeanValidationValue(dataType.getTypeName(), imports, annotations) |
| 33 | + } |
32 | 34 |
|
| 35 | + override val inout: BeanValidationValue |
| 36 | + get() { |
| 37 | + val dt = mutableListOf<String>() |
| 38 | + dt.addAll(annotations) |
| 39 | + dt.add(dataType.getTypeName()) |
| 40 | + return BeanValidationValue(dt.joinToString(" "), imports, emptyList()) |
| 41 | + } |
| 42 | +} |
33 | 43 |
|
34 | | -class BeanValidationInfoProperty( |
| 44 | +class BeanValidationInfoCollection( |
35 | 45 | override val dataType: DataType, |
36 | 46 | override val imports: Set<String>, |
37 | | - override val annotations: List<String> |
| 47 | + override val annotations: List<String>, |
| 48 | + val item: BeanValidationInfo |
38 | 49 | ): BeanValidationInfo { |
39 | 50 |
|
40 | | - override val typeName: String |
| 51 | + override val prop: BeanValidationValue |
| 52 | + get() { |
| 53 | + dataType as CollectionDataType |
| 54 | + |
| 55 | + return if (item.dataType is ModelDataType) { |
| 56 | + val allImports = mutableSetOf<String>() |
| 57 | + allImports.addAll(imports) |
| 58 | + if (dataType !is ArrayDataType) { |
| 59 | + allImports.add(BeanValidation.VALID.import) |
| 60 | + } |
| 61 | + |
| 62 | + val colAnnotations = mutableListOf<String>() |
| 63 | + colAnnotations.addAll(annotations) |
| 64 | + |
| 65 | + val itemAnnotations = mutableSetOf<String>() |
| 66 | + if (dataType !is ArrayDataType) { |
| 67 | + itemAnnotations.add(BeanValidation.VALID.annotation) |
| 68 | + } |
| 69 | + |
| 70 | + BeanValidationValue( |
| 71 | + dataType.getTypeName(emptySet(), itemAnnotations), |
| 72 | + allImports, |
| 73 | + colAnnotations |
| 74 | + ) |
| 75 | + } else { |
| 76 | + val allImports = mutableSetOf<String>() |
| 77 | + allImports.addAll(imports) |
| 78 | + if (dataType !is ArrayDataType) { |
| 79 | + allImports.addAll(item.imports) |
| 80 | + } |
| 81 | + |
| 82 | + val colAnnotations = mutableListOf<String>() |
| 83 | + colAnnotations.addAll(annotations) |
| 84 | + |
| 85 | + val itemAnnotations = mutableSetOf<String>() |
| 86 | + if (dataType !is ArrayDataType) { |
| 87 | + itemAnnotations.addAll(item.annotations) |
| 88 | + } |
| 89 | + |
| 90 | + BeanValidationValue( |
| 91 | + dataType.getTypeName(emptySet(), itemAnnotations), |
| 92 | + allImports, |
| 93 | + colAnnotations |
| 94 | + ) |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + override val inout: BeanValidationValue |
41 | 99 | get() { |
42 | | - // no collection or array |
43 | | - if (dataType !is MappedCollectionDataType) |
44 | | - return dataType.getTypeName() |
| 100 | + val cdt = dataType as CollectionDataType |
| 101 | + |
| 102 | + return if (item.dataType is ModelDataType) { |
| 103 | + val allImports = mutableSetOf<String>() |
| 104 | + allImports.addAll(imports) |
| 105 | + if (dataType !is ArrayDataType) { |
| 106 | + allImports.add(BeanValidation.VALID.import) |
| 107 | + } |
| 108 | + |
| 109 | + val colAnnotations = mutableSetOf<String>() |
| 110 | + colAnnotations.addAll(annotations) |
| 111 | + |
| 112 | + val itemAnnotations = mutableSetOf<String>() |
| 113 | + if (dataType !is ArrayDataType) { |
| 114 | + itemAnnotations.add(BeanValidation.VALID.annotation) |
| 115 | + } |
| 116 | + |
| 117 | + BeanValidationValue( |
| 118 | + cdt.getTypeName(colAnnotations, itemAnnotations), |
| 119 | + allImports, |
| 120 | + emptyList()) |
| 121 | + } else { |
| 122 | + val allImports = mutableSetOf<String>() |
| 123 | + allImports.addAll(imports) |
| 124 | + if (dataType !is ArrayDataType) { |
| 125 | + allImports.addAll(item.imports) |
| 126 | + } |
| 127 | + |
| 128 | + val colAnnotations = mutableSetOf<String>() |
| 129 | + colAnnotations.addAll(annotations) |
45 | 130 |
|
46 | | - if (dataType.item !is ModelDataType) |
47 | | - return dataType.getTypeName() |
| 131 | + val itemAnnotations = mutableSetOf<String>() |
| 132 | + if (dataType !is ArrayDataType) { |
| 133 | + itemAnnotations.addAll(item.annotations) |
| 134 | + } |
48 | 135 |
|
49 | | - return dataType.getTypeNameWithAnnotatedItem(BeanValidation.VALID.annotation) |
| 136 | + BeanValidationValue( |
| 137 | + cdt.getTypeName(colAnnotations, itemAnnotations), |
| 138 | + allImports, |
| 139 | + emptyList()) |
| 140 | + } |
50 | 141 | } |
51 | 142 |
|
52 | 143 | } |
0 commit comments