Skip to content

Commit

Permalink
fix: optimize and support inherited discriminator
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Mar 9, 2017
1 parent 193f4bf commit 64e5741
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/utils/spec-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,28 @@ 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 &&
!def['x-derived-from']) continue;
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) {
Expand Down

0 comments on commit 64e5741

Please sign in to comment.