Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -154,6 +154,16 @@ protected static Schema<?> addSchema(Schema<?> schema, Schema<?> fromSchema) {
}
schema.getExtensions().putAll(fromSchema.getExtensions());
}
if (fromSchema instanceof ComposedSchema && schema instanceof ComposedSchema) {
ComposedSchema composedFromSchema = (ComposedSchema) fromSchema;
ComposedSchema composedSchema = (ComposedSchema) schema;
if (composedFromSchema.getOneOf() != null) {
if (composedSchema.getOneOf() == null) {
composedSchema.setOneOf(new ArrayList<>());
}
composedSchema.getOneOf().addAll(composedFromSchema.getOneOf());
}
}
if (fromSchema.getDiscriminator() != null) {
if (schema.getDiscriminator() == null) {
schema.setDiscriminator(new Discriminator());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.openapitools.openapidiff.core;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.openapitools.openapidiff.core.model.ChangedOpenApi;

public class AllOfOneOfDiffTest {
@Test
void allOfReferringToOneOfSchemasAreSupported() {
ChangedOpenApi diff = OpenApiCompare.fromLocations("issue-317_1.json", "issue-317_2.json");
assertThat(diff.isCoreChanged().isUnchanged());
}
}
84 changes: 84 additions & 0 deletions core/src/test/resources/issue-317_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"openapi":"3.0.0",
"info":{
"title":"API",
"version":"0.1.0"
},
"paths":{
"/resource":{
"post":{
"responses":{
"200":{
"description":"Created resource",
"content":{
"application/json":{
"schema":{
"type":"string"
}
}
}
}
},
"summary":"Create resource",
"requestBody":{
"content":{
"application/json":{
"schema":{
"$ref":"#/components/schemas/Resource"
}
}
},
"description":"Definition of the resource"
}
}
}
},
"components":{
"schemas":{
"Resource":{
"type":"object",
"properties":{
"assignment":{
"$ref":"#/components/schemas/Foo"
}
}
},
"Foo":{
"oneOf":[
{
"$ref":"#/components/schemas/Foo.Bar"
},
{
"$ref":"#/components/schemas/Foo.Baz"
}
],
"discriminator":{
"propertyName":"type",
"mapping":{
"Bar":"#/components/schemas/Foo.Bar",
"Baz":"#/components/schemas/Foo.Baz"
}
}
},
"Foo.Bar":{
"type":"object",
"properties":{
"type":{
"type":"string"
}
}
},
"Foo.Baz":{
"type":"object",
"properties":{
"type":{
"type":"string"
}
}
}
},
"securitySchemes":{

}
}
}
91 changes: 91 additions & 0 deletions core/src/test/resources/issue-317_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"openapi":"3.0.0",
"info":{
"title":"API",
"version":"0.1.0"
},
"paths":{
"/resource":{
"post":{
"responses":{
"200":{
"description":"Created resource",
"content":{
"application/json":{
"schema":{
"type":"string"
}
}
}
}
},
"summary":"Create resource",
"requestBody":{
"content":{
"application/json":{
"schema":{
"$ref":"#/components/schemas/Resource"
}
}
},
"description":"Definition of the resource"
}
}
}
},
"components":{
"schemas":{
"Resource":{
"type":"object",
"properties":{
"assignment":{
"default":{
"type":"Bar"
},
"allOf":[
{
"$ref":"#/components/schemas/Foo"
}
]
}
}
},
"Foo":{
"oneOf":[
{
"$ref":"#/components/schemas/Foo.Bar"
},
{
"$ref":"#/components/schemas/Foo.Baz"
}
],
"discriminator":{
"propertyName":"type",
"mapping":{
"Bar":"#/components/schemas/Foo.Bar",
"Baz":"#/components/schemas/Foo.Baz"
}
}
},
"Foo.Bar":{
"type":"object",
"properties":{
"type":{
"type":"string"
}
}
},
"Foo.Baz":{
"type":"object",
"properties":{
"type":{
"type":"string"
}
}
}
},
"securitySchemes":{

}
}
}