fix: optimize and support inherited discriminator

This commit is contained in:
Roman Hotsiy 2017-03-09 19:59:49 +02:00
parent 193f4bfb44
commit 64e5741f67
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0

View File

@ -183,6 +183,21 @@ export class SpecManager {
let globalDefs = this._schema.definitions || {};
let res:DescendantInfo[] = [];
let extendedDiscriminatorProp = definition['x-extendedDiscriminator'];
let pointers;
if (definition['x-derived-from']) {
// support inherited discriminator o_O
let derivedDiscriminator = definition['x-derived-from'].filter(ptr => {
if (!ptr) return false;
let def = this.byPointer(ptr);
return def && def.discriminator;
});
pointers = [defPointer, ...derivedDiscriminator];
} else {
pointers = [defPointer];
}
for (let defName of Object.keys(globalDefs)) {
let def = globalDefs[defName];
if (!def.allOf &&
@ -190,12 +205,6 @@ export class SpecManager {
let subTypes = def['x-derived-from'] ||
def.allOf.map(subType => subType._pointer || subType.$ref);
let pointers;
if (definition['x-derived-from']) {
pointers = [defPointer, ...definition['x-derived-from']];
} else {
pointers = [defPointer];
}
let idx = -1;
for (let ptr of pointers) {