Repository: swagger-api/swagger-parser
Pull request #848 (2018-09-26 06:08:47)

Code roll-in for issue 844
Hi team,

This PR is to solve the issue #844 (parser not honoring redirect responses in open API 3.0) in open API Parser. 

Please review the PR and merge the same.

Thanks,
Mohammed


Patch:
diff --git a/README.md b/README.md
index b7bbe3a9..d34d5ae5 100644
--- a/README.md
+++ b/README.md
@@ -97,7 +97,7 @@ You can include this library from Sonatype OSS for SNAPSHOTS, or Maven central f
 <dependency>
   <groupId>io.swagger.parser.v3</groupId>
   <artifactId>swagger-parser</artifactId>
-  <version>2.0.5-SNAPSHOT</version>
+  <version>2.0.4</version>
 </dependency>
 
 ```
@@ -108,7 +108,7 @@ or
 <dependency>
   <groupId>io.swagger.parser.v3</groupId>
   <artifactId>swagger-parser</artifactId>
-  <version>2.0.5-SNAPSHOT</version>
+  <version>2.0.4</version>
 </dependency>
 
 ```
diff --git a/modules/swagger-parser-core/pom.xml b/modules/swagger-parser-core/pom.xml
index 51afca3f..cf0f0c64 100644
--- a/modules/swagger-parser-core/pom.xml
+++ b/modules/swagger-parser-core/pom.xml
@@ -3,7 +3,7 @@
     <parent>
         <groupId>io.swagger.parser.v3</groupId>
         <artifactId>swagger-parser-project</artifactId>
-        <version>2.0.5-SNAPSHOT</version>
+        <version>2.0.4</version>
         <relativePath>../..</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>
diff --git a/modules/swagger-parser-v2-converter/pom.xml b/modules/swagger-parser-v2-converter/pom.xml
index 172e2db2..f5471d44 100644
--- a/modules/swagger-parser-v2-converter/pom.xml
+++ b/modules/swagger-parser-v2-converter/pom.xml
@@ -3,7 +3,7 @@
     <parent>
         <groupId>io.swagger.parser.v3</groupId>
         <artifactId>swagger-parser-project</artifactId>
-        <version>2.0.5-SNAPSHOT</version>
+        <version>2.0.4</version>
         <relativePath>../..</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>
@@ -30,12 +30,12 @@
         <dependency>
             <groupId>io.swagger.parser.v3</groupId>
             <artifactId>swagger-parser-core</artifactId>
-            <version>${project.parent.version}</version>
+            <version>${parent.version}</version>
         </dependency>
         <dependency>
             <groupId>io.swagger.parser.v3</groupId>
             <artifactId>swagger-parser-v3</artifactId>
-            <version>${project.parent.version}</version>
+            <version>${parent.version}</version>
         </dependency>
         <dependency>
             <groupId>org.apache.commons</groupId>
diff --git a/modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java b/modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java
index 0a47ca63..371ea850 100644
--- a/modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java
+++ b/modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java
@@ -194,8 +194,7 @@ public class SwaggerConverter implements SwaggerParserExtension {
                 if ("body".equals(v.getIn())) {
                     components.addRequestBodies(k, convertParameterToRequestBody(v));
                 } else if ("formData".equals(v.getIn())) {
-                    // formData_ is added not to overwrite existing schemas
-                    components.addSchemas("formData_" + k, convertFormDataToSchema(v));
+                    components.addRequestBodies(k, convertFormDataToRequestBody(v));
                 } else {
                     components.addParameters(k, convert(v));
                 }
@@ -530,16 +529,6 @@ public class SwaggerConverter implements SwaggerParserExtension {
         return false;
     }
 
-    private boolean isRefAFormParam(io.swagger.models.parameters.Parameter param) {
-        if (param instanceof RefParameter) {
-            RefParameter refParameter = (RefParameter) param;
-            String simpleRef = refParameter.getSimpleRef();
-            io.swagger.models.parameters.Parameter parameter = globalV2Parameters.get(simpleRef);
-            return "formData".equals(parameter.getIn());
-        }
-        return false;
-    }
-
     public Operation convert(io.swagger.models.Operation v2Operation) {
         Operation operation = new Operation();
         if (StringUtils.isNotBlank(v2Operation.getDescription())) {
@@ -566,11 +555,10 @@ public class SwaggerConverter implements SwaggerParserExtension {
                     String $ref = convert.get$ref();
                     if ($ref != null && $ref.startsWith("#/components/requestBodies/") && isRefABodyParam(param)) {
                         operation.setRequestBody(new RequestBody().$ref($ref));
-                    } else if ($ref != null && $ref.startsWith("#/components/schemas/") && isRefAFormParam(param)) {
-                        formParams.add(param);
                     } else {
                         operation.addParametersItem(convert);
                     }
+                    //operation.addParametersItem(convert(param));
                 }
             }
 
@@ -623,9 +611,8 @@ public class SwaggerConverter implements SwaggerParserExtension {
         return vendorExtensions;
     }
 
-    private Schema convertFormDataToSchema(io.swagger.models.parameters.Parameter formParam) {
-        SerializableParameter sp = (SerializableParameter) formParam;
-        return convert(sp);
+    private RequestBody convertFormDataToRequestBody(io.swagger.models.parameters.Parameter formParam) {
+        return convertFormDataToRequestBody(Arrays.asList(formParam), null);
     }
 
     private RequestBody convertFormDataToRequestBody(List<io.swagger.models.parameters.Parameter> formParams, List<String> consumes) {
@@ -634,27 +621,73 @@ public class SwaggerConverter implements SwaggerParserExtension {
         Schema formSchema = new Schema();
 
         for (io.swagger.models.parameters.Parameter param : formParams) {
-            SerializableParameter sp;
+            SerializableParameter sp = (SerializableParameter) param;
 
             Schema schema;
-            String name;
-            if (param instanceof RefParameter) {
-                RefParameter refParameter = (RefParameter) param;
-                String simpleRef = refParameter.getSimpleRef();
-                sp = (SerializableParameter) globalV2Parameters.get(simpleRef);
-                name = components.getSchemas().get("formData_" + simpleRef).getName();
-                schema = new Schema().$ref("#/components/schemas/formData_" + simpleRef);
+            if ("file".equals(sp.getType())) {
+                schema = new FileSchema();
+            } else if ("array".equals(sp.getType())) {
+                ArraySchema as = new ArraySchema();
+                if (sp.getItems() != null) {
+                    as.setItems(convert(sp.getItems()));
+                }
+                schema = as;
             } else {
-                sp = (SerializableParameter) param;
-                schema = convert(sp);
-                name = schema.getName();
+                schema = new Schema();
+                schema.setType(sp.getType());
+                schema.setFormat(sp.getFormat());
+            }
+
+            schema.setDescription(sp.getDescription());
+            schema.setReadOnly(sp.isReadOnly());
+            schema.setEnum(sp.getEnum());
+
+            if (sp.getMaxItems() != null) {
+                schema.setMaxItems(sp.getMaxItems());
+            }
+            if (sp.getMinItems() != null) {
+                schema.setMinItems(sp.getMinItems());
+            }
+            if (sp.isUniqueItems() != null) {
+                schema.setUniqueItems(sp.isUniqueItems());
+            }
+
+            schema.setMaximum(sp.getMaximum());
+            schema.setExclusiveMaximum(sp.isExclusiveMaximum());
+            schema.setMinimum(sp.getMinimum());
+            schema.setExclusiveMinimum(sp.isExclusiveMinimum());
+            schema.setMinLength(sp.getMinLength());
+            schema.setMaxLength(sp.getMaxLength());
+
+            if (sp.getVendorExtensions() != null) {
+                Object exampleExtension = sp.getVendorExtensions().get("x-example");
+                if (exampleExtension != null) {
+                    schema.setExample(exampleExtension);
+                }
+                Object nullableExtension = sp.getVendorExtensions().get("x-nullable");
+                if (nullableExtension != null) {
+                    schema.setNullable((Boolean) nullableExtension);
+                }
+                schema.setExtensions(convert(sp.getVendorExtensions()));
+            }
+
+            if (sp.getMultipleOf() != null) {
+                schema.setMultipleOf(new BigDecimal(sp.getMultipleOf().toString()));
+            }
+
+            schema.setPattern(sp.getPattern());
+            schema.setExtensions(convert(sp.getVendorExtensions()));
+
+            if (sp instanceof AbstractSerializableParameter) {
+                AbstractSerializableParameter ap = (AbstractSerializableParameter) sp;
+                schema.setDefault(ap.getDefault());
             }
 
             if (sp.getRequired()) {
                 formSchema.addRequiredItem(sp.getName());
             }
 
-            formSchema.addProperties(name, schema);
+            formSchema.addProperties(param.getName(), schema);
         }
 
         List<String> mediaTypes = new ArrayList<>(globalConsumes);
@@ -676,69 +709,6 @@ public class SwaggerConverter implements SwaggerParserExtension {
         return body;
     }
 
-    private Schema convert(SerializableParameter sp) {
-        Schema schema;
-        if ("file".equals(sp.getType())) {
-            schema = new FileSchema();
-        } else if ("array".equals(sp.getType())) {
-            ArraySchema as = new ArraySchema();
-            if (sp.getItems() != null) {
-                as.setItems(convert(sp.getItems()));
-            }
-            schema = as;
-        } else {
-            schema = new Schema();
-            schema.setType(sp.getType());
-            schema.setFormat(sp.getFormat());
-        }
-
-        schema.setDescription(sp.getDescription());
-        schema.setReadOnly(sp.isReadOnly());
-        schema.setEnum(sp.getEnum());
-
-        if (sp.getMaxItems() != null) {
-            schema.setMaxItems(sp.getMaxItems());
-        }
-        if (sp.getMinItems() != null) {
-            schema.setMinItems(sp.getMinItems());
-        }
-        if (sp.isUniqueItems() != null) {
-            schema.setUniqueItems(sp.isUniqueItems());
-        }
-
-        schema.setMaximum(sp.getMaximum());
-        schema.setExclusiveMaximum(sp.isExclusiveMaximum());
-        schema.setMinimum(sp.getMinimum());
-        schema.setExclusiveMinimum(sp.isExclusiveMinimum());
-        schema.setMinLength(sp.getMinLength());
-        schema.setMaxLength(sp.getMaxLength());
-        schema.setName(sp.getName());
-
-        if (sp.getVendorExtensions() != null) {
-            Object exampleExtension = sp.getVendorExtensions().get("x-example");
-            if (exampleExtension != null) {
-                schema.setExample(exampleExtension);
-            }
-            Object nullableExtension = sp.getVendorExtensions().get("x-nullable");
-            if (nullableExtension != null) {
-                schema.setNullable((Boolean) nullableExtension);
-            }
-            schema.setExtensions(convert(sp.getVendorExtensions()));
-        }
-
-        if (sp.getMultipleOf() != null) {
-            schema.setMultipleOf(new BigDecimal(sp.getMultipleOf().toString()));
-        }
-
-        schema.setPattern(sp.getPattern());
-
-        if (sp instanceof AbstractSerializableParameter) {
-            AbstractSerializableParameter ap = (AbstractSerializableParameter) sp;
-            schema.setDefault(ap.getDefault());
-        }
-        return schema;
-    }
-
     private RequestBody convertParameterToRequestBody(io.swagger.models.parameters.Parameter param) {
         return convertParameterToRequestBody(param, null);
     }
@@ -987,8 +957,6 @@ public class SwaggerConverter implements SwaggerParserExtension {
                 if (components.getRequestBodies() != null &&
                         components.getRequestBodies().get(ref.getSimpleRef()) != null) {
                     updatedRef += "requestBodies";
-                } else if (components.getSchemas() != null && components.getSchemas().get("formData_" + ref.getSimpleRef()) != null) {
-                    updatedRef += "schemas";
                 } else {
                     updatedRef += "parameters";
                 }
diff --git a/modules/swagger-parser-v3/pom.xml b/modules/swagger-parser-v3/pom.xml
index 4fceeddb..c71f09c1 100644
--- a/modules/swagger-parser-v3/pom.xml
+++ b/modules/swagger-parser-v3/pom.xml
@@ -3,7 +3,7 @@
     <parent>
         <groupId>io.swagger.parser.v3</groupId>
         <artifactId>swagger-parser-project</artifactId>
-        <version>2.0.5-SNAPSHOT</version>
+        <version>2.0.4</version>
         <relativePath>../..</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>
@@ -26,7 +26,7 @@
         <dependency>
             <groupId>io.swagger.parser.v3</groupId>
             <artifactId>swagger-parser-core</artifactId>
-            <version>${project.parent.version}</version>
+            <version>${parent.version}</version>
         </dependency>
         <dependency>
             <groupId>org.jmockit</groupId>
@@ -80,6 +80,6 @@
         </dependency>
     </dependencies>
     <properties>
-        <swagger-core-module-version>2.0.5-SNAPSHOT</swagger-core-module-version>
+        <swagger-core-module-version>2.0.4</swagger-core-module-version>
     </properties>
 </project>
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 04051bb7..fb402d32 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
@@ -14,7 +14,6 @@ import io.swagger.v3.oas.models.media.Schema;
 import io.swagger.v3.oas.models.parameters.Parameter;
 import io.swagger.v3.oas.models.parameters.RequestBody;
 import io.swagger.v3.oas.models.responses.ApiResponse;
-import io.swagger.v3.oas.models.responses.ApiResponses;
 import io.swagger.v3.oas.models.security.SecurityScheme;
 import io.swagger.v3.parser.ResolverCache;
 import io.swagger.v3.parser.models.RefFormat;
@@ -201,37 +200,9 @@ public final class ExternalRefProcessor {
         }
     }
 
-    public String processRefToExternalResponse(String $ref, RefFormat refFormat) {
-        String renamedRef = cache.getRenamedRef($ref);
-        if(renamedRef != null) {
-            return renamedRef;
-        }
-        final ApiResponse response = cache.loadRef($ref, refFormat, ApiResponse.class);
-
-        String newRef;
-
-        if (openAPI.getComponents() == null) {
-            openAPI.setComponents(new Components());
-        }
-        Map<String, ApiResponse> responses = openAPI.getComponents().getResponses();
+    public void processRefToExternalResponse(String $ref, RefFormat refFormat) {
 
-        if (responses == null) {
-            responses = new LinkedHashMap<>();
-        }
-
-        final String possiblyConflictingDefinitionName = computeDefinitionName($ref);
-
-        ApiResponse existingResponse = responses.get(possiblyConflictingDefinitionName);
-
-        if (existingResponse != null) {
-            LOGGER.debug("A model for " + existingResponse + " already exists");
-            if(existingResponse.get$ref() != null) {
-                // use the new model
-                existingResponse = null;
-            }
-        }
-        newRef = possiblyConflictingDefinitionName;
-        cache.putRenamedRef($ref, newRef);
+        final ApiResponse response = cache.loadRef($ref, refFormat, ApiResponse.class);
 
         if(response != null) {
 
@@ -256,7 +227,6 @@ public final class ExternalRefProcessor {
                 }
             }
         }
-        return newRef;
     }
 
     public String processRefToExternalRequestBody(String $ref, RefFormat refFormat) {
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ResponseProcessor.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ResponseProcessor.java
index 926641f4..036c3489 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ResponseProcessor.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ResponseProcessor.java
@@ -1,6 +1,5 @@
 package io.swagger.v3.parser.processors;
 
-import io.swagger.v3.oas.models.examples.Example;
 import io.swagger.v3.oas.models.headers.Header;
 import io.swagger.v3.oas.models.links.Link;
 import io.swagger.v3.oas.models.media.MediaType;
@@ -21,7 +20,6 @@ public class ResponseProcessor {
     private final HeaderProcessor headerProcessor;
     private final LinkProcessor linkProcessor;
     private final ExternalRefProcessor externalRefProcessor;
-    private final ExampleProcessor exampleProcessor;
     private final ResolverCache cache;
     private final OpenAPI openAPI;
 
@@ -29,7 +27,6 @@ public class ResponseProcessor {
         schemaProcessor = new SchemaProcessor(cache,openAPI);
         headerProcessor = new HeaderProcessor(cache,openAPI);
         linkProcessor = new LinkProcessor(cache,openAPI);
-        exampleProcessor = new ExampleProcessor(cache,openAPI);
         this.externalRefProcessor = new ExternalRefProcessor(cache, openAPI);
         this.cache = cache;
         this.openAPI = openAPI;
@@ -52,11 +49,6 @@ public class ResponseProcessor {
                         schemaProcessor.processSchema(schema);
                     }
                 }
-                if(mediaType.getExamples() != null) {
-                    for(Example ex: mediaType.getExamples().values()){
-                        exampleProcessor.processExample(ex);
-                    }
-                }
             }
         }
         if (response.getHeaders() != null){
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/RemoteUrl.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/RemoteUrl.java
index 18fb9729..a2f5b5a1 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/RemoteUrl.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/RemoteUrl.java
@@ -14,10 +14,7 @@ import javax.net.ssl.X509TrustManager;
 import java.io.BufferedReader;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.net.URI;
-import java.net.URL;
-import java.net.URLConnection;
-import java.net.URLEncoder;
+import java.net.*;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.security.KeyManagementException;
@@ -109,42 +106,45 @@ public class RemoteUrl {
         BufferedReader br = null;
 
         try {
-            final URL inUrl = new URL(cleanUrl(url));
-            final List<AuthorizationValue> query = new ArrayList<>();
-            final List<AuthorizationValue> header = new ArrayList<>();
-            if (auths != null && auths.size() > 0) {
-                for (AuthorizationValue auth : auths) {
-                    if ("query".equals(auth.getType())) {
-                        appendValue(inUrl, auth, query);
-                    } else if ("header".equals(auth.getType())) {
-                        appendValue(inUrl, auth, header);
+            URLConnection conn;
+            do {
+                final URL inUrl = new URL(cleanUrl(url));
+                final List<AuthorizationValue> query = new ArrayList<>();
+                final List<AuthorizationValue> header = new ArrayList<>();
+                if (auths != null && auths.size() > 0) {
+                    for (AuthorizationValue auth : auths) {
+                        if ("query".equals(auth.getType())) {
+                            appendValue(inUrl, auth, query);
+                        } else if ("header".equals(auth.getType())) {
+                            appendValue(inUrl, auth, header);
+                        }
                     }
                 }
-            }
-            final URLConnection conn;
-            if (!query.isEmpty()) {
-                final URI inUri = inUrl.toURI();
-                final StringBuilder newQuery = new StringBuilder(inUri.getQuery() == null ? "" : inUri.getQuery());
-                for (AuthorizationValue item : query) {
-                    if (newQuery.length() > 0) {
-                        newQuery.append("&");
+                if (!query.isEmpty()) {
+                    final URI inUri = inUrl.toURI();
+                    final StringBuilder newQuery = new StringBuilder(inUri.getQuery() == null ? "" : inUri.getQuery());
+                    for (AuthorizationValue item : query) {
+                        if (newQuery.length() > 0) {
+                            newQuery.append("&");
+                        }
+                        newQuery.append(URLEncoder.encode(item.getKeyName(), UTF_8.name())).append("=")
+                                .append(URLEncoder.encode(item.getValue(), UTF_8.name()));
                     }
-                    newQuery.append(URLEncoder.encode(item.getKeyName(), UTF_8.name())).append("=")
-                            .append(URLEncoder.encode(item.getValue(), UTF_8.name()));
+                    conn = new URI(inUri.getScheme(), inUri.getAuthority(), inUri.getPath(), newQuery.toString(),
+                            inUri.getFragment()).toURL().openConnection();
+                } else {
+                    conn = inUrl.openConnection();
+                }
+                CONNECTION_CONFIGURATOR.process(conn);
+                for (AuthorizationValue item : header) {
+                    conn.setRequestProperty(item.getKeyName(), item.getValue());
                 }
-                conn = new URI(inUri.getScheme(), inUri.getAuthority(), inUri.getPath(), newQuery.toString(),
-                        inUri.getFragment()).toURL().openConnection();
-            } else {
-                conn = inUrl.openConnection();
-            }
-            CONNECTION_CONFIGURATOR.process(conn);
-            for (AuthorizationValue item : header) {
-                conn.setRequestProperty(item.getKeyName(), item.getValue());
-            }
 
-            conn.setRequestProperty("Accept", ACCEPT_HEADER_VALUE);
-            conn.setRequestProperty("User-Agent", USER_AGENT_HEADER_VALUE);
-            conn.connect();
+                conn.setRequestProperty("Accept", ACCEPT_HEADER_VALUE);
+                conn.setRequestProperty("User-Agent", USER_AGENT_HEADER_VALUE);
+                conn.connect();
+                url = ((HttpURLConnection) conn).getHeaderField("Location");
+            } while (301 == ((HttpURLConnection) conn).getResponseCode());
             InputStream in = conn.getInputStream();
 
             StringBuilder contents = new StringBuilder();
diff --git a/modules/swagger-parser/pom.xml b/modules/swagger-parser/pom.xml
index ec2a90f2..f9a57012 100644
--- a/modules/swagger-parser/pom.xml
+++ b/modules/swagger-parser/pom.xml
@@ -3,7 +3,7 @@
     <parent>
         <groupId>io.swagger.parser.v3</groupId>
         <artifactId>swagger-parser-project</artifactId>
-        <version>2.0.5-SNAPSHOT</version>
+        <version>2.0.4</version>
         <relativePath>../..</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>
@@ -15,12 +15,12 @@
         <dependency>
             <groupId>io.swagger.parser.v3</groupId>
             <artifactId>swagger-parser-v2-converter</artifactId>
-            <version>${project.parent.version}</version>
+            <version>${parent.version}</version>
         </dependency>
         <dependency>
             <groupId>io.swagger.parser.v3</groupId>
             <artifactId>swagger-parser-v3</artifactId>
-            <version>${project.parent.version}</version>
+            <version>${parent.version}</version>
         </dependency>
         <dependency>
             <groupId>org.jmockit</groupId>
diff --git a/pom.xml b/pom.xml
index c5100cc4..ebd4fb3c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,7 +8,7 @@
     <modelVersion>4.0.0</modelVersion>
     <groupId>io.swagger.parser.v3</groupId>
     <artifactId>swagger-parser-project</artifactId>
-    <version>2.0.5-SNAPSHOT</version>
+    <version>2.0.4</version>
     <packaging>pom</packaging>
     <name>swagger-parser-project</name>
     <developers>
@@ -250,7 +250,7 @@
         </repository>
     </repositories>
     <properties>
-        <swagger-parser-v2-version>1.0.39-SNAPSHOT</swagger-parser-v2-version>
+        <swagger-parser-v2-version>1.0.38</swagger-parser-v2-version>
         <commons-io-version>2.4</commons-io-version>
         <slf4j-version>1.6.3</slf4j-version>
         <swagger-core-version>2.0.4</swagger-core-version>


Test patch:
diff --git a/modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java b/modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java
index ea36a55c..bd0a75d5 100644
--- a/modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java
+++ b/modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java
@@ -325,12 +325,11 @@ public class V2ConverterTest {
     public void testIssue17() throws Exception {
         OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_17_JSON);
         Map<String, RequestBody> requestBodies = oas.getComponents().getRequestBodies();
-        Map<String, Schema> schemas = oas.getComponents().getSchemas();
-        assertNotNull(schemas.get("formData_formEmail"));
-        assertNotNull(schemas.get("formData_formPassword"));
+        assertNotNull(requestBodies.get("formEmail").getContent().get("multipart/form-data"));
+        assertNotNull(requestBodies.get("formPassword").getContent().get("multipart/form-data"));
         assertNotNull(requestBodies.get("bodyParam").getContent().get("*/*"));
-        assertNull(oas.getPaths().get("/formPost").getPost().getParameters());
-        assertNotNull(oas.getPaths().get("/formPost").getPost().getRequestBody());
+        assertEquals(oas.getPaths().get("/formPost").getPost().getParameters().get(0).get$ref(),
+                REQUEST_BODY_FORMEMAIL);
         assertNotNull(oas.getPaths().get("/report/{userId}").getGet().getRequestBody().
                 getContent().get("multipart/form-data").getSchema().getProperties().get("limitForm"));
     }
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 3b403913..10430fc9 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
@@ -2,7 +2,6 @@ package io.swagger.v3.parser.test;
 
 
 import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.github.tomakehurst.wiremock.WireMockServer;
 import com.github.tomakehurst.wiremock.client.WireMock;
 import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
@@ -12,11 +11,9 @@ import io.swagger.v3.oas.models.Components;
 import io.swagger.v3.oas.models.OpenAPI;
 import io.swagger.v3.oas.models.Operation;
 import io.swagger.v3.oas.models.PathItem;
-import io.swagger.v3.oas.models.examples.Example;
 import io.swagger.v3.oas.models.media.ArraySchema;
 import io.swagger.v3.oas.models.media.ByteArraySchema;
 import io.swagger.v3.oas.models.media.ComposedSchema;
-import io.swagger.v3.oas.models.media.Content;
 import io.swagger.v3.oas.models.media.IntegerSchema;
 import io.swagger.v3.oas.models.media.Schema;
 import io.swagger.v3.oas.models.media.StringSchema;
@@ -59,47 +56,6 @@ public class OpenAPIV3ParserTest {
     protected int serverPort = getDynamicPort();
     protected WireMockServer wireMockServer;
 
-    @Test
-    public void testIssue837() {
-        ParseOptions options = new ParseOptions();
-        options.setResolve(true);
-        final OpenAPI openAPI = new OpenAPIV3Parser().readLocation("./issue837/main.yaml", null, options).getOpenAPI();
-
-        Assert.assertNotNull(openAPI);
-
-        Content content = openAPI.getPaths().get("/events").getGet().getResponses().get("200").getContent();
-        Assert.assertNotNull(content);
-
-        Map<String, Example> examples = content.get("application/json").getExamples();
-        Assert.assertEquals(examples.size(), 3);
-        Assert.assertEquals(((ObjectNode) examples.get("plain").getValue()).get("test").asText(), "plain");
-        Assert.assertEquals(examples.get("local").get$ref(), "#/components/examples/LocalRef");
-        Assert.assertEquals(examples.get("external").get$ref(), "#/components/examples/ExternalRef");
-    }
-  
-    @Test
-    public void testIssue834() {
-        ParseOptions options = new ParseOptions();
-        options.setResolve(true);
-        SwaggerParseResult result = new OpenAPIV3Parser().readLocation("issue-834/index.yaml", null, options);
-        assertNotNull(result.getOpenAPI());
-
-        Content foo200Content = result.getOpenAPI().getPaths().get("/foo").getGet().getResponses().get("200").getContent();
-        assertNotNull(foo200Content);
-        String foo200SchemaRef = foo200Content.get("application/json").getSchema().get$ref();
-        assertEquals(foo200SchemaRef, "#/components/schemas/schema");
-
-        Content foo300Content = result.getOpenAPI().getPaths().get("/foo").getGet().getResponses().get("300").getContent();
-        assertNotNull(foo300Content);
-        String foo300SchemaRef = foo300Content.get("application/json").getSchema().get$ref();
-        assertEquals(foo300SchemaRef, "#/components/schemas/schema");
-
-        Content bar200Content = result.getOpenAPI().getPaths().get("/bar").getGet().getResponses().get("200").getContent();
-        assertNotNull(bar200Content);
-        String bar200SchemaRef = bar200Content.get("application/json").getSchema().get$ref();
-        assertEquals(bar200SchemaRef, "#/components/schemas/schema");
-    }
-
     @Test
     public void testIssue811_RefSchema_ToRefSchema() {
         ParseOptions options = new ParseOptions();
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-834/components/response1.yaml b/modules/swagger-parser-v3/src/test/resources/issue-834/components/response1.yaml
deleted file mode 100644
index 1e041607..00000000
--- a/modules/swagger-parser-v3/src/test/resources/issue-834/components/response1.yaml
+++ /dev/null
@@ -1,6 +0,0 @@
----
-description: Response with schema containing reference
-content:
-  application/json:
-    schema:
-      $ref: "./schema.yaml"
\ No newline at end of file
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-834/components/response2.yaml b/modules/swagger-parser-v3/src/test/resources/issue-834/components/response2.yaml
deleted file mode 100644
index 1e041607..00000000
--- a/modules/swagger-parser-v3/src/test/resources/issue-834/components/response2.yaml
+++ /dev/null
@@ -1,6 +0,0 @@
----
-description: Response with schema containing reference
-content:
-  application/json:
-    schema:
-      $ref: "./schema.yaml"
\ No newline at end of file
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-834/components/schema.yaml b/modules/swagger-parser-v3/src/test/resources/issue-834/components/schema.yaml
deleted file mode 100644
index 3be57c93..00000000
--- a/modules/swagger-parser-v3/src/test/resources/issue-834/components/schema.yaml
+++ /dev/null
@@ -1,2 +0,0 @@
----
-type: object
\ No newline at end of file
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-834/index.yaml b/modules/swagger-parser-v3/src/test/resources/issue-834/index.yaml
deleted file mode 100644
index b3b5a0ce..00000000
--- a/modules/swagger-parser-v3/src/test/resources/issue-834/index.yaml
+++ /dev/null
@@ -1,32 +0,0 @@
----
-openapi: "3.0.0"
-externalDocs:
-  description: Test
-  url: http://test.com/test
-info:
-  version: 0.0.1
-  title: Test
-  license:
-    name: Test
-    url: http://test.com/test
-servers:
-- url: http://test.com/test
-paths:
-  /foo:
-    get:
-      description: foo
-      summary: foo
-      operationId: foo
-      responses:
-        200:
-          $ref: "./components/response1.yaml"
-        300:
-          $ref: "./components/response2.yaml"
-  /bar:
-    get:
-      description: bar
-      summary: bar
-      operationId: bar
-      responses:
-        200:
-          $ref: "./components/response1.yaml"
\ No newline at end of file
diff --git a/modules/swagger-parser-v3/src/test/resources/issue837/components.yaml b/modules/swagger-parser-v3/src/test/resources/issue837/components.yaml
deleted file mode 100644
index f0e7e47a..00000000
--- a/modules/swagger-parser-v3/src/test/resources/issue837/components.yaml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-components:
-  examples:
-    ExternalRef:
-      summary: An external reference
-      value:
-        test: external
\ No newline at end of file
diff --git a/modules/swagger-parser-v3/src/test/resources/issue837/main.yaml b/modules/swagger-parser-v3/src/test/resources/issue837/main.yaml
deleted file mode 100644
index 1d60f542..00000000
--- a/modules/swagger-parser-v3/src/test/resources/issue837/main.yaml
+++ /dev/null
@@ -1,40 +0,0 @@
-openapi: 3.0.0
-servers:
-  - url: 'https://example.com/api/v1'
-info:
-  title: Test API
-  version: '1'
-paths:
-  /events:
-    get:
-      description: A list of events
-      operationId: getEvents
-      responses:
-        '200':
-          description: OK
-          content:
-            application/json:
-              schema:
-                required:
-                  - test
-                type: object
-                properties:
-                  test:
-                    type: string
-              examples:
-                plain:
-                  summary: plain example
-                  value:
-                    test: plain
-                local:
-                  $ref: '#/components/examples/LocalRef'
-                external:
-                  $ref: './issue837/components.yaml#/components/examples/ExternalRef'
-components:
-  examples:
-    LocalRef:
-      summary: A local reference
-      value:
-        test: local
-
-
diff --git a/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java b/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java
index 0ccb2421..ea2422c1 100644
--- a/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java
+++ b/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java
@@ -352,4 +352,15 @@ public class OpenAPIParserTest {
         assertTrue(result.getOpenAPI() != null);
 
     }
+
+    @Test
+    public void testIssue844() {
+        OpenAPIParser openApiParser = new OpenAPIParser();
+        ParseOptions options = new ParseOptions();
+        options.setResolve(true);
+
+        OpenAPI openAPI = openApiParser.readLocation("reusableParametersWithExternalRef.json", null, options).getOpenAPI();
+        assertNotNull(openAPI);
+        assertEquals(openAPI.getPaths().get("/pets/{id}").getGet().getParameters().get(0).getIn(), "header");
+    }
 }
diff --git a/modules/swagger-parser/src/test/resources/Issue-783/issue-783-b.yaml b/modules/swagger-parser/src/test/resources/Issue-783/issue-783-b.yaml
deleted file mode 100644
index f4ef1895..00000000
--- a/modules/swagger-parser/src/test/resources/Issue-783/issue-783-b.yaml
+++ /dev/null
@@ -1,27 +0,0 @@
-common:
-  allOf:
-  - $ref: "#/core"
-  - type: object
-    properties:
-      attribute:
-        type: string
-      direct:
-        $ref: "#/core"
-      referenced:
-        type: array
-        items:
-          $ref: "#/core"
-
-core:
-  type: object
-  properties:
-    coreAttribute:
-      type: string
-    inner:
-      $ref: "#/innerCore"
-
-innerCore:
-  type: object
-  properties:
-    innerCoreAttribute:
-      type: string
\ No newline at end of file
diff --git a/modules/swagger-parser/src/test/resources/Issue-783/issue-783.yaml b/modules/swagger-parser/src/test/resources/Issue-783/issue-783.yaml
deleted file mode 100644
index e16cffb5..00000000
--- a/modules/swagger-parser/src/test/resources/Issue-783/issue-783.yaml
+++ /dev/null
@@ -1,29 +0,0 @@
-swagger: 2.0
-info:
-  version: 0.0.1
-  title: API
-paths:
-  /:
-    post:
-      summary: Create
-      name: user
-      in: body
-      description: user to add to the system
-      required: true
-      schema:
-        $ref: '#/definitions/create'
-      responses:
-        '200':
-          description: Successful response
-definitions:
-  create:
-    type: object
-    properties:
-      attribute:
-        type: string
-      direct:
-        $ref: "./issue-783-b.yaml#/common"
-      referenced:
-        type: array
-        items:
-          $ref: "./issue-783-b.yaml#/common"
\ No newline at end of file
diff --git a/modules/swagger-parser/src/test/resources/reusableParametersWithExternalRef.json b/modules/swagger-parser/src/test/resources/reusableParametersWithExternalRef.json
new file mode 100644
index 00000000..dc63918f
--- /dev/null
+++ b/modules/swagger-parser/src/test/resources/reusableParametersWithExternalRef.json
@@ -0,0 +1,27 @@
+{
+  "openapi": "3.0.1",
+  "info": {
+    "version": "1.0.9-abcd",
+    "title": "Swagger Sample API Reusable Parameters"
+  },
+  "paths": {
+    "/pets/{id}": {
+      "get": {
+        "description": "Returns pets based on ID",
+        "summary": "Find pets by ID",
+        "operationId": "getPetsById",
+        "parameters": [
+          { "$ref": "http://docs.baikalplatform.com/common/v2.0/common.json#/parameters/x-correlator" }
+        ],
+        "responses": {
+          "200": {
+            "description": "pet response"
+          },
+          "default": {
+            "description": "error payload"
+          }
+        }
+      }
+    }
+  }
+}
\ No newline at end of file