@@ -1347,7 +1347,7 @@ protected Schema processSimplifyOneOfEnum(Schema schema) {
13471347 * @return Simplified schema
13481348 */
13491349 protected Schema simplifyComposedSchemaWithEnums (Schema schema , List <Object > subSchemas , String composedType ) {
1350- List <Object > enumValues = new ArrayList <>();
1350+ Map <Object , String > enumValues = new LinkedHashMap <>();
13511351
13521352 if (schema .getTypes () != null && schema .getTypes ().size () > 1 ) {
13531353 // we cannot handle enums with multiple types
@@ -1387,7 +1387,21 @@ protected Schema simplifyComposedSchemaWithEnums(Schema schema, List<Object> sub
13871387 }
13881388 }
13891389 // Add all enum values from this sub-schema to our collection
1390- enumValues .addAll (subSchema .getEnum ());
1390+ if (subSchema .getEnum ().size () == 1 ) {
1391+ String description = subSchema .getTitle () == null ? "" : subSchema .getTitle ();
1392+ if (subSchema .getDescription () != null ) {
1393+ if (!description .isEmpty ()) {
1394+ description += " - " ;
1395+ }
1396+ description += subSchema .getDescription ();
1397+ }
1398+ enumValues .put (subSchema .getEnum ().get (0 ), description );
1399+ } else {
1400+ for (Object e : subSchema .getEnum ()) {
1401+ enumValues .put (e , "" );
1402+ }
1403+ }
1404+
13911405 }
13921406
13931407 return createSimplifiedEnumSchema (schema , enumValues , schemaType , composedType );
@@ -1403,7 +1417,7 @@ protected Schema simplifyComposedSchemaWithEnums(Schema schema, List<Object> sub
14031417 * @param composedType Type of composed schema being simplified
14041418 * @return Simplified enum schema
14051419 */
1406- protected Schema createSimplifiedEnumSchema (Schema originalSchema , List <Object > enumValues , String schemaType , String composedType ) {
1420+ protected Schema createSimplifiedEnumSchema (Schema originalSchema , Map <Object , String > enumValues , String schemaType , String composedType ) {
14071421 // Clear the composed schema type
14081422 if ("oneOf" .equals (composedType )) {
14091423 originalSchema .setOneOf (null );
@@ -1416,9 +1430,11 @@ protected Schema createSimplifiedEnumSchema(Schema originalSchema, List<Object>
14161430 ModelUtils .setType (originalSchema , schemaType );
14171431 }
14181432
1419- // Set the combined enum values (deduplicated to avoid duplicates)
1420- List <Object > uniqueEnumValues = enumValues .stream ().distinct ().collect (Collectors .toList ());
1421- originalSchema .setEnum (uniqueEnumValues );
1433+ originalSchema .setEnum (new ArrayList <>(enumValues .keySet ()));
1434+ if (enumValues .values ().stream ().anyMatch (e -> !e .isEmpty ())) {
1435+ //set x-enum-descriptions only if there's at least one non-empty description
1436+ originalSchema .addExtension ("x-enum-descriptions" , new ArrayList <>(enumValues .values ()));
1437+ }
14221438
14231439 LOGGER .debug ("Simplified {} with enum sub-schemas to single enum: {}" , composedType , originalSchema );
14241440
0 commit comments