diff --git a/lib/components/JsonSchema/json-schema-lazy.ts b/lib/components/JsonSchema/json-schema-lazy.ts index edbea22f..80dc3f63 100644 --- a/lib/components/JsonSchema/json-schema-lazy.ts +++ b/lib/components/JsonSchema/json-schema-lazy.ts @@ -46,7 +46,7 @@ export class JsonSchemaLazy implements OnDestroy, AfterViewInit { } load() { - if (this.optionsService.options.disableLazySchemas) return; + if (this.disableLazy) return; if (this.loaded) return; if (this.pointer) { this._loadAfterSelf(); diff --git a/lib/components/JsonSchema/json-schema.ts b/lib/components/JsonSchema/json-schema.ts index 3bb1c3c6..6cc6642d 100644 --- a/lib/components/JsonSchema/json-schema.ts +++ b/lib/components/JsonSchema/json-schema.ts @@ -47,7 +47,8 @@ export class JsonSchema extends BaseComponent implements OnInit { this.pointer = activeDescendant.$ref; this.schema = this.specMgr.byPointer(this.pointer); - this.schema = this.normalizer.normalize(this.schema, this.normPointer, {omitParent: false}); + this.schema = this.normalizer.normalize(this.schema, this.normPointer, + {resolved: true}); this.preprocessSchema(); } @@ -80,7 +81,7 @@ export class JsonSchema extends BaseComponent implements OnInit { this.applyStyling(); - this.schema = this.normalizer.normalize(this.schema, this.normPointer); + this.schema = this.normalizer.normalize(this.schema, this.normPointer, {resolved: true}); this.schema = SchemaHelper.unwrapArray(this.schema, this.normPointer); this.initDescendants(); this.preprocessSchema(); diff --git a/lib/components/ParamsList/params-list.html b/lib/components/ParamsList/params-list.html index 6601e4dc..89211a1b 100644 --- a/lib/components/ParamsList/params-list.html +++ b/lib/components/ParamsList/params-list.html @@ -33,7 +33,7 @@

- +
diff --git a/lib/components/ParamsList/params-list.ts b/lib/components/ParamsList/params-list.ts index d21e2661..3bf40dcf 100644 --- a/lib/components/ParamsList/params-list.ts +++ b/lib/components/ParamsList/params-list.ts @@ -40,7 +40,6 @@ export class ParamsList extends BaseComponent implements OnInit { if (paramsMap.body && paramsMap.body.length) { let bodyParam = paramsMap.body[0]; - bodyParam.pointer = bodyParam._pointer; this.bodyParam = bodyParam; paramsMap.body = undefined; } diff --git a/lib/services/schema-normalizer.service.ts b/lib/services/schema-normalizer.service.ts index 73a2d4f9..8b1de77a 100644 --- a/lib/services/schema-normalizer.service.ts +++ b/lib/services/schema-normalizer.service.ts @@ -24,17 +24,20 @@ export class SchemaNormalizer { this._dereferencer = new SchemaDereferencer(_schema, this); } normalize(schema, ptr, opts:any ={}) { - opts.omitParent = opts.omitParent !== false; + let hasPtr = !!schema.$ref; + if (opts.resolved && !hasPtr) this._dereferencer.visit(ptr); + if (schema['x-redoc-normalized']) return schema; let res = SchemaWalker.walk(schema, ptr, (subSchema, ptr) => { let resolved = this._dereferencer.dereference(subSchema, ptr); if (resolved.allOf) { resolved._pointer = resolved._pointer || ptr; resolved = Object.assign({}, resolved); - AllOfMerger.merge(resolved, resolved.allOf, {omitParent: opts.omitParent}); + AllOfMerger.merge(resolved, resolved.allOf); } return resolved; }); + if (opts.resolved && !hasPtr) this._dereferencer.exit(ptr); res['x-redoc-normalized'] = true; return res; } @@ -88,12 +91,11 @@ class SchemaWalker { } class AllOfMerger { - static merge(into, schemas, opts) { + static merge(into, schemas) { into['x-derived-from'] = []; for (let i=0; i < schemas.length; i++) { let subSchema = schemas[i]; into['x-derived-from'].push(subSchema._pointer); - if (opts && opts.omitParent && subSchema.discriminator) continue; AllOfMerger.checkCanMerge(subSchema, into); @@ -177,6 +179,14 @@ class SchemaDereferencer { constructor(private _spec: SpecManager, private normalizator: SchemaNormalizer) { } + visit($ref) { + this._refCouner.visit($ref); + } + + exit($ref) { + this._refCouner.exit($ref); + } + dereference(schema: Reference, pointer:string):any { if (!schema || !schema.$ref) return schema; window['derefCount'] = window['derefCount'] ? window['derefCount'] + 1 : 1; diff --git a/tests/e2e/redoc.e2e.js b/tests/e2e/redoc.e2e.js index eaf250e3..01c5e940 100644 --- a/tests/e2e/redoc.e2e.js +++ b/tests/e2e/redoc.e2e.js @@ -91,7 +91,6 @@ if (process.env.JOB === 'e2e-guru') { delete apisGuruList['googleapis.com:mirror']; // bad urls in images delete apisGuruList['googleapis.com:discovery']; // non-string references delete apisGuruList['clarify.io']; // non-string references - delete apisGuruList['clickmeter.com']; // some complex circular reference //delete apisGuruList['pushpay.com']; // https://github.com/Rebilly/ReDoc/issues/30 delete apisGuruList['bbci.co.uk']; // too big