Skip to content

Commit b1f0127

Browse files
authored
add methods to name interface (OpenAPITools#2046)
1 parent 0532699 commit b1f0127

File tree

1 file changed

+53
-24
lines changed

1 file changed

+53
-24
lines changed

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

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,40 +1325,69 @@ public String getSchemaType(Schema schema) {
13251325
if (schema instanceof ComposedSchema) { // composed schema
13261326
ComposedSchema cs = (ComposedSchema) schema;
13271327
List<Schema> schemas = ModelUtils.getInterfaces(cs);
1328-
if (cs.getAllOf() != null) {
1329-
List<String> names = new ArrayList<>();
1330-
for (Schema s : schemas) {
1331-
names.add(getSingleSchemaType(s));
1332-
}
13331328

1334-
if (names.size() == 0) {
1335-
LOGGER.error("allOf has no member defined: {}. Default to ERROR_ALLOF_SCHEMA", cs);
1336-
return "ERROR_ALLOF_SCHEMA";
1337-
} else if (names.size() == 1) {
1338-
return names.get(0);
1339-
} else {
1340-
LOGGER.warn("allOf with multiple schemas defined. Using only the first one: {}. To fully utilize allOf, please use $ref instead of inline schema definition", names.get(0));
1341-
return names.get(0);
1342-
}
1329+
List<String> names = new ArrayList<>();
1330+
for (Schema s : schemas) {
1331+
names.add(getSingleSchemaType(s));
1332+
}
1333+
1334+
if (cs.getAllOf() != null) {
1335+
return toAllOfName(names, cs);
13431336
} else if (cs.getAnyOf() != null) { // anyOf
1344-
List<String> names = new ArrayList<>();
1345-
for (Schema s : schemas) {
1346-
names.add(getSingleSchemaType(s));
1347-
}
1348-
return "anyOf<" + String.join(",", names) + ">";
1337+
return toAnyOfName(names, cs);
13491338
} else if (cs.getOneOf() != null) { // oneOf
1350-
List<String> names = new ArrayList<>();
1351-
for (Schema s : schemas) {
1352-
names.add(getSingleSchemaType(s));
1353-
}
1354-
return "oneOf<" + String.join(",", names) + ">";
1339+
return toOneOfName(names, cs);
13551340
}
13561341
}
13571342

13581343
return getSingleSchemaType(schema);
13591344

13601345
}
13611346

1347+
/**
1348+
* Return the name of the allOf schema
1349+
*
1350+
* @param names List of names
1351+
* @param composedSchema composed schema
1352+
* @return name of the allOf schema
1353+
*/
1354+
@SuppressWarnings("static-method")
1355+
public String toAllOfName(List<String> names, ComposedSchema composedSchema) {
1356+
if (names.size() == 0) {
1357+
LOGGER.error("allOf has no member defined: {}. Default to ERROR_ALLOF_SCHEMA", composedSchema);
1358+
return "ERROR_ALLOF_SCHEMA";
1359+
} else if (names.size() == 1) {
1360+
return names.get(0);
1361+
} else {
1362+
LOGGER.warn("allOf with multiple schemas defined. Using only the first one: {}. To fully utilize allOf, please use $ref instead of inline schema definition", names.get(0));
1363+
return names.get(0);
1364+
}
1365+
}
1366+
1367+
/**
1368+
* Return the name of the anyOf schema
1369+
*
1370+
* @param names List of names
1371+
* @param composedSchema composed schema
1372+
* @return name of the anyOf schema
1373+
*/
1374+
@SuppressWarnings("static-method")
1375+
public String toAnyOfName(List<String> names, ComposedSchema composedSchema) {
1376+
return "anyOf<" + String.join(",", names) + ">";
1377+
}
1378+
1379+
/**
1380+
* Return the name of the oneOf schema
1381+
*
1382+
* @param names List of names
1383+
* @param composedSchema composed schema
1384+
* @return name of the oneOf schema
1385+
*/
1386+
@SuppressWarnings("static-method")
1387+
public String toOneOfName(List<String> names, ComposedSchema composedSchema) {
1388+
return "oneOf<" + String.join(",", names) + ">";
1389+
}
1390+
13621391
private String getSingleSchemaType(Schema schema) {
13631392
Schema unaliasSchema = ModelUtils.unaliasSchema(this.openAPI, schema);
13641393

0 commit comments

Comments
 (0)