|
12 | 12 | import org.apache.commons.collections4.CollectionUtils; |
13 | 13 | import org.openapitools.openapidiff.core.compare.MapKeyDiff; |
14 | 14 | import org.openapitools.openapidiff.core.compare.OpenApiDiff; |
| 15 | +import org.openapitools.openapidiff.core.compare.SchemaDiff; |
15 | 16 | import org.openapitools.openapidiff.core.model.ChangedSchema; |
16 | 17 | import org.openapitools.openapidiff.core.model.DiffContext; |
17 | 18 | import org.openapitools.openapidiff.core.model.deferred.DeferredBuilder; |
@@ -98,11 +99,24 @@ public <T extends Schema<X>, X> DeferredChanged<ChangedSchema> diff( |
98 | 99 | .build() |
99 | 100 | .flatMap( |
100 | 101 | values -> super.diff(refSet, leftComponents, rightComponents, left, right, context)); |
| 102 | + } else if (isResolvedToPlainSchema(right)) { |
| 103 | + // `right` is a composed schema whose allOf/anyOf members have already been merged into it |
| 104 | + // by SchemaDiff#resolveComposedSchema, so structurally it is a plain schema. Types and |
| 105 | + // formats were compared in SchemaDiff#computeDiffForReal before this result was selected, |
| 106 | + // so diff both sides with the result matching the left-hand schema instead of reporting a |
| 107 | + // type change. |
| 108 | + return SchemaDiff.getSchemaDiffResult(left.getClass(), openApiDiff) |
| 109 | + .diff(refSet, leftComponents, rightComponents, left, right, context); |
101 | 110 | } else { |
102 | 111 | return openApiDiff.getSchemaDiff().getTypeChangedSchema(left, right, context); |
103 | 112 | } |
104 | 113 | } |
105 | 114 |
|
| 115 | + private static boolean isResolvedToPlainSchema(Schema<?> schema) { |
| 116 | + return schema instanceof ComposedSchema |
| 117 | + && CollectionUtils.isEmpty(((ComposedSchema) schema).getOneOf()); |
| 118 | + } |
| 119 | + |
106 | 120 | private Map<String, Schema> getSchema( |
107 | 121 | Components components, Map<String, String> mapping, ComposedSchema composedSchema) { |
108 | 122 | Map<String, Schema> result = new LinkedHashMap<>(); |
|
0 commit comments