Fix allOf withing array items (fixes #136)

This commit is contained in:
Roman Hotsiy 2016-11-05 16:08:39 +02:00
parent d1862ecea0
commit efcb811151
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
2 changed files with 9 additions and 5 deletions

View File

@ -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) {

View File

@ -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;
}