From 52484157912d908daea8255d0b7d684b33258d7a Mon Sep 17 00:00:00 2001
From: Roman Hotsiy <gotsijroman@gmail.com>
Date: Tue, 14 Jan 2020 22:53:45 +0200
Subject: [PATCH] fix: do not process oneOf if inherited from parent with
 discriminator

---
 src/services/OpenAPIParser.ts |  2 +-
 src/services/models/Schema.ts | 11 ++++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/services/OpenAPIParser.ts b/src/services/OpenAPIParser.ts
index c8a4d5c51b..8adbc7abe4 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<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) {
diff --git a/src/services/models/Schema.ts b/src/services/models/Schema.ts
index fa3d3ba326..7fb5a8e95e 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];
       }
     }