From efcb811151ee7fc0102c38fa98cc0edffebfa1f9 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Sat, 5 Nov 2016 16:08:39 +0200 Subject: [PATCH] Fix allOf withing array items (fixes #136) --- lib/components/SchemaSample/schema-sample.ts | 5 +++-- lib/services/schema-normalizer.service.ts | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/components/SchemaSample/schema-sample.ts b/lib/components/SchemaSample/schema-sample.ts index 74e77366..70de0887 100644 --- a/lib/components/SchemaSample/schema-sample.ts +++ b/lib/components/SchemaSample/schema-sample.ts @@ -35,10 +35,11 @@ export class SchemaSample extends BaseComponent implements OnInit { let base:any = {}; let sample; - // got pointer not directly to the schema but e.g. to response obj + // got pointer not directly to the schema but e.g. to the response obj if (this.componentSchema.schema) { base = this.componentSchema; this.componentSchema = this.componentSchema.schema; + this.pointer += '/schema'; } if (base.examples && base.examples['application/json']) { @@ -48,7 +49,7 @@ export class SchemaSample extends BaseComponent implements OnInit { this.componentSchema = this._normalizer.normalize(this.componentSchema, this.pointer); - let discriminator = this.componentSchema.discriminator || this.componentSchema['x-extendedDiscriminator']; + let discriminator = this.componentSchema.discriminator || this.componentSchema['x-discriminatorBasePointer']; if (discriminator) { let descendants = this.specMgr.findDerivedDefinitions(this.componentSchema._pointer || this.pointer); if (descendants.length) { diff --git a/lib/services/schema-normalizer.service.ts b/lib/services/schema-normalizer.service.ts index d4041f1d..ad127c1e 100644 --- a/lib/services/schema-normalizer.service.ts +++ b/lib/services/schema-normalizer.service.ts @@ -27,8 +27,11 @@ export class SchemaNormalizer { 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) => { + if (schema['x-redoc-normalized']) { + if (!schema['x-redoc-normalized']._pointer) schema['x-redoc-normalized']._pointer = ptr; + return schema['x-redoc-normalized']; + } + let res = SchemaWalker.walk(Object.assign({}, schema), ptr, (subSchema, ptr) => { let resolved = this._dereferencer.dereference(subSchema, ptr); if (resolved.allOf) { resolved._pointer = resolved._pointer || ptr; @@ -38,7 +41,7 @@ export class SchemaNormalizer { return resolved; }); if (opts.resolved && !hasPtr) this._dereferencer.exit(ptr); - res['x-redoc-normalized'] = true; + schema['x-redoc-normalized'] = res; return res; }