Repository: swagger-api/swagger-parser
Pull request #1124 (2019-06-13 17:29:53)

Fix for fully resoling map schema.
See Issue for details.

https://github.com/swagger-api/swagger-parser/issues/1125


Patch:
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java
index fb778295..9aea373d 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java
@@ -11,6 +11,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.MapSchema;
 import io.swagger.v3.oas.models.media.MediaType;
 import io.swagger.v3.oas.models.media.ObjectSchema;
 import io.swagger.v3.oas.models.media.Schema;
@@ -307,6 +308,15 @@ public class ResolverFully {
 
             return arrayModel;
         }
+
+        if (schema instanceof MapSchema) {
+            MapSchema mapSchema = (MapSchema) schema;
+            if (mapSchema.getAdditionalProperties() instanceof Schema) {
+                Schema additionalPropertiesSchema = (Schema) mapSchema.getAdditionalProperties();
+                mapSchema.setAdditionalProperties(resolveSchema(additionalPropertiesSchema));
+            }
+        }
+
         if (schema instanceof ObjectSchema) {
             ObjectSchema obj = (ObjectSchema) schema;
             if(obj.getProperties() != null) {


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 e4181471..c3779a8e 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
@@ -1931,6 +1931,21 @@ public class OpenAPIV3ParserTest {
 
     }
 
+    @Test
+    public void testResolveFullyMap() {
+        ParseOptions options = new ParseOptions();
+        options.setResolveFully(false);
+        OpenAPI openAPI = new OpenAPIV3Parser().readLocation("resolve-fully-map.yaml", null, options).getOpenAPI();
+        String yaml = Yaml.pretty(openAPI);
+        assertTrue(yaml.contains("$ref"));
+
+        options = new ParseOptions();
+        options.setResolveFully(true);
+        openAPI = new OpenAPIV3Parser().readLocation("resolve-fully-map.yaml", null, options).getOpenAPI();
+        yaml = Yaml.pretty(openAPI);
+        assertFalse(yaml.contains("$ref"));
+    }
+
     private static int getDynamicPort() {
         return new Random().ints(10000, 20000).findFirst().getAsInt();
     }
diff --git a/modules/swagger-parser-v3/src/test/resources/resolve-fully-map.yaml b/modules/swagger-parser-v3/src/test/resources/resolve-fully-map.yaml
new file mode 100644
index 00000000..02ba065c
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/resolve-fully-map.yaml
@@ -0,0 +1,31 @@
+openapi: 3.0.0
+servers:
+  - url: 'http://localhost:8080/sample'
+info:
+  description: A simple API to learn how to write OpenAPI Specification
+  version: 1.0.1
+  title: Simple API
+paths:
+  /sample:
+    get:
+      tags:
+        - Sample
+      operationId: getSample
+      responses:
+        '200':
+          description: Sample
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/MyModelMap'
+components:
+  schemas:
+    MyModel:
+      type: object
+      properties:
+        name:
+          type: string
+    MyModelMap:
+      type: object
+      additionalProperties:
+        $ref: "#/components/schemas/MyModel"