fix: support discriminator with parent type

closes #220
This commit is contained in:
Roman Hotsiy 2017-03-10 00:04:15 +02:00
parent e4f5388076
commit 17fb7bad27
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0

View File

@ -182,6 +182,21 @@ export class SpecManager {
let globalDefs = this._schema.definitions || {};
let res:DescendantInfo[] = [];
// from the spec: When used, the value MUST be the name of this schema or any schema that inherits it.
// but most of people use it as an abstract class so here is workaround to allow using it other way
// check if parent definition name is in the enum of possible values
if (definition.discriminator) {
let prop = definition.properties[definition.discriminator];
if (prop.enum && prop.enum.indexOf(JsonPointer.baseName(defPointer)) > -1) {
res.push({
name: JsonPointer.baseName(defPointer),
$ref: defPointer
});
}
}
let extendedDiscriminatorProp = definition['x-extendedDiscriminator'];
let pointers;
@ -224,7 +239,7 @@ export class SpecManager {
break;
}
}
if (!derivedName) {
if (derivedName == undefined) {
WarningsService.warn(`Incorrect usage of x-extendedDiscriminator at ${defPointer}: `
+ `can't find corresponding enum with single value in definition "${defName}"`);
continue;