Skip to content

Commit f74a76f

Browse files
Handle recursive refs in ComposedSchema (allOf/anyOf)
1 parent a6df0ad commit f74a76f

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

core/src/main/java/org/openapitools/openapidiff/core/compare/SchemaDiff.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected static Schema<?> resolveComposedSchema(
9696
updatedVisitedRefs.add(composed.get$ref());
9797
composed = refPointer.resolveRef(components, composed, composed.get$ref());
9898
composed = resolveComposedSchema(components, composed, updatedVisitedRefs);
99-
schema = addSchema(schema, composed);
99+
addSchema(schema, composed);
100100
}
101101
}
102102
composedSchema.setAllOf(null);
@@ -340,8 +340,8 @@ public DeferredChanged<ChangedSchema> computeDiffForReal(
340340
left = refPointer.resolveRef(this.leftComponents, left, getSchemaRef(left));
341341
right = refPointer.resolveRef(this.rightComponents, right, getSchemaRef(right));
342342

343-
left = resolveComposedSchema(leftComponents, left, new HashSet<>());
344-
right = resolveComposedSchema(rightComponents, right, new HashSet<>());
343+
left = resolveComposedSchema(leftComponents, left, refSet.getLeftKeys());
344+
right = resolveComposedSchema(rightComponents, right, refSet.getRightKeys());
345345

346346
// If type of schemas are different, just set old & new schema, set changedType to true in
347347
// SchemaDiffResult and

core/src/main/java/org/openapitools/openapidiff/core/model/deferred/RecursiveSchemaSet.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@ public class RecursiveSchemaSet {
77
HashSet<String> leftKeys = new HashSet<>();
88
HashSet<String> rightKeys = new HashSet<>();
99

10+
public HashSet<String> getLeftKeys() {
11+
return leftKeys;
12+
}
13+
14+
public HashSet<String> getRightKeys() {
15+
return rightKeys;
16+
}
17+
1018
public boolean contains(CacheKey key) {
1119
return leftKeys.contains(key.getLeft()) || rightKeys.contains(key.getRight());
1220
}
1321

1422
public void put(CacheKey key) {
1523
leftKeys.add(key.getLeft());
16-
leftKeys.add(key.getRight());
24+
rightKeys.add(key.getRight());
1725
}
1826
}

core/src/test/resources/recursive_model_1.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ components:
2525
type: string
2626
message2:
2727
type: string
28+
recursiveDirect:
29+
$ref: '#/components/schemas/B'
30+
recursiveAllOf:
31+
allOf:
32+
- $ref: '#/components/schemas/B'
33+
recursiveOneOf:
34+
oneOf:
35+
- $ref: '#/components/schemas/B'
36+
recursiveAnyOf:
37+
anyOf:
38+
- $ref: '#/components/schemas/B'
2839
details:
2940
type: array
3041
items:

0 commit comments

Comments
 (0)