Skip to content

Commit 2aeae7c

Browse files
committed
fix(walker): processedFragments should always contain non-mirrored nodes
1 parent 83a901e commit 2aeae7c

File tree

3 files changed

+9
-106
lines changed

3 files changed

+9
-106
lines changed

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

Lines changed: 2 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -613,57 +613,7 @@ 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-
│ │ ├─ 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-
│ │ │ ├─ types
646-
│ │ │ │ └─ 0: object
647-
│ │ │ ├─ primaryType: object
648-
│ │ │ └─ children
649-
│ │ │ └─ 0
650-
│ │ │ └─ #/properties/foo/properties/user/allOf/0/properties/users/items/properties/creation/properties/user/allOf/0/properties/users/items/properties/creation/properties/user
651-
│ │ │ ├─ combiners
652-
│ │ │ │ └─ 0: allOf
653-
│ │ │ └─ children
654-
│ │ │ └─ 0
655-
│ │ │ └─ #/properties/foo/properties/user/allOf/0/properties/users/items/properties/creation/properties/user/allOf/0/properties/users/items/properties/creation/properties/user/allOf/0
656-
│ │ │ └─ mirrors: #/properties/foo/properties/user/allOf/0/properties/users/items/properties/creation/properties/user/allOf/0
657-
│ │ ├─ 1
658-
│ │ │ └─ #/properties/foo/properties/user/allOf/0/properties/users/items/properties/creation/properties/user/allOf/0/properties/users/items/properties/foo
659-
│ │ │ ├─ $ref: #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts
660-
│ │ │ ├─ external: false
661-
│ │ │ └─ error: Could not resolve '#/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts'
662-
│ │ └─ 2
663-
│ │ └─ #/properties/foo/properties/user/allOf/0/properties/users/items/properties/creation/properties/user/allOf/0/properties/users/items/properties/products
664-
│ │ ├─ $ref: #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts
665-
│ │ ├─ external: false
666-
│ │ └─ error: Could not resolve '#/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts'
616+
│ │ └─ mirrors: #/properties/foo/properties/user/allOf/0
667617
│ ├─ 1
668618
│ │ └─ #/properties/foo/properties/user/allOf/0/properties/users/items/properties/foo
669619
│ │ ├─ $ref: #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts
@@ -693,57 +643,7 @@ exports[`SchemaTree output should generate valid tree for combiners/allOfs/compl
693643
└─ children
694644
└─ 0
695645
└─ #/properties/bar/properties/foo/properties/user/allOf/0
696-
├─ types
697-
│ └─ 0: object
698-
├─ primaryType: object
699-
└─ children
700-
├─ 0
701-
│ └─ #/properties/bar/properties/foo/properties/user/allOf/0/properties/names
702-
│ ├─ types
703-
│ │ └─ 0: array
704-
│ ├─ primaryType: array
705-
│ └─ children
706-
│ └─ 0
707-
│ └─ #/properties/bar/properties/foo/properties/user/allOf/0/properties/names/items
708-
│ ├─ $ref: #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/name
709-
│ ├─ external: false
710-
│ └─ error: Could not resolve '#/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/name'
711-
└─ 1
712-
└─ #/properties/bar/properties/foo/properties/user/allOf/0/properties/users
713-
├─ types
714-
│ └─ 0: array
715-
├─ primaryType: array
716-
└─ children
717-
└─ 0
718-
└─ #/properties/bar/properties/foo/properties/user/allOf/0/properties/users/items
719-
├─ types
720-
│ └─ 0: object
721-
├─ primaryType: object
722-
└─ children
723-
├─ 0
724-
│ └─ #/properties/bar/properties/foo/properties/user/allOf/0/properties/users/items/properties/creation
725-
│ ├─ types
726-
│ │ └─ 0: object
727-
│ ├─ primaryType: object
728-
│ └─ children
729-
│ └─ 0
730-
│ └─ #/properties/bar/properties/foo/properties/user/allOf/0/properties/users/items/properties/creation/properties/user
731-
│ ├─ combiners
732-
│ │ └─ 0: allOf
733-
│ └─ children
734-
│ └─ 0
735-
│ └─ #/properties/bar/properties/foo/properties/user/allOf/0/properties/users/items/properties/creation/properties/user/allOf/0
736-
│ └─ mirrors: #/properties/foo/properties/user/allOf/0/properties/users/items/properties/creation/properties/user/allOf/0/properties/users/items/properties/creation/properties/user/allOf/0
737-
├─ 1
738-
│ └─ #/properties/bar/properties/foo/properties/user/allOf/0/properties/users/items/properties/foo
739-
│ ├─ $ref: #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts
740-
│ ├─ external: false
741-
│ └─ error: Could not resolve '#/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts'
742-
└─ 2
743-
└─ #/properties/bar/properties/foo/properties/user/allOf/0/properties/users/items/properties/products
744-
├─ $ref: #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts
745-
├─ external: false
746-
└─ error: Could not resolve '#/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts'
646+
└─ mirrors: #/properties/foo/properties/user/allOf/0
747647
"
748648
`;
749649

src/__tests__/tree.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ describe('SchemaTree', () => {
243243
│ └─ children
244244
│ └─ 0
245245
│ └─ #/properties/bar/items
246-
│ └─ mirrors: #/properties/foo/items/properties/user/items
246+
│ └─ mirrors: #/properties/foo/items
247247
└─ 2
248248
└─ #/properties/baz
249249
├─ types
@@ -252,7 +252,7 @@ describe('SchemaTree', () => {
252252
└─ children
253253
└─ 0
254254
└─ #/properties/baz/items
255-
└─ mirrors: #/properties/bar/items
255+
└─ mirrors: #/properties/foo/items
256256
"
257257
`);
258258
});

src/walker/walker.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class Walker extends EventEmitter<WalkerEmitter> {
4646
this.depth = -1;
4747
this.fragment = this.root.fragment;
4848
this.schemaNode = this.root;
49-
this.processedFragments = new WeakMap<SchemaFragment, SchemaNode>();
49+
this.processedFragments = new WeakMap<SchemaFragment, RegularNode | ReferenceNode>();
5050
}
5151

5252
public loadSnapshot(snapshot: WalkerSnapshot) {
@@ -107,7 +107,10 @@ export class Walker extends EventEmitter<WalkerEmitter> {
107107
for (const schemaNode of this.processFragment()) {
108108
super.emit('enterNode', schemaNode);
109109

110-
this.processedFragments.set(schemaNode.fragment, schemaNode);
110+
this.processedFragments.set(
111+
schemaNode.fragment,
112+
isMirroredNode(schemaNode) ? schemaNode.mirroredNode : schemaNode,
113+
);
111114

112115
this.fragment = schemaNode.fragment;
113116
this.depth = initialDepth + 1;

0 commit comments

Comments
 (0)