diff --git a/src/__tests__/__fixtures__/references/circular-with-overrides.json b/src/__tests__/__fixtures__/references/circular-with-overrides.json new file mode 100644 index 0000000..49ce245 --- /dev/null +++ b/src/__tests__/__fixtures__/references/circular-with-overrides.json @@ -0,0 +1,38 @@ +{ + "type": "object", + "properties": { + "order": { + "$ref": "#/definitions/Order", + "description": "My Order" + } + }, + "definitions": { + "Cart": { + "type": "object", + "properties": { + "order": { + "$ref": "#/definitions/Order", + "description": "My Order" + } + } + }, + "Order": { + "type": "object", + "properties": { + "member": { + "$ref": "#/definitions/Member", + "description": "Member" + } + } + }, + "Member": { + "type": "object", + "properties": { + "referredMember": { + "$ref": "#/definitions/Member", + "description": "Member" + } + } + } + } +} diff --git a/src/__tests__/__snapshots__/tree.spec.ts.snap b/src/__tests__/__snapshots__/tree.spec.ts.snap index 2708563..15893f9 100644 --- a/src/__tests__/__snapshots__/tree.spec.ts.snap +++ b/src/__tests__/__snapshots__/tree.spec.ts.snap @@ -1279,6 +1279,36 @@ exports[`SchemaTree output should generate valid tree for references/base.json 1 " `; +exports[`SchemaTree output should generate valid tree for references/circular-with-overrides.json 1`] = ` +"└─ # + ├─ types + │ └─ 0: object + ├─ primaryType: object + └─ children + └─ 0 + └─ #/properties/order + ├─ types + │ └─ 0: object + ├─ primaryType: object + └─ children + └─ 0 + └─ #/properties/order/properties/member + ├─ types + │ └─ 0: object + ├─ primaryType: object + └─ children + └─ 0 + └─ #/properties/order/properties/member/properties/referredMember + ├─ types + │ └─ 0: object + ├─ primaryType: object + └─ children + └─ 0 + └─ #/properties/order/properties/member/properties/referredMember/properties/referredMember + └─ mirrors: #/properties/order/properties/member/properties/referredMember +" +`; + exports[`SchemaTree output should generate valid tree for references/nullish.json 1`] = ` "└─ # ├─ types diff --git a/src/walker/walker.ts b/src/walker/walker.ts index af4e0c0..7989d90 100644 --- a/src/walker/walker.ts +++ b/src/walker/walker.ts @@ -285,6 +285,8 @@ export class Walker extends EventEmitter { return retrieved; } + let initialFragment: ProcessedFragment = fragment; + if ('$ref' in fragment) { if (typeof walkingOptions.maxRefDepth === 'number' && walkingOptions.maxRefDepth < depth) { return [new ReferenceNode(fragment, `max $ref depth limit reached`), fragment]; @@ -297,6 +299,11 @@ export class Walker extends EventEmitter { if (typeof fragment.description === 'string') { newFragment = { ...newFragment }; Object.assign(newFragment, { description: fragment.description }); + } else { + retrieved = this.retrieveFromFragment(newFragment, originalFragment); + if (retrieved) { + return retrieved; + } } fragment = newFragment; @@ -331,7 +338,6 @@ export class Walker extends EventEmitter { } } } - let initialFragment: ProcessedFragment = fragment; if (walkingOptions.mergeAllOf && SchemaCombinerName.AllOf in fragment) { try { if (Array.isArray(fragment.allOf)) {