Skip to content

Commit c8c46f9

Browse files
committed
reduce duplication
1 parent 234b13c commit c8c46f9

1 file changed

Lines changed: 57 additions & 40 deletions

File tree

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

Lines changed: 57 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -114,70 +114,87 @@ class Array(): SupportedType {
114114

115115

116116
private const val JSON_NULLABLE = "org.openapitools.jackson.nullable.JsonNullable"
117+
private const val CHAR_SEQUENCE = "java.lang.CharSequence"
118+
private const val BIG_DECIMAL = "java.math.BigDecimal"
119+
private const val BIG_INTEGER = "java.math.BigInteger"
120+
private const val BYTE = "java.lang.Byte"
121+
private const val BYTE_PRIMITIVE = "byte"
122+
private const val SHORT = "java.lang.Short"
123+
private const val SHORT_PRIMITIVE = "short"
124+
private const val INTEGER = "java.lang.Integer"
125+
private const val INTEGER_PRIMITIVE = "int"
126+
private const val LONG = "java.lang.Long"
127+
private const val LONG_PRIMITIVE = "long"
128+
private const val BOOLEAN = "java.lang.Boolean"
129+
private const val BOOLEAN_PRIMITIVE = "boolean"
130+
private const val FLOAT = "java.lang.Float"
131+
private const val FLOAT_PRIMITIVE = "float"
132+
private const val DOUBLE = "java.lang.Double"
133+
private const val DOUBLE_PRIMITIVE = "double"
117134

118135
private val BOOLEAN_TYPES = listOf(
119-
Type("java.lang.Boolean"),
120-
Primitive("boolean"),
136+
Type(BOOLEAN),
137+
Primitive(BOOLEAN_PRIMITIVE),
121138
AdditionalType(JSON_NULLABLE)
122139
)
123140

124141
private val NUMBER_TYPES = listOf(
125-
Type("java.math.BigDecimal"),
126-
Type("java.math.BigInteger"),
127-
Type("java.lang.Byte"),
128-
Type("java.lang.Short"),
129-
Type("java.lang.Integer"),
130-
Type("java.lang.Long"),
131-
Type("java.lang.Float"),
132-
Type("java.lang.Double"),
133-
Primitive("byte"),
134-
Primitive("short"),
135-
Primitive("int"),
136-
Primitive("long"),
137-
Primitive("float"),
138-
Primitive("double"),
142+
Type(BIG_DECIMAL),
143+
Type(BIG_INTEGER),
144+
Type(BYTE),
145+
Type(SHORT),
146+
Type(INTEGER),
147+
Type(LONG),
148+
Type(FLOAT),
149+
Type(DOUBLE),
150+
Primitive(BYTE_PRIMITIVE),
151+
Primitive(SHORT_PRIMITIVE),
152+
Primitive(INTEGER_PRIMITIVE),
153+
Primitive(LONG_PRIMITIVE),
154+
Primitive(FLOAT_PRIMITIVE),
155+
Primitive(DOUBLE_PRIMITIVE),
139156
AdditionalType(JSON_NULLABLE)
140157
)
141158

142159
private val INTEGER_TYPES = listOf(
143-
Type("java.math.BigDecimal"),
144-
Type("java.math.BigInteger"),
145-
Type("java.lang.CharSequence"),
146-
Type("java.lang.Byte"),
147-
Type("java.lang.Short"),
148-
Type("java.lang.Integer"),
149-
Type("java.lang.Long"),
150-
Primitive("byte"),
151-
Primitive("short"),
152-
Primitive("int"),
153-
Primitive("long"),
160+
Type(BIG_DECIMAL),
161+
Type(BIG_INTEGER),
162+
Type(CHAR_SEQUENCE),
163+
Type(BYTE),
164+
Type(SHORT),
165+
Type(INTEGER),
166+
Type(LONG),
167+
Primitive(BYTE_PRIMITIVE),
168+
Primitive(SHORT_PRIMITIVE),
169+
Primitive(INTEGER_PRIMITIVE),
170+
Primitive(LONG_PRIMITIVE),
154171
AdditionalType(JSON_NULLABLE)
155172
)
156173

157174
private val LENGTH_TYPES = listOf(
158-
Type("java.lang.CharSequence"),
175+
Type(CHAR_SEQUENCE),
159176
Type("java.util.Collection"),
160177
Type("java.util.Map"),
161178
Array(),
162179
AdditionalType(JSON_NULLABLE)
163180
)
164181

165182
private val MAX_MIN_TYPES = listOf(
166-
Type("java.math.BigDecimal"),
167-
Type("java.math.BigInteger"),
168-
Type("java.lang.Byte"),
169-
Type("java.lang.Short"),
170-
Type("java.lang.Integer"),
171-
Type("java.lang.Long"),
172-
Primitive("byte"),
173-
Primitive("short"),
174-
Primitive("int"),
175-
Primitive("long"),
183+
Type(BIG_DECIMAL),
184+
Type(BIG_INTEGER),
185+
Type(BYTE),
186+
Type(SHORT),
187+
Type(INTEGER),
188+
Type(LONG),
189+
Primitive(BYTE_PRIMITIVE),
190+
Primitive(SHORT_PRIMITIVE),
191+
Primitive(INTEGER_PRIMITIVE),
192+
Primitive(LONG_PRIMITIVE),
176193
AdditionalType(JSON_NULLABLE)
177194
)
178195

179196
private val EMAIL_TYPES = listOf(
180-
Type("java.lang.CharSequence"),
197+
Type(CHAR_SEQUENCE),
181198
AdditionalType(JSON_NULLABLE)
182199
)
183200

@@ -203,7 +220,7 @@ private val PAST_TYPES = listOf(
203220
AdditionalType(JSON_NULLABLE)
204221
)
205222

206-
// not all annotation are supported/used by the BeanValidationFactory
223+
// not all annotations are supported/used by the BeanValidationFactory
207224
private val supportedTargets = mapOf<String, Set<SupportedType>>(
208225
/* javax */
209226
// "javax.validation.constraints.Null" to ANY_TYPES.toMutableSet(),

0 commit comments

Comments
 (0)