Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null type check when simplifying any type #18504

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading