Skip to content

Commit ddcaa13

Browse files
committed
perf(walker): fragment retrieval is missed after resolving
1 parent 6edf57f commit ddcaa13

File tree

3 files changed

+189
-50
lines changed

3 files changed

+189
-50
lines changed

src/__tests__/__snapshots__/tree.spec.ts.snap

Lines changed: 93 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,46 @@ exports[`SchemaTree output should generate valid tree for combiners/allOfs/compl
613613
│ │ └─ children
614614
│ │ └─ 0
615615
│ │ └─ #/properties/foo/properties/user/allOf/0/properties/users/items/properties/creation/properties/user/allOf/0
616-
│ │ └─ mirrors: #/properties/foo/properties/user/allOf/0
616+
│ │ ├─ types
617+
│ │ │ └─ 0: object
618+
│ │ ├─ primaryType: object
619+
│ │ └─ children
620+
│ │ ├─ 0
621+
│ │ │ └─ #/properties/foo/properties/user/allOf/0/properties/users/items/properties/creation/properties/user/allOf/0/properties/names
622+
│ │ │ ├─ types
623+
│ │ │ │ └─ 0: array
624+
│ │ │ ├─ primaryType: array
625+
│ │ │ └─ children
626+
│ │ │ └─ 0
627+
│ │ │ └─ #/properties/foo/properties/user/allOf/0/properties/users/items/properties/creation/properties/user/allOf/0/properties/names/items
628+
│ │ │ ├─ $ref: #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/name
629+
│ │ │ ├─ external: false
630+
│ │ │ └─ error: Could not resolve '#/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/name'
631+
│ │ └─ 1
632+
│ │ └─ #/properties/foo/properties/user/allOf/0/properties/users/items/properties/creation/properties/user/allOf/0/properties/users
633+
│ │ ├─ types
634+
│ │ │ └─ 0: array
635+
│ │ ├─ primaryType: array
636+
│ │ └─ children
637+
│ │ └─ 0
638+
│ │ └─ #/properties/foo/properties/user/allOf/0/properties/users/items/properties/creation/properties/user/allOf/0/properties/users/items
639+
│ │ ├─ types
640+
│ │ │ └─ 0: object
641+
│ │ ├─ primaryType: object
642+
│ │ └─ children
643+
│ │ ├─ 0
644+
│ │ │ └─ #/properties/foo/properties/user/allOf/0/properties/users/items/properties/creation/properties/user/allOf/0/properties/users/items/properties/creation
645+
│ │ │ └─ mirrors: #/properties/foo/properties/user/allOf/0/properties/users/items/properties/creation
646+
│ │ ├─ 1
647+
│ │ │ └─ #/properties/foo/properties/user/allOf/0/properties/users/items/properties/creation/properties/user/allOf/0/properties/users/items/properties/foo
648+
│ │ │ ├─ $ref: #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts
649+
│ │ │ ├─ external: false
650+
│ │ │ └─ error: Could not resolve '#/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts'
651+
│ │ └─ 2
652+
│ │ └─ #/properties/foo/properties/user/allOf/0/properties/users/items/properties/creation/properties/user/allOf/0/properties/users/items/properties/products
653+
│ │ ├─ $ref: #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts
654+
│ │ ├─ external: false
655+
│ │ └─ error: Could not resolve '#/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts'
617656
│ ├─ 1
618657
│ │ └─ #/properties/foo/properties/user/allOf/0/properties/users/items/properties/foo
619658
│ │ ├─ $ref: #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts
@@ -643,7 +682,57 @@ exports[`SchemaTree output should generate valid tree for combiners/allOfs/compl
643682
└─ children
644683
└─ 0
645684
└─ #/properties/bar/properties/foo/properties/user/allOf/0
646-
└─ mirrors: #/properties/foo/properties/user/allOf/0
685+
├─ types
686+
│ └─ 0: object
687+
├─ primaryType: object
688+
└─ children
689+
├─ 0
690+
│ └─ #/properties/bar/properties/foo/properties/user/allOf/0/properties/names
691+
│ ├─ types
692+
│ │ └─ 0: array
693+
│ ├─ primaryType: array
694+
│ └─ children
695+
│ └─ 0
696+
│ └─ #/properties/bar/properties/foo/properties/user/allOf/0/properties/names/items
697+
│ ├─ $ref: #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/name
698+
│ ├─ external: false
699+
│ └─ error: Could not resolve '#/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/name'
700+
└─ 1
701+
└─ #/properties/bar/properties/foo/properties/user/allOf/0/properties/users
702+
├─ types
703+
│ └─ 0: array
704+
├─ primaryType: array
705+
└─ children
706+
└─ 0
707+
└─ #/properties/bar/properties/foo/properties/user/allOf/0/properties/users/items
708+
├─ types
709+
│ └─ 0: object
710+
├─ primaryType: object
711+
└─ children
712+
├─ 0
713+
│ └─ #/properties/bar/properties/foo/properties/user/allOf/0/properties/users/items/properties/creation
714+
│ ├─ types
715+
│ │ └─ 0: object
716+
│ ├─ primaryType: object
717+
│ └─ children
718+
│ └─ 0
719+
│ └─ #/properties/bar/properties/foo/properties/user/allOf/0/properties/users/items/properties/creation/properties/user
720+
│ ├─ combiners
721+
│ │ └─ 0: allOf
722+
│ └─ children
723+
│ └─ 0
724+
│ └─ #/properties/bar/properties/foo/properties/user/allOf/0/properties/users/items/properties/creation/properties/user/allOf/0
725+
│ └─ mirrors: #/properties/foo/properties/user/allOf/0/properties/users/items/properties/creation/properties/user/allOf/0
726+
├─ 1
727+
│ └─ #/properties/bar/properties/foo/properties/user/allOf/0/properties/users/items/properties/foo
728+
│ ├─ $ref: #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts
729+
│ ├─ external: false
730+
│ └─ error: Could not resolve '#/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts'
731+
└─ 2
732+
└─ #/properties/bar/properties/foo/properties/user/allOf/0/properties/users/items/properties/products
733+
├─ $ref: #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts
734+
├─ external: false
735+
└─ error: Could not resolve '#/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts'
647736
"
648737
`;
649738

@@ -993,14 +1082,7 @@ exports[`SchemaTree output should generate valid tree for default-schema.json 1`
9931082
│ └─ primaryType: integer
9941083
├─ 7
9951084
│ └─ #/properties/ref
996-
│ ├─ types
997-
│ │ ├─ 0: string
998-
│ │ └─ 1: object
999-
│ ├─ primaryType: object
1000-
│ └─ children
1001-
│ └─ 0
1002-
│ └─ #/properties/ref/properties/ids
1003-
│ └─ mirrors: #/properties/permissions/properties/ids
1085+
│ └─ mirrors: #/properties/permissions
10041086
├─ 8
10051087
│ └─ #/patternProperties/^id_
10061088
│ ├─ types
@@ -1097,19 +1179,7 @@ exports[`SchemaTree output should generate valid tree for references/base.json 1
10971179
│ └─ primaryType: string
10981180
└─ 1
10991181
└─ #/properties/shipping_address
1100-
├─ types
1101-
│ └─ 0: object
1102-
├─ primaryType: object
1103-
└─ children
1104-
├─ 0
1105-
│ └─ #/properties/shipping_address/properties/street_address
1106-
│ └─ mirrors: #/properties/billing_address/properties/street_address
1107-
├─ 1
1108-
│ └─ #/properties/shipping_address/properties/city
1109-
│ └─ mirrors: #/properties/billing_address/properties/city
1110-
└─ 2
1111-
└─ #/properties/shipping_address/properties/state
1112-
└─ mirrors: #/properties/billing_address/properties/state
1182+
└─ mirrors: #/properties/billing_address
11131183
"
11141184
`;
11151185

src/__tests__/tree.spec.ts

Lines changed: 73 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -228,31 +228,86 @@ describe('SchemaTree', () => {
228228
│ └─ children
229229
│ └─ 0
230230
│ └─ #/properties/foo/items/properties/user
231-
│ ├─ types
232-
│ │ └─ 0: array
233-
│ ├─ primaryType: array
234-
│ └─ children
235-
│ └─ 0
236-
│ └─ #/properties/foo/items/properties/user/items
237-
│ └─ mirrors: #/properties/foo/items
231+
│ └─ mirrors: #/properties/foo
238232
├─ 1
239233
│ └─ #/properties/bar
240-
│ ├─ types
241-
│ │ └─ 0: array
242-
│ ├─ primaryType: array
243-
│ └─ children
244-
│ └─ 0
245-
│ └─ #/properties/bar/items
246-
│ └─ mirrors: #/properties/foo/items
234+
│ └─ mirrors: #/properties/foo
247235
└─ 2
248236
└─ #/properties/baz
237+
└─ mirrors: #/properties/foo
238+
"
239+
`);
240+
});
241+
242+
it('should handle circular references pointing at parents', () => {
243+
const schema: JSONSchema4 = {
244+
properties: {
245+
bar: {
246+
properties: {
247+
foo: {
248+
type: 'string',
249+
},
250+
baz: {
251+
$ref: '#/properties/bar',
252+
},
253+
},
254+
},
255+
},
256+
};
257+
258+
expect(printTree(schema)).toMatchInlineSnapshot(`
259+
"└─ #
260+
├─ types
261+
│ └─ 0: object
262+
├─ primaryType: object
263+
└─ children
264+
└─ 0
265+
└─ #/properties/bar
266+
├─ types
267+
│ └─ 0: object
268+
├─ primaryType: object
269+
└─ children
270+
├─ 0
271+
│ └─ #/properties/bar/properties/foo
272+
│ ├─ types
273+
│ │ └─ 0: string
274+
│ └─ primaryType: string
275+
└─ 1
276+
└─ #/properties/bar/properties/baz
277+
└─ mirrors: #/properties/bar
278+
"
279+
`);
280+
});
281+
282+
it('should handle circular references pointing at document', () => {
283+
const schema: JSONSchema4 = {
284+
title: 'root',
285+
properties: {
286+
bar: {
287+
properties: {
288+
baz: {
289+
$ref: '#',
290+
},
291+
},
292+
},
293+
},
294+
};
295+
296+
expect(printTree(schema)).toMatchInlineSnapshot(`
297+
"└─ #
298+
├─ types
299+
│ └─ 0: object
300+
├─ primaryType: object
301+
└─ children
302+
└─ 0
303+
└─ #/properties/bar
249304
├─ types
250-
│ └─ 0: array
251-
├─ primaryType: array
305+
│ └─ 0: object
306+
├─ primaryType: object
252307
└─ children
253308
└─ 0
254-
└─ #/properties/baz/items
255-
└─ mirrors: #/properties/foo/items
309+
└─ #/properties/bar/properties/baz
310+
└─ mirrors: #
256311
"
257312
`);
258313
});

0 commit comments

Comments
 (0)