Skip to content

Commit

Permalink
fix null type check when simplifying any type (#18504)
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 committed Apr 26, 2024
1 parent a5ccd7a commit 1751163
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,13 @@ private Schema processSimplifyOneOf(Schema schema) {
if (oneOfSchemas.size() == 6) {
TreeSet<String> ts = new TreeSet<>();
for (Schema s: oneOfSchemas) {
ts.add(ModelUtils.getType(s));
s = ModelUtils.getReferencedSchema(openAPI, s);
String type = ModelUtils.getType(s);
if (type == null) {
LOGGER.debug("Error null type found in schema when simplifying any type with 6 sub-schemas: {}", s);
} else {
ts.add(type);
}
}

if (ts.equals(anyTypeTreeSet)) {
Expand Down Expand Up @@ -1068,7 +1074,13 @@ private Schema processSimplifyAnyOf(Schema schema) {
if (anyOfSchemas.size() == 6) {
TreeSet<String> ts = new TreeSet<>();
for (Schema s: anyOfSchemas) {
ts.add(ModelUtils.getType(s));
s = ModelUtils.getReferencedSchema(openAPI, s);
String type = ModelUtils.getType(s);
if (type == null) {
LOGGER.debug("Error null type found in schema when simplifying any type with 6 sub-schemas: {}", s);
} else {
ts.add(type);
}
}

if (ts.equals(anyTypeTreeSet)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ public void testOpenAPINormalizerSimplifyOneOfAnyOf() {
Schema schema13 = openAPI.getComponents().getSchemas().get("OneOfAnyType");
assertEquals(schema13.getOneOf().size(), 6);

Schema schema15 = openAPI.getComponents().getSchemas().get("AnyOfAnyTypeWithRef");
assertEquals(schema15.getAnyOf().size(), 6);

Map<String, String> options = new HashMap<>();
options.put("SIMPLIFY_ONEOF_ANYOF", "true");
OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer(openAPI, options);
Expand Down Expand Up @@ -216,6 +219,9 @@ public void testOpenAPINormalizerSimplifyOneOfAnyOf() {
assertEquals(schema14.getOneOf(), null);
assertEquals(schema14.getType(), null);

Schema schema16 = openAPI.getComponents().getSchemas().get("AnyOfAnyTypeWithRef");
assertEquals(schema16.getAnyOf(), null);
assertEquals(schema16.getType(), null);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ components:
- type: string
- type: number
- type: integer
AnyOfAnyTypeWithRef:
anyOf:
- type: boolean
- type: array
items: { }
- type: object
- type: string
- type: number
- $ref: '#/components/schemas/IntegerRef'
IntegerRef:
type: integer
OneOfAnyType:
oneOf:
- type: object
Expand Down

0 comments on commit 1751163

Please sign in to comment.