diff --git a/src/services/OpenAPIParser.ts b/src/services/OpenAPIParser.ts index c8a4d5c5..8adbc7ab 100644 --- a/src/services/OpenAPIParser.ts +++ b/src/services/OpenAPIParser.ts @@ -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 { + findDerived($refs: string[]): Dict { const res: Dict = {}; const schemas = (this.spec.components && this.spec.components.schemas) || {}; for (const defName in schemas) { diff --git a/src/services/models/Schema.ts b/src/services/models/Schema.ts index fa3d3ba3..7fb5a8e9 100644 --- a/src/services/models/Schema.ts +++ b/src/services/models/Schema.ts @@ -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]; } }