Skip to content

Commit

Permalink
fix: do not process oneOf if inherited from parent with discriminator
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Jan 14, 2020
1 parent 27a4af7 commit 5248415
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/services/OpenAPIParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 10 additions & 1 deletion src/services/models/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -227,7 +235,7 @@ export class SchemaModel {
continue;
}
const name = JsonPointer.baseName(variant.$ref);
implicitInversedMapping[variant.$ref] = [name];
implicitInversedMapping[variant.$ref] = name;
}
}

Expand All @@ -239,6 +247,7 @@ export class SchemaModel {
if (Array.isArray(explicitInversedMapping[$ref])) {
explicitInversedMapping[$ref].push(name);
} else {
// overrides implicit mapping here
explicitInversedMapping[$ref] = [name];
}
}
Expand Down

0 comments on commit 5248415

Please sign in to comment.