Skip to content

Commit

Permalink
Better isAlias detection (#16943)
Browse files Browse the repository at this point in the history
* better isAlias check for allOf with single item

* better code format
  • Loading branch information
wing328 committed Oct 31, 2023
1 parent 6cd73eb commit bfe6157
Show file tree
Hide file tree
Showing 3 changed files with 701 additions and 632 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5987,21 +5987,31 @@ Map<String, String> getAllAliases(Map<String, Schema> schemas) {
for (Map.Entry<String, Schema> entry : schemas.entrySet()) {
Schema schema = entry.getValue();
if (isAliasOfSimpleTypes(schema)) {
String oasName = entry.getKey();
String schemaType = getPrimitiveType(schema);
aliases.put(oasName, schemaType);
if (schema.getAllOf() != null && schema.getAllOf().size() == 1) { // allOf with a single item
Schema unaliasSchema = unaliasSchema(schema);
unaliasSchema = ModelUtils.getReferencedSchema(this.openAPI, unaliasSchema);
aliases.put(entry.getKey() /* schema name, e.g. Pet */, getPrimitiveType(unaliasSchema));
} else {
aliases.put(entry.getKey() /* schema name, e.g. Pet */, getPrimitiveType(schema));
}
}

}

return aliases;
}

private static Boolean isAliasOfSimpleTypes(Schema schema) {
private Boolean isAliasOfSimpleTypes(Schema schema) {
if (schema == null) {
return false;
}

// allOf with a single item
if (schema.getAllOf() != null && schema.getAllOf().size() == 1
&& schema.getAllOf().get(0) instanceof Schema) {
schema = unaliasSchema((Schema) schema.getAllOf().get(0));
schema = ModelUtils.getReferencedSchema(this.openAPI, schema);
}

return (!ModelUtils.isObjectSchema(schema)
&& !ModelUtils.isArraySchema(schema)
&& !ModelUtils.isMapSchema(schema)
Expand Down
Loading

0 comments on commit bfe6157

Please sign in to comment.