Skip to content
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 @@ -117,16 +117,18 @@ private Map<String, Schema> getSchema(

private Map<String, String> getMapping(ComposedSchema composedSchema) {
Map<String, String> reverseMapping = new LinkedHashMap<>();
for (Schema<?> schema : composedSchema.getOneOf()) {
String ref = schema.get$ref();
if (ref == null) {
continue;
}
String schemaName = refPointer.getRefName(ref);
if (schemaName == null) {
throw new IllegalArgumentException("invalid schema: " + ref);
if (composedSchema.getOneOf() != null) {
for (Schema<?> schema : composedSchema.getOneOf()) {
String ref = schema.get$ref();
if (ref == null) {
continue;
}
String schemaName = refPointer.getRefName(ref);
if (schemaName == null) {
throw new IllegalArgumentException("invalid schema: " + ref);
}
reverseMapping.put(ref, schemaName);
}
reverseMapping.put(ref, schemaName);
}

if (composedSchema.getDiscriminator() != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class OneOfDiffTest {
private final String OPENAPI_DOC8 = "oneOf_discriminator-missing_1.yaml";
private final String OPENAPI_DOC9 = "oneOf_discriminator-missing_2.yaml";
private final String OPENAPI_DOC10 = "unnamed_oneof_schema_1.yaml";
private final String OPENAPI_DOC11 = "oneOf_to_anyOf_1.yaml";
private final String OPENAPI_DOC12 = "oneOf_to_anyOf_2.yaml";

@Test
public void testDiffSame() {
Expand Down Expand Up @@ -59,4 +61,9 @@ public void testOneOfDiscrimitatorMissingSameOrder() {
public void testOneOfDiscrimitatorMissingDifferentOrder() {
assertOpenApiAreEquals(OPENAPI_DOC8, OPENAPI_DOC9);
}

@Test // issue #381
public void testOneOfToAnyOfDoesNotThrow() {
assertOpenApiChangedEndpoints(OPENAPI_DOC11, OPENAPI_DOC12);
}
}
34 changes: 34 additions & 0 deletions core/src/test/resources/oneOf_to_anyOf_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
openapi: 3.0.1
info:
title: oneOf to anyOf repro (old)
version: 1.0.0
paths:
/example:
get:
responses:
"200":
description: ok
content:
application/json:
schema:
$ref: "#/components/schemas/Result"
components:
schemas:
Result:
oneOf:
- $ref: "#/components/schemas/TypeA"
- $ref: "#/components/schemas/TypeB"
TypeA:
type: object
required:
- a
properties:
a:
type: string
TypeB:
type: object
required:
- b
properties:
b:
type: string
34 changes: 34 additions & 0 deletions core/src/test/resources/oneOf_to_anyOf_2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
openapi: 3.0.1
info:
title: oneOf to anyOf repro (new)
version: 1.0.0
paths:
/example:
get:
responses:
"200":
description: ok
content:
application/json:
schema:
$ref: "#/components/schemas/Result"
components:
schemas:
Result:
anyOf:
- $ref: "#/components/schemas/TypeA"
- $ref: "#/components/schemas/TypeB"
TypeA:
type: object
required:
- a
properties:
a:
type: string
TypeB:
type: object
required:
- b
properties:
b:
type: string