Skip to content

Commit 7dbc867

Browse files
authored
fix(specmap): fix resolver being affected by the order of schemas (#3857)
Refs swagger-api/swagger-ui#10096
1 parent 2e8b04b commit 7dbc867

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/resolver/specmap/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ class SpecMap {
136136
if (!traversed) {
137137
if (isObj) {
138138
// Only store the ref if it exists
139-
if (specmap.allowMetaPatches && objRef) {
139+
if (
140+
specmap.allowMetaPatches &&
141+
objRef &&
142+
isSubPath(pathDiscriminator, updatedPath)
143+
) {
140144
refCache[objRef] = true;
141145
}
142146
yield* traverse(val, updatedPath, patch);

test/subtree-resolver/strategies/openapi-2--3-0.js

+28
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,33 @@ describe('subtree $ref resolver', () => {
626626
});
627627
});
628628

629+
test('should resolve nested allOf with $ref with no influence of order of schemas', async () => {
630+
const input = {
631+
components: {
632+
schemas: {
633+
Second: { allOf: [{ $ref: '#/components/schemas/Third' }] },
634+
First: { allOf: [{ $ref: '#/components/schemas/Second' }] },
635+
Third: { allOf: [{ $ref: '#/components/schemas/Fourth' }] },
636+
Fourth: { allOf: [{ $ref: '#/components/schemas/Fifth' }] },
637+
Fifth: { properties: { a: { type: 'string' } } },
638+
},
639+
},
640+
};
641+
642+
const res = await resolve(input, ['components', 'schemas', 'First']);
643+
644+
expect(res).toEqual({
645+
errors: [],
646+
spec: {
647+
properties: {
648+
a: {
649+
type: 'string',
650+
},
651+
},
652+
},
653+
});
654+
});
655+
629656
test('should resolve complex allOf correctly', async () => {
630657
const input = {
631658
definitions: {
@@ -679,6 +706,7 @@ describe('subtree $ref resolver', () => {
679706
},
680707
});
681708
});
709+
682710
test('should fully resolve across remote documents correctly', async () => {
683711
const mockPool = mockAgent.get('http://example.com');
684712
mockPool.intercept({ path: '/remote.json' }).reply(

0 commit comments

Comments
 (0)