fix: do not process oneOf if inherited from parent with discriminator

This commit is contained in:
Roman Hotsiy 2020-01-14 22:53:45 +02:00
parent 27a4af7076
commit 5248415791
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
2 changed files with 11 additions and 2 deletions

View File

@ -296,7 +296,7 @@ export class OpenAPIParser {
* returns map of definition pointer to definition name
* @param $refs array of references to find derived from
*/
findDerived($refs: string[]): Dict<string[]> {
findDerived($refs: string[]): Dict<string[] | string> {
const res: Dict<string[]> = {};
const schemas = (this.spec.components && this.spec.components.schemas) || {};
for (const defName in schemas) {

View File

@ -75,6 +75,7 @@ export class SchemaModel {
this.pointer = schemaOrRef.$ref || pointer || '';
this.rawSchema = parser.deref(schemaOrRef);
this.schema = parser.mergeAllOf(this.rawSchema, this.pointer, isChild);
this.init(parser, isChild);
parser.exitRef(schemaOrRef);
@ -125,6 +126,13 @@ export class SchemaModel {
if (!isChild && getDiscriminator(schema) !== undefined) {
this.initDiscriminator(schema, parser);
return;
} else if (
isChild &&
Array.isArray(schema.oneOf) &&
schema.oneOf.find(s => s.$ref === this.pointer)
) {
// we hit allOf of the schema with the parent discriminator
delete schema.oneOf;
}
if (schema.oneOf !== undefined) {
@ -227,7 +235,7 @@ export class SchemaModel {
continue;
}
const name = JsonPointer.baseName(variant.$ref);
implicitInversedMapping[variant.$ref] = [name];
implicitInversedMapping[variant.$ref] = name;
}
}
@ -239,6 +247,7 @@ export class SchemaModel {
if (Array.isArray(explicitInversedMapping[$ref])) {
explicitInversedMapping[$ref].push(name);
} else {
// overrides implicit mapping here
explicitInversedMapping[$ref] = [name];
}
}