Skip to content

Commit 2066ce6

Browse files
committed
Process referenced schemas with oneof/enum as well
1 parent 9dcfc07 commit 2066ce6

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,16 +1353,20 @@ protected Schema simplifyComposedSchemaWithEnums(Schema schema, List<Object> sub
13531353
// we cannot handle enums with multiple types
13541354
return schema;
13551355
}
1356+
1357+
if(subSchemas.size() < 2) {
1358+
//do not process if there's less than 2 sub-schemas. It will be normalized later, and this prevents
1359+
//named enum schemas from being converted to inline enum schemas
1360+
return schema;
1361+
}
13561362
String schemaType = ModelUtils.getType(schema);
13571363

13581364
for (Object item : subSchemas) {
13591365
if (!(item instanceof Schema)) {
13601366
return schema;
13611367
}
13621368

1363-
Schema subSchema = (Schema) item;
1364-
//processing references is very possible with this code (subSchema = ModelUtils.getReferencedSchema(openAPI, (Schema) item);),
1365-
// but might lead to reduced reuse in generated code
1369+
Schema subSchema = ModelUtils.getReferencedSchema(openAPI, (Schema) item);
13661370
if(subSchema.get$ref() != null) {
13671371
return schema;
13681372
}
@@ -1385,7 +1389,6 @@ protected Schema simplifyComposedSchemaWithEnums(Schema schema, List<Object> sub
13851389
return schema;
13861390
}
13871391
}
1388-
13891392
// Add all enum values from this sub-schema to our collection
13901393
enumValues.addAll(subSchema.getEnum());
13911394
}

0 commit comments

Comments
 (0)