Repository: swagger-api/swagger-parser
Pull request #1333 (2020-03-05 01:07:18)

Follow discriminator mappings to resolve subtypes
Fixes issue #970 (only for the case where the discriminator has a mapping
defined).


Patch:
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java
index 8e371d94..fdbeb377 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java
@@ -9,6 +9,7 @@ import io.swagger.v3.oas.models.headers.Header;
 import io.swagger.v3.oas.models.links.Link;
 import io.swagger.v3.oas.models.media.ArraySchema;
 import io.swagger.v3.oas.models.media.ComposedSchema;
+import io.swagger.v3.oas.models.media.Discriminator;
 import io.swagger.v3.oas.models.media.MediaType;
 import io.swagger.v3.oas.models.media.ObjectSchema;
 import io.swagger.v3.oas.models.media.Schema;
@@ -150,6 +151,8 @@ public final class ExternalRefProcessor {
 
             processProperties(subProps,file);
 
+            processDiscriminator(schema.getDiscriminator(),file);
+
             if(schema.getAdditionalProperties() != null && schema.getAdditionalProperties() instanceof Schema){
                 Schema additionalProperty = (Schema) schema.getAdditionalProperties();
                 if (additionalProperty.get$ref() != null) {
@@ -223,6 +226,21 @@ public final class ExternalRefProcessor {
         }
     }
 
+    private void processDiscriminator(Discriminator d, String file) {
+        if (d != null && d.getMapping() != null) {
+            processDiscriminatorMapping(d.getMapping(), file);
+        }
+    }
+
+    private void processDiscriminatorMapping(Map<String, String> mapping, String file) {
+        for (String key : mapping.keySet()) {
+            String ref = mapping.get(key);
+            Schema subtype = new Schema().$ref(ref);
+            processSchema(subtype, file);
+            mapping.put(key, subtype.get$ref());
+        }
+    }
+
     public String processRefToExternalResponse(String $ref, RefFormat refFormat) {
         String renamedRef = cache.getRenamedRef($ref);
         if(renamedRef != null) {
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/SchemaProcessor.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/SchemaProcessor.java
index de489644..acd1b408 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/SchemaProcessor.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/SchemaProcessor.java
@@ -61,7 +61,19 @@ public class SchemaProcessor {
             processAdditionalProperties(schema);
             
         }
+        if (schema.getDiscriminator() != null) {
+            processDiscriminatorSchema(schema);
+        }
+
+    }
 
+    private void processDiscriminatorSchema(Schema schema) {
+        if (schema.getDiscriminator() != null && schema.getDiscriminator().getMapping() != null) {
+            Map<String, String> mapping = schema.getDiscriminator().getMapping();
+            for (String ref : mapping.values()) {
+                processReferenceSchema(new Schema().$ref(ref));
+            }
+        }
     }
 
     private void processAdditionalProperties(Object additionalProperties) {


Test patch:
diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java
index 888b93a4..48963289 100644
--- a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java
+++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java
@@ -2325,4 +2325,69 @@ public class OpenAPIV3ParserTest {
     private static int getDynamicPort() {
         return new Random().ints(10000, 20000).findFirst().getAsInt();
     }
+
+    @Test
+    public void testDiscriminatorSingleFileNoMapping() throws Exception {
+        OpenAPI openAPI = new OpenAPIV3Parser().read("./discriminator-mapping-resolution/single-file-no-mapping.yaml");
+        Assert.assertNotNull(openAPI);
+        Schema cat = openAPI.getComponents().getSchemas().get("Cat");
+        Assert.assertNotNull(cat);
+    }
+
+    @Test
+    public void testDiscriminatorSeparateFileNoMapping() throws Exception {
+        OpenAPI openAPI = new OpenAPIV3Parser().read("./discriminator-mapping-resolution/main-no-mapping.yaml");
+        Assert.assertNotNull(openAPI);
+        Schema cat = openAPI.getComponents().getSchemas().get("Cat");
+        Assert.assertNull(cat); // FIXME, issue #970 still exists in this form
+    }
+
+    @Test
+    public void testDiscriminatorSingleFilePlainMapping() throws Exception {
+        OpenAPI openAPI = new OpenAPIV3Parser().read("./discriminator-mapping-resolution/single-file-plain-mapping.yaml");
+        Assert.assertNotNull(openAPI);
+        Schema cat = openAPI.getComponents().getSchemas().get("Cat");
+        Assert.assertNotNull(cat);
+    }
+
+    @Test
+    public void testDiscriminatorSeparateFilePlainMapping() throws Exception {
+        OpenAPI openAPI = new OpenAPIV3Parser().read("./discriminator-mapping-resolution/main-plain-mapping.yaml");
+        Assert.assertNotNull(openAPI);
+        Schema cat = openAPI.getComponents().getSchemas().get("Cat");
+        Assert.assertNotNull(cat);
+    }
+
+    @Test
+    public void testDiscriminatorSingleFileInternalMapping() throws Exception {
+        OpenAPI openAPI = new OpenAPIV3Parser().read("./discriminator-mapping-resolution/single-file-internal-mapping.yaml");
+        Assert.assertNotNull(openAPI);
+        Schema cat = openAPI.getComponents().getSchemas().get("Cat");
+        Assert.assertNotNull(cat);
+    }
+
+    @Test
+    public void testDiscriminatorSeparateFileInternalMapping() throws Exception {
+        OpenAPI openAPI = new OpenAPIV3Parser().read("./discriminator-mapping-resolution/main-internal-mapping.yaml");
+        Assert.assertNotNull(openAPI);
+        Schema cat = openAPI.getComponents().getSchemas().get("Cat");
+        Assert.assertNotNull(cat);
+    }
+
+    @Test
+    public void testDiscriminatorSameFileExternalMapping() throws Exception {
+        OpenAPI openAPI = new OpenAPIV3Parser().read("./discriminator-mapping-resolution/main-external-mapping.yaml");
+        Assert.assertNotNull(openAPI);
+        Schema cat = openAPI.getComponents().getSchemas().get("Cat");
+        Assert.assertNotNull(cat);
+    }
+
+    @Test
+    public void testDiscriminatorSeparateFileExternalMapping() throws Exception {
+        OpenAPI openAPI = new OpenAPIV3Parser().read("./discriminator-mapping-resolution/main-external-mapping-3files.yaml");
+        Assert.assertNotNull(openAPI);
+        Schema cat = openAPI.getComponents().getSchemas().get("Cat");
+        Assert.assertNotNull(cat);
+    }
+
 }
diff --git a/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/Cat.yaml b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/Cat.yaml
new file mode 100644
index 00000000..dba16a63
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/Cat.yaml
@@ -0,0 +1,8 @@
+    Cat:
+      allOf:
+      - $ref: '#/components/schemas/Pet'
+      # all other properties specific to a `Cat`
+      type: object
+      properties:
+        name:
+          type: string
diff --git a/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/Dog.yaml b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/Dog.yaml
new file mode 100644
index 00000000..32dd0817
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/Dog.yaml
@@ -0,0 +1,8 @@
+    Dog:
+      allOf:
+      - $ref: '#/components/schemas/Pet'
+      # all other properties specific to a `Dog`
+      type: object
+      properties:
+        bark:
+          type: string
diff --git a/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/main-external-mapping-3files.yaml b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/main-external-mapping-3files.yaml
new file mode 100644
index 00000000..1cf1003d
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/main-external-mapping-3files.yaml
@@ -0,0 +1,54 @@
+openapi: 3.0.0
+servers:
+  - url: 'http://petstore.swagger.io/v2'
+info:
+  description: >-
+    This is a sample server Petstore server.  You can find out more about
+    Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net,
+    #swagger](http://swagger.io/irc/).  For this sample, you can use the api key
+    `special-key` to test the authorization filters.
+  version: 1.0.0
+  title: Swagger Petstore
+  termsOfService: 'http://swagger.io/terms/'
+  contact:
+    email: apiteam@swagger.io
+  license:
+    name: Apache 2.0
+    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
+paths:
+  /pet/findByStatus:
+    get:
+      tags:
+        - pet
+      summary: Finds Pets by status
+      description: Multiple status values can be provided with comma separated strings
+      operationId: findPetsByStatus
+      parameters:
+        - name: status
+          in: query
+          description: Status values that need to be considered for filter
+          required: true
+          explode: true
+          schema:
+            type: array
+            items:
+              type: string
+              enum:
+                - available
+                - pending
+                - sold
+              default: available
+      responses:
+        '200':
+          description: successful operation
+          content:
+            application/json:
+              schema:
+                type: object
+                properties:
+                  pets:
+                    type: array
+                    items:
+                      $ref: 'parent-external-mapping.yaml#/components/schemas/Pet'
+        '400':
+          description: Invalid status value
diff --git a/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/main-external-mapping.yaml b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/main-external-mapping.yaml
new file mode 100644
index 00000000..701a3fca
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/main-external-mapping.yaml
@@ -0,0 +1,68 @@
+openapi: 3.0.0
+servers:
+  - url: 'http://petstore.swagger.io/v2'
+info:
+  description: >-
+    This is a sample server Petstore server.  You can find out more about
+    Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net,
+    #swagger](http://swagger.io/irc/).  For this sample, you can use the api key
+    `special-key` to test the authorization filters.
+  version: 1.0.0
+  title: Swagger Petstore
+  termsOfService: 'http://swagger.io/terms/'
+  contact:
+    email: apiteam@swagger.io
+  license:
+    name: Apache 2.0
+    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
+paths:
+  /pet/findByStatus:
+    get:
+      tags:
+        - pet
+      summary: Finds Pets by status
+      description: Multiple status values can be provided with comma separated strings
+      operationId: findPetsByStatus
+      parameters:
+        - name: status
+          in: query
+          description: Status values that need to be considered for filter
+          required: true
+          explode: true
+          schema:
+            type: array
+            items:
+              type: string
+              enum:
+                - available
+                - pending
+                - sold
+              default: available
+      responses:
+        '200':
+          description: successful operation
+          content:
+            application/json:
+              schema:
+                type: object
+                properties:
+                  pets:
+                    type: array
+                    items:
+                      $ref: '#/components/schemas/Pet'
+        '400':
+          description: Invalid status value
+components:
+  schemas:
+    Pet:
+      type: object
+      required:
+      - pet_type
+      properties:
+        pet_type:
+          type: string
+      discriminator:
+        propertyName: pet_type
+        mapping:
+          Cat: 'Cat.yaml'
+          Dog: 'Dog.yaml'
diff --git a/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/main-internal-mapping.yaml b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/main-internal-mapping.yaml
new file mode 100644
index 00000000..abdfa752
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/main-internal-mapping.yaml
@@ -0,0 +1,54 @@
+openapi: 3.0.0
+servers:
+  - url: 'http://petstore.swagger.io/v2'
+info:
+  description: >-
+    This is a sample server Petstore server.  You can find out more about
+    Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net,
+    #swagger](http://swagger.io/irc/).  For this sample, you can use the api key
+    `special-key` to test the authorization filters.
+  version: 1.0.0
+  title: Swagger Petstore
+  termsOfService: 'http://swagger.io/terms/'
+  contact:
+    email: apiteam@swagger.io
+  license:
+    name: Apache 2.0
+    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
+paths:
+  /pet/findByStatus:
+    get:
+      tags:
+        - pet
+      summary: Finds Pets by status
+      description: Multiple status values can be provided with comma separated strings
+      operationId: findPetsByStatus
+      parameters:
+        - name: status
+          in: query
+          description: Status values that need to be considered for filter
+          required: true
+          explode: true
+          schema:
+            type: array
+            items:
+              type: string
+              enum:
+                - available
+                - pending
+                - sold
+              default: available
+      responses:
+        '200':
+          description: successful operation
+          content:
+            application/json:
+              schema:
+                type: object
+                properties:
+                  pets:
+                    type: array
+                    items:
+                      $ref: 'pet-internal-mapping.yaml#/components/schemas/Pet'
+        '400':
+          description: Invalid status value
diff --git a/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/main-no-mapping-oneof.yaml b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/main-no-mapping-oneof.yaml
new file mode 100644
index 00000000..a227f322
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/main-no-mapping-oneof.yaml
@@ -0,0 +1,54 @@
+openapi: 3.0.0
+servers:
+  - url: 'http://petstore.swagger.io/v2'
+info:
+  description: >-
+    This is a sample server Petstore server.  You can find out more about
+    Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net,
+    #swagger](http://swagger.io/irc/).  For this sample, you can use the api key
+    `special-key` to test the authorization filters.
+  version: 1.0.0
+  title: Swagger Petstore
+  termsOfService: 'http://swagger.io/terms/'
+  contact:
+    email: apiteam@swagger.io
+  license:
+    name: Apache 2.0
+    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
+paths:
+  /pet/findByStatus:
+    get:
+      tags:
+        - pet
+      summary: Finds Pets by status
+      description: Multiple status values can be provided with comma separated strings
+      operationId: findPetsByStatus
+      parameters:
+        - name: status
+          in: query
+          description: Status values that need to be considered for filter
+          required: true
+          explode: true
+          schema:
+            type: array
+            items:
+              type: string
+              enum:
+                - available
+                - pending
+                - sold
+              default: available
+      responses:
+        '200':
+          description: successful operation
+          content:
+            application/json:
+              schema:
+                type: object
+                properties:
+                  pets:
+                    type: array
+                    items:
+                      $ref: 'pet-no-mapping-oneof.yaml#/components/schemas/Pet'
+        '400':
+          description: Invalid status value
diff --git a/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/main-no-mapping.yaml b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/main-no-mapping.yaml
new file mode 100644
index 00000000..17e11ef6
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/main-no-mapping.yaml
@@ -0,0 +1,54 @@
+openapi: 3.0.0
+servers:
+  - url: 'http://petstore.swagger.io/v2'
+info:
+  description: >-
+    This is a sample server Petstore server.  You can find out more about
+    Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net,
+    #swagger](http://swagger.io/irc/).  For this sample, you can use the api key
+    `special-key` to test the authorization filters.
+  version: 1.0.0
+  title: Swagger Petstore
+  termsOfService: 'http://swagger.io/terms/'
+  contact:
+    email: apiteam@swagger.io
+  license:
+    name: Apache 2.0
+    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
+paths:
+  /pet/findByStatus:
+    get:
+      tags:
+        - pet
+      summary: Finds Pets by status
+      description: Multiple status values can be provided with comma separated strings
+      operationId: findPetsByStatus
+      parameters:
+        - name: status
+          in: query
+          description: Status values that need to be considered for filter
+          required: true
+          explode: true
+          schema:
+            type: array
+            items:
+              type: string
+              enum:
+                - available
+                - pending
+                - sold
+              default: available
+      responses:
+        '200':
+          description: successful operation
+          content:
+            application/json:
+              schema:
+                type: object
+                properties:
+                  pets:
+                    type: array
+                    items:
+                      $ref: 'pet-no-mapping.yaml#/components/schemas/Pet'
+        '400':
+          description: Invalid status value
diff --git a/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/main-plain-mapping.yaml b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/main-plain-mapping.yaml
new file mode 100644
index 00000000..2ef24df9
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/main-plain-mapping.yaml
@@ -0,0 +1,54 @@
+openapi: 3.0.0
+servers:
+  - url: 'http://petstore.swagger.io/v2'
+info:
+  description: >-
+    This is a sample server Petstore server.  You can find out more about
+    Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net,
+    #swagger](http://swagger.io/irc/).  For this sample, you can use the api key
+    `special-key` to test the authorization filters.
+  version: 1.0.0
+  title: Swagger Petstore
+  termsOfService: 'http://swagger.io/terms/'
+  contact:
+    email: apiteam@swagger.io
+  license:
+    name: Apache 2.0
+    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
+paths:
+  /pet/findByStatus:
+    get:
+      tags:
+        - pet
+      summary: Finds Pets by status
+      description: Multiple status values can be provided with comma separated strings
+      operationId: findPetsByStatus
+      parameters:
+        - name: status
+          in: query
+          description: Status values that need to be considered for filter
+          required: true
+          explode: true
+          schema:
+            type: array
+            items:
+              type: string
+              enum:
+                - available
+                - pending
+                - sold
+              default: available
+      responses:
+        '200':
+          description: successful operation
+          content:
+            application/json:
+              schema:
+                type: object
+                properties:
+                  pets:
+                    type: array
+                    items:
+                      $ref: 'pet-plain-mapping.yaml#/components/schemas/Pet'
+        '400':
+          description: Invalid status value
diff --git a/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/parent-external-mapping.yaml b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/parent-external-mapping.yaml
new file mode 100644
index 00000000..572289e0
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/parent-external-mapping.yaml
@@ -0,0 +1,14 @@
+components:
+  schemas:
+    Pet:
+      type: object
+      required:
+      - pet_type
+      properties:
+        pet_type:
+          type: string
+      discriminator:
+        propertyName: pet_type
+        mapping:
+          Cat: 'Cat.yaml'
+          Dog: 'Dog.yaml'
diff --git a/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/pet-internal-mapping.yaml b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/pet-internal-mapping.yaml
new file mode 100644
index 00000000..ccd9f0e0
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/pet-internal-mapping.yaml
@@ -0,0 +1,30 @@
+components:
+  schemas:
+    Pet:
+      type: object
+      required:
+      - pet_type
+      properties:
+        pet_type:
+          type: string
+      discriminator:
+        propertyName: pet_type
+        mapping:
+          Cat: '#/components/schemas/Cat'
+          Dog: '#/components/schemas/Dog'
+    Cat:
+      allOf:
+      - $ref: '#/components/schemas/Pet'
+      # all other properties specific to a `Cat`
+      type: object
+      properties:
+        name:
+          type: string
+    Dog:
+      allOf:
+      - $ref: '#/components/schemas/Pet'
+      # all other properties specific to a `Dog`
+      type: object
+      properties:
+        bark:
+          type: string
diff --git a/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/pet-no-mapping-oneof.yaml b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/pet-no-mapping-oneof.yaml
new file mode 100644
index 00000000..098bf9af
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/pet-no-mapping-oneof.yaml
@@ -0,0 +1,30 @@
+components:
+  schemas:
+    Pet:
+      type: object
+      required:
+      - pet_type
+      properties:
+        pet_type:
+          type: string
+      oneOf:
+      - $ref: '#/components/schemas/Cat'
+      - $ref: '#/components/schemas/Dog'
+      discriminator:
+        propertyName: pet_type
+    Cat:
+      allOf:
+      - $ref: '#/components/schemas/Pet'
+      # all other properties specific to a `Cat`
+      type: object
+      properties:
+        name:
+          type: string
+    Dog:
+      allOf:
+      - $ref: '#/components/schemas/Pet'
+      # all other properties specific to a `Dog`
+      type: object
+      properties:
+        bark:
+          type: string
diff --git a/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/pet-no-mapping.yaml b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/pet-no-mapping.yaml
new file mode 100644
index 00000000..9190e539
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/pet-no-mapping.yaml
@@ -0,0 +1,27 @@
+components:
+  schemas:
+    Pet:
+      type: object
+      required:
+      - pet_type
+      properties:
+        pet_type:
+          type: string
+      discriminator:
+        propertyName: pet_type
+    Cat:
+      allOf:
+      - $ref: '#/components/schemas/Pet'
+      # all other properties specific to a `Cat`
+      type: object
+      properties:
+        name:
+          type: string
+    Dog:
+      allOf:
+      - $ref: '#/components/schemas/Pet'
+      # all other properties specific to a `Dog`
+      type: object
+      properties:
+        bark:
+          type: string
diff --git a/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/pet-plain-mapping.yaml b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/pet-plain-mapping.yaml
new file mode 100644
index 00000000..d20c66a4
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/pet-plain-mapping.yaml
@@ -0,0 +1,30 @@
+components:
+  schemas:
+    Pet:
+      type: object
+      required:
+      - pet_type
+      properties:
+        pet_type:
+          type: string
+      discriminator:
+        propertyName: pet_type
+        mapping:
+          Cat: Cat
+          Dog: Dog
+    Cat:
+      allOf:
+      - $ref: '#/components/schemas/Pet'
+      # all other properties specific to a `Cat`
+      type: object
+      properties:
+        name:
+          type: string
+    Dog:
+      allOf:
+      - $ref: '#/components/schemas/Pet'
+      # all other properties specific to a `Dog`
+      type: object
+      properties:
+        bark:
+          type: string
diff --git a/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/single-file-internal-mapping.yaml b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/single-file-internal-mapping.yaml
new file mode 100644
index 00000000..ea9097dd
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/single-file-internal-mapping.yaml
@@ -0,0 +1,84 @@
+openapi: 3.0.0
+servers:
+  - url: 'http://petstore.swagger.io/v2'
+info:
+  description: >-
+    This is a sample server Petstore server.  You can find out more about
+    Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net,
+    #swagger](http://swagger.io/irc/).  For this sample, you can use the api key
+    `special-key` to test the authorization filters.
+  version: 1.0.0
+  title: Swagger Petstore
+  termsOfService: 'http://swagger.io/terms/'
+  contact:
+    email: apiteam@swagger.io
+  license:
+    name: Apache 2.0
+    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
+paths:
+  /pet/findByStatus:
+    get:
+      tags:
+        - pet
+      summary: Finds Pets by status
+      description: Multiple status values can be provided with comma separated strings
+      operationId: findPetsByStatus
+      parameters:
+        - name: status
+          in: query
+          description: Status values that need to be considered for filter
+          required: true
+          explode: true
+          schema:
+            type: array
+            items:
+              type: string
+              enum:
+                - available
+                - pending
+                - sold
+              default: available
+      responses:
+        '200':
+          description: successful operation
+          content:
+            application/json:
+              schema:
+                type: object
+                properties:
+                  pets:
+                    type: array
+                    items:
+                      $ref: '#/components/schemas/Pet'
+        '400':
+          description: Invalid status value
+components:
+  schemas:
+    Pet:
+      type: object
+      required:
+      - pet_type
+      properties:
+        pet_type:
+          type: string
+      discriminator:
+        propertyName: pet_type
+        mapping:
+          Cat: '#/components/schemas/Cat'
+          Dog: '#/components/schemas/Dog'
+    Cat:
+      allOf:
+      - $ref: '#/components/schemas/Pet'
+      # all other properties specific to a `Cat`
+      type: object
+      properties:
+        name:
+          type: string
+    Dog:
+      allOf:
+      - $ref: '#/components/schemas/Pet'
+      # all other properties specific to a `Dog`
+      type: object
+      properties:
+        bark:
+          type: string
diff --git a/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/single-file-no-mapping.yaml b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/single-file-no-mapping.yaml
new file mode 100644
index 00000000..014d7e98
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/single-file-no-mapping.yaml
@@ -0,0 +1,81 @@
+openapi: 3.0.0
+servers:
+  - url: 'http://petstore.swagger.io/v2'
+info:
+  description: >-
+    This is a sample server Petstore server.  You can find out more about
+    Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net,
+    #swagger](http://swagger.io/irc/).  For this sample, you can use the api key
+    `special-key` to test the authorization filters.
+  version: 1.0.0
+  title: Swagger Petstore
+  termsOfService: 'http://swagger.io/terms/'
+  contact:
+    email: apiteam@swagger.io
+  license:
+    name: Apache 2.0
+    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
+paths:
+  /pet/findByStatus:
+    get:
+      tags:
+        - pet
+      summary: Finds Pets by status
+      description: Multiple status values can be provided with comma separated strings
+      operationId: findPetsByStatus
+      parameters:
+        - name: status
+          in: query
+          description: Status values that need to be considered for filter
+          required: true
+          explode: true
+          schema:
+            type: array
+            items:
+              type: string
+              enum:
+                - available
+                - pending
+                - sold
+              default: available
+      responses:
+        '200':
+          description: successful operation
+          content:
+            application/json:
+              schema:
+                type: object
+                properties:
+                  pets:
+                    type: array
+                    items:
+                      $ref: '#/components/schemas/Pet'
+        '400':
+          description: Invalid status value
+components:
+  schemas:
+    Pet:
+      type: object
+      required:
+      - pet_type
+      properties:
+        pet_type:
+          type: string
+      discriminator:
+        propertyName: pet_type
+    Cat:
+      allOf:
+      - $ref: '#/components/schemas/Pet'
+      # all other properties specific to a `Cat`
+      type: object
+      properties:
+        name:
+          type: string
+    Dog:
+      allOf:
+      - $ref: '#/components/schemas/Pet'
+      # all other properties specific to a `Dog`
+      type: object
+      properties:
+        bark:
+          type: string
diff --git a/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/single-file-plain-mapping.yaml b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/single-file-plain-mapping.yaml
new file mode 100644
index 00000000..d1a484c1
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/discriminator-mapping-resolution/single-file-plain-mapping.yaml
@@ -0,0 +1,84 @@
+openapi: 3.0.0
+servers:
+  - url: 'http://petstore.swagger.io/v2'
+info:
+  description: >-
+    This is a sample server Petstore server.  You can find out more about
+    Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net,
+    #swagger](http://swagger.io/irc/).  For this sample, you can use the api key
+    `special-key` to test the authorization filters.
+  version: 1.0.0
+  title: Swagger Petstore
+  termsOfService: 'http://swagger.io/terms/'
+  contact:
+    email: apiteam@swagger.io
+  license:
+    name: Apache 2.0
+    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
+paths:
+  /pet/findByStatus:
+    get:
+      tags:
+        - pet
+      summary: Finds Pets by status
+      description: Multiple status values can be provided with comma separated strings
+      operationId: findPetsByStatus
+      parameters:
+        - name: status
+          in: query
+          description: Status values that need to be considered for filter
+          required: true
+          explode: true
+          schema:
+            type: array
+            items:
+              type: string
+              enum:
+                - available
+                - pending
+                - sold
+              default: available
+      responses:
+        '200':
+          description: successful operation
+          content:
+            application/json:
+              schema:
+                type: object
+                properties:
+                  pets:
+                    type: array
+                    items:
+                      $ref: '#/components/schemas/Pet'
+        '400':
+          description: Invalid status value
+components:
+  schemas:
+    Pet:
+      type: object
+      required:
+      - pet_type
+      properties:
+        pet_type:
+          type: string
+      discriminator:
+        propertyName: pet_type
+        mapping:
+          Cat: Cat
+          Dog: Dog
+    Cat:
+      allOf:
+      - $ref: '#/components/schemas/Pet'
+      # all other properties specific to a `Cat`
+      type: object
+      properties:
+        name:
+          type: string
+    Dog:
+      allOf:
+      - $ref: '#/components/schemas/Pet'
+      # all other properties specific to a `Dog`
+      type: object
+      properties:
+        bark:
+          type: string