Fix dereference issue caused by invalid circular refs checking

This commit is contained in:
Roman Hotsiy 2016-01-23 17:50:36 +02:00
parent d805cba782
commit 4c4e0a17ed

View File

@ -104,7 +104,9 @@ export class BaseComponent {
let dereferencedCache = {}; let dereferencedCache = {};
let resolve = (schema) => { let resolve = (schema) => {
let resolvedRef;
if (schema && schema.$ref) { if (schema && schema.$ref) {
resolvedRef = schema.$ref;
let resolved = this.schemaMgr.byPointer(schema.$ref); let resolved = this.schemaMgr.byPointer(schema.$ref);
let baseName = JsonPointer.baseName(schema.$ref); let baseName = JsonPointer.baseName(schema.$ref);
if (!dereferencedCache[schema.$ref]) { if (!dereferencedCache[schema.$ref]) {
@ -114,11 +116,12 @@ export class BaseComponent {
} else { } else {
// for circular referenced save only title and type // for circular referenced save only title and type
resolved = { resolved = {
title: resolved.title title: resolved.title,
type: resolved.type
}; };
} }
dereferencedCache[schema.$ref] = true; dereferencedCache[schema.$ref] = dereferencedCache[schema.$ref] ? dereferencedCache[schema.$ref] + 1 : 1;
resolved.title = resolved.title || baseName; resolved.title = resolved.title || baseName;
@ -133,7 +136,6 @@ export class BaseComponent {
schema = schema.description ? { schema = schema.description ? {
description: schema.description description: schema.description
} : {}; } : {};
//for (var prop in schema) delete schema[prop];
Object.assign(schema, resolved); Object.assign(schema, resolved);
} }
@ -143,10 +145,11 @@ export class BaseComponent {
schema[key] = resolve(value); schema[key] = resolve(value);
} }
}); });
if (resolvedRef) dereferencedCache[resolvedRef] = dereferencedCache[resolvedRef] ? dereferencedCache[resolvedRef] - 1 : 0;
return schema; return schema;
}; };
this.componentSchema = resolve(schema); this.componentSchema = resolve(schema, 1);
} }
joinAllOf(schema = this.componentSchema, opts) { joinAllOf(schema = this.componentSchema, opts) {