1- import { isLocalRef } from '@stoplight/json' ;
1+ import { isLocalRef , pointerToPath } from '@stoplight/json' ;
22import { Tree , TreeListParentNode , TreeState } from '@stoplight/tree-list' ;
3+ import { JsonPath } from '@stoplight/types/dist' ;
34import { JSONSchema4 } from 'json-schema' ;
45import { get } from 'lodash-es' ;
56import { SchemaNode } from '../types' ;
@@ -30,8 +31,7 @@ export class SchemaTree extends Tree {
3031 this . invalidate ( ) ;
3132 }
3233
33- public populateTreeFragment ( parent : TreeListParentNode ) {
34- const { path } = MetadataStore [ parent . id ] ;
34+ public populateTreeFragment ( parent : TreeListParentNode , path : JsonPath ) {
3535 const initialLevel = Tree . getLevel ( parent ) ;
3636 const artificialRoot = Tree . createArtificialRoot ( ) ;
3737 populateTree ( get ( this . schema , path ) , artificialRoot , initialLevel , path , {
@@ -43,12 +43,18 @@ export class SchemaTree extends Tree {
4343 }
4444
4545 public unwrap ( node : TreeListParentNode ) {
46- if ( isRefNode ( MetadataStore [ node . id ] . schema ) ) {
47- } else if ( node . children . length === 0 && ! this . visited . has ( node ) ) {
48- this . populateTreeFragment ( node ) ;
49- super . unwrap ( node ) ;
46+ if ( node . children . length !== 0 || this . visited . has ( node ) ) {
47+ return super . unwrap ( node ) ;
48+ }
49+
50+ const { path, schema } = MetadataStore [ node . id ] ;
51+ if ( isRefNode ( schema ) ) {
52+ this . populateTreeFragment ( node , pointerToPath ( schema . $ref ) ) ;
5053 } else {
51- super . unwrap ( node ) ;
54+ this . populateTreeFragment ( node , path ) ;
5255 }
56+
57+ this . visited . add ( node ) ;
58+ return super . unwrap ( node ) ;
5359 }
5460}
0 commit comments