Repository: swagger-api/swagger-parser
Pull request #1353 (2020-04-02 21:39:37)

ResolverFully: Ensure any header schema $ref is resolved
Fixes issue #1352


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 f766b287..e01c1d0a 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
@@ -217,6 +217,13 @@ public class ResolverFully {
                 Map<String,Example> resolved = resolveExample(examples);
                 resolvedValue.setExamples(resolved);
             }
+            Schema schema = resolvedValue.getSchema();
+            if(schema != null) {
+                Schema resolvedSchema = resolveSchema( schema);
+                if(resolvedSchema != null) {
+                    resolvedValue.setSchema( resolvedSchema);
+                }
+            }
             header.setValue(resolvedValue);
         }
     }


Test patch:
diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIResolverTest.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIResolverTest.java
index 2599092e..5987fcdb 100644
--- a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIResolverTest.java
+++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIResolverTest.java
@@ -492,6 +492,17 @@ public class OpenAPIResolverTest {
         assertTrue(prop instanceof Schema);
     }
 
+    @Test
+    public void testIssue1352(@Injectable final List<AuthorizationValue> auths) {
+        ParseOptions options = new ParseOptions();
+        options.setResolve(true);
+        options.setResolveFully(true);
+
+        OpenAPI openAPI= new OpenAPIV3Parser().readLocation("issue-1352.json", auths, options).getOpenAPI();
+        assertNull(openAPI.getPaths().get("/responses").getPatch().getResponses().get("200").getHeaders().get("x-my-secret-header").getSchema().get$ref());
+
+    }
+
     @Test
     public void testIssue1157(@Injectable final List<AuthorizationValue> auths) {
         ParseOptions options = new ParseOptions();
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-1352.json b/modules/swagger-parser-v3/src/test/resources/issue-1352.json
new file mode 100644
index 00000000..e19db4d9
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/issue-1352.json
@@ -0,0 +1,82 @@
+{
+  "openapi": "3.0.0",
+  "info": {
+    "title": "Responses",
+    "version": "0.0.0"
+  },
+  "paths": {
+    "/responses": {
+      "patch": {
+        "responses": {
+          "200": {
+            "description": "It's a secret",
+            "headers": {
+              "x-my-secret-header": {
+                "required": true,
+                "schema": {
+                  "$ref": "#/components/schemas/secrets"
+                }
+              }
+            },
+            "content": {
+              "application/json": {
+                "schema": {
+                  "type": "object",
+                  "maxProperties": 1,
+                  "additionalProperties": {
+                    "type": "number"
+                  }
+                }
+              },
+              "text/javascript": {
+                "schema": {
+                  "type": "object",
+                  "minProperties": 1,
+                  "additionalProperties": {
+                    "type": "boolean"
+                  }
+                }
+              }
+            }
+          },
+          "4XX": {
+            "$ref": "#/components/responses/failure"
+          }
+        }
+      }
+    }
+  },
+  "components": {
+    "responses": {
+      "success": {
+        "description": "Success",
+        "content": {
+          "application/json": {
+            "schema": {
+              "$ref": "#/components/schemas/successContent"
+            }
+          }
+        }
+      },
+      "failure": {
+        "description": "Error",
+        "content": {
+          "application/json": {
+            "schema": {
+              "type": "object"
+            }
+          }
+        }
+      }
+    },
+    "schemas": {
+      "secrets": {
+        "type": "array",
+        "items": {
+          "type": "integer",
+          "format": "int64"
+        }
+      }
+    }
+  }
+}