@@ -338,8 +338,6 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
338
338
@ SuppressWarnings ("unchecked" )
339
339
Class <Enum <?>> rawEnumClass = (Class <Enum <?>>) type .getRawClass ();
340
340
model = _createSchemaForEnum (rawEnumClass );
341
- model = openapi31 ? new JsonSchema ().typesItem ("string" ) : new StringSchema ();
342
- _addEnumProps (type .getRawClass (), model );
343
341
isPrimitive = true ;
344
342
}
345
343
if (model == null ) {
@@ -1295,69 +1293,18 @@ protected boolean _isOptionalType(JavaType propType) {
1295
1293
}
1296
1294
1297
1295
/**
1298
- * Adds each enum property value to the model schema
1299
- *
1300
- * @param propClass the enum class for which to add properties
1301
- * @param property the schema to add properties to
1296
+ * @deprecated use '_createSchemaForEnum'
1302
1297
*/
1303
1298
protected void _addEnumProps (Class <?> propClass , Schema property ) {
1304
- final boolean useIndex = _mapper .isEnabled (SerializationFeature .WRITE_ENUMS_USING_INDEX );
1305
- final boolean useToString = _mapper .isEnabled (SerializationFeature .WRITE_ENUMS_USING_TO_STRING );
1306
-
1307
- Optional <Method > jsonValueMethod = Arrays .stream (propClass .getDeclaredMethods ())
1308
- .filter (m -> m .isAnnotationPresent (JsonValue .class ))
1309
- .filter (m -> m .getAnnotation (JsonValue .class ).value ())
1310
- .findFirst ();
1311
-
1312
- Optional <Field > jsonValueField = Arrays .stream (propClass .getDeclaredFields ())
1313
- .filter (f -> f .isAnnotationPresent (JsonValue .class ))
1314
- .filter (f -> f .getAnnotation (JsonValue .class ).value ())
1315
- .findFirst ();
1316
-
1317
- jsonValueMethod .ifPresent (m -> m .setAccessible (true ));
1318
- jsonValueField .ifPresent (m -> m .setAccessible (true ));
1319
- @ SuppressWarnings ("unchecked" )
1320
- Class <Enum <?>> enumClass = (Class <Enum <?>>) propClass ;
1321
-
1322
- Enum <?>[] enumConstants = enumClass .getEnumConstants ();
1323
-
1324
- if (enumConstants != null ) {
1325
- String [] enumValues = _intr ().findEnumValues (propClass , enumConstants ,
1326
- new String [enumConstants .length ]);
1327
-
1328
- for (Enum <?> en : enumConstants ) {
1329
- String n ;
1330
-
1331
- Field enumField = ReflectionUtils .findField (en .name (), enumClass );
1332
- if (null != enumField && enumField .isAnnotationPresent (Hidden .class )) {
1333
- continue ;
1334
- }
1335
-
1336
- String enumValue = enumValues [en .ordinal ()];
1337
- String methodValue = jsonValueMethod .flatMap (m -> ReflectionUtils .safeInvoke (m , en )).map (Object ::toString ).orElse (null );
1338
- String fieldValue = jsonValueField .flatMap (f -> ReflectionUtils .safeGet (f , en )).map (Object ::toString ).orElse (null );
1339
-
1340
- if (methodValue != null ) {
1341
- n = methodValue ;
1342
- } else if (fieldValue != null ) {
1343
- n = fieldValue ;
1344
- } else if (enumValue != null ) {
1345
- n = enumValue ;
1346
- } else if (useIndex ) {
1347
- n = String .valueOf (en .ordinal ());
1348
- } else if (useToString ) {
1349
- n = en .toString ();
1350
- } else {
1351
- n = _intr ().findEnumValue (en );
1352
- }
1353
- if (isStringSchema (property )) {
1354
- if (openapi31 ) {
1355
- property .addEnumItemObject (n );
1356
- } else {
1357
- StringSchema sp = (StringSchema ) property ;
1358
- sp .addEnumItem (n );
1359
- }
1360
- }
1299
+ if (propClass .isEnum ()) {
1300
+ Class <Enum <?>> rawEnumClass = (Class <Enum <?>>) propClass ;
1301
+ Schema enumSchema = _createSchemaForEnum (rawEnumClass );
1302
+ if (enumSchema != null ) {
1303
+ property .setEnum (enumSchema .getEnum ());
1304
+ property .setType (enumSchema .getType ());
1305
+ property .setFormat (enumSchema .getFormat ());
1306
+ property .setName (enumSchema .getName ());
1307
+ property .setDescription (enumSchema .getDescription ());
1361
1308
}
1362
1309
}
1363
1310
}
@@ -1386,23 +1333,23 @@ protected Schema _createSchemaForEnum(Class<Enum<?>> enumClass) {
1386
1333
jsonValueField .get ().setAccessible (true );
1387
1334
PrimitiveType primitiveType = PrimitiveType .fromType (jsonValueField .get ().getType ());
1388
1335
if (primitiveType != null ) {
1389
- schema = primitiveType .createProperty ();
1336
+ schema = openapi31 ? primitiveType . createProperty31 () : primitiveType .createProperty ();
1390
1337
}
1391
1338
} else if (jsonValueMethod .isPresent ()) {
1392
1339
jsonValueMethod .get ().setAccessible (true );
1393
1340
PrimitiveType primitiveType = PrimitiveType .fromType (jsonValueMethod .get ().getReturnType ());
1394
1341
if (primitiveType != null ) {
1395
- schema = primitiveType .createProperty ();
1342
+ schema = openapi31 ? primitiveType . createProperty31 () : primitiveType .createProperty ();
1396
1343
}
1397
1344
}
1398
1345
if (schema == null ) {
1399
- schema = new StringSchema ();
1346
+ schema = openapi31 ? new JsonSchema (). typesItem ( "string" ) : new StringSchema ();
1400
1347
}
1401
1348
1402
1349
Enum <?>[] enumConstants = enumClass .getEnumConstants ();
1403
1350
1404
1351
if (enumConstants != null ) {
1405
- String [] enumValues = _intr .findEnumValues (enumClass , enumConstants ,
1352
+ String [] enumValues = _intr () .findEnumValues (enumClass , enumConstants ,
1406
1353
new String [enumConstants .length ]);
1407
1354
1408
1355
for (Enum <?> en : enumConstants ) {
@@ -1427,7 +1374,7 @@ protected Schema _createSchemaForEnum(Class<Enum<?>> enumClass) {
1427
1374
} else if (useToString ) {
1428
1375
n = en .toString ();
1429
1376
} else {
1430
- n = _intr .findEnumValue (en );
1377
+ n = _intr () .findEnumValue (en );
1431
1378
}
1432
1379
schema .addEnumItemObject (n );
1433
1380
}
0 commit comments