Repository: swagger-api/swagger-parser
Pull request #754 (2018-07-06 14:26:11)

Fix for #742


Patch:
diff --git a/README.md b/README.md
index 2bc8bcd0..a8cd031a 100644
--- a/README.md
+++ b/README.md
@@ -95,7 +95,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.2-SNAPSHOT</version>
+  <version>2.0.1</version>
 </dependency>
 
 ```
@@ -106,7 +106,7 @@ or
 <dependency>
   <groupId>io.swagger.parser.v3</groupId>
   <artifactId>swagger-parser</artifactId>
-  <version>2.0.2-SNAPSHOT</version>
+  <version>2.0.1</version>
 </dependency>
 
 ```
diff --git a/modules/swagger-parser-core/pom.xml b/modules/swagger-parser-core/pom.xml
index 8559734b..7e39477f 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.2-SNAPSHOT</version>
+        <version>2.0.1</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 e8e47330..33cc1ded 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.2-SNAPSHOT</version>
+        <version>2.0.1</version>
         <relativePath>../..</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>
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 814f1543..b4250e44 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
@@ -317,10 +317,7 @@ public class SwaggerConverter implements SwaggerParserExtension {
         }
 
         Scopes scopes = new Scopes();
-        Map<String, String> oAuth2Scopes = oAuth2Definition.getScopes();
-        if (oAuth2Scopes != null) {
-            oAuth2Scopes.forEach((k, v) -> scopes.addString(k, v));
-        }
+        oAuth2Definition.getScopes().forEach((k, v) -> scopes.addString(k, v));
         oAuthFlow.setScopes(scopes);
 
         securityScheme.setFlows(oAuthFlows);
diff --git a/modules/swagger-parser-v3/pom.xml b/modules/swagger-parser-v3/pom.xml
index 35cbe7f9..407fd1c9 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.2-SNAPSHOT</version>
+        <version>2.0.1</version>
         <relativePath>../..</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/OpenAPIV3Parser.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/OpenAPIV3Parser.java
index 0e5f57d7..256e2762 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/OpenAPIV3Parser.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/OpenAPIV3Parser.java
@@ -99,9 +99,9 @@ public class OpenAPIV3Parser implements SwaggerParserExtension {
         return null;
     }
 
-    public SwaggerParseResult readWithInfo(JsonNode node) {
+    public SwaggerParseResult readWithInfo(String path, JsonNode node) {
         OpenAPIDeserializer ser = new OpenAPIDeserializer();
-        return ser.deserialize(node);
+        return ser.deserialize(node, path);
     }
 
     private ObjectMapper getRightMapper(String data) {
@@ -139,7 +139,7 @@ public class OpenAPIV3Parser implements SwaggerParserExtension {
             ObjectMapper mapper = getRightMapper(data);
             JsonNode rootNode = mapper.readTree(data);
             LOGGER.debug("Parsed rootNode: {}", rootNode);
-            return readWithInfo(rootNode);
+            return readWithInfo(location, rootNode);
         }
         catch (SSLHandshakeException e) {
             SwaggerParseResult output = new SwaggerParseResult();
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/InlineModelResolver.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/InlineModelResolver.java
index 4eb0579a..be93c1d4 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/InlineModelResolver.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/InlineModelResolver.java
@@ -436,7 +436,6 @@ public class InlineModelResolver {
         model.setExample(example);
         model.setName(name);
         model.setXml(xml);
-        model.setType(object.getType());
 
         if (properties != null) {
             flattenProperties(properties, path);
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java
index 3bdeb8f1..c2779659 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java
@@ -48,7 +48,11 @@ import io.swagger.v3.parser.core.models.SwaggerParseResult;
 import io.swagger.v3.core.util.Json;
 import org.apache.commons.lang3.StringUtils;
 
+import java.io.File;
 import java.math.BigDecimal;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
@@ -97,10 +101,14 @@ public class OpenAPIDeserializer {
 
 
     public SwaggerParseResult deserialize(JsonNode rootNode) {
+    	return deserialize(rootNode, null);
+    }
+    
+    public SwaggerParseResult deserialize(JsonNode rootNode, String path) {
         SwaggerParseResult result = new SwaggerParseResult();
         try {
             ParseResult rootParse = new ParseResult();
-            OpenAPI api = parseRoot(rootNode, rootParse);
+            OpenAPI api = parseRoot(rootNode, rootParse, path);
             result.setOpenAPI(api);
             result.setMessages(rootParse.getMessages());
         } catch (Exception e) {
@@ -110,7 +118,7 @@ public class OpenAPIDeserializer {
         return result;
     }
 
-    public OpenAPI parseRoot(JsonNode node, ParseResult result) {
+    public OpenAPI parseRoot(JsonNode node, ParseResult result, String path) {
         String location = "";
         OpenAPI openAPI = new OpenAPI();
         if (node.getNodeType().equals(JsonNodeType.OBJECT)) {
@@ -145,7 +153,7 @@ public class OpenAPIDeserializer {
 
             ArrayNode array = getArray("servers", rootNode, false, location, result);
             if (array != null && array.size() > 0) {
-                openAPI.setServers(getServersList(array, String.format("%s.%s", location, "servers"), result));
+                openAPI.setServers(getServersList(array, String.format("%s.%s", location, "servers"), result, path));
             }else {
                 Server defaultServer = new Server();
                 defaultServer.setUrl("/");
@@ -331,7 +339,7 @@ public class OpenAPIDeserializer {
 
 
 
-    public List<Server> getServersList(ArrayNode obj, String location, ParseResult result) {
+    public List<Server> getServersList(ArrayNode obj, String location, ParseResult result, String path) {
 
         List<Server> servers = new ArrayList<>();
         if (obj == null) {
@@ -352,8 +360,16 @@ public class OpenAPIDeserializer {
         }
         return servers;
     }
+    
+    public List<Server> getServersList(ArrayNode obj, String location, ParseResult result) {
+		return getServersList(obj, location, result, null);
+	}
+
+	public Server getServer(ObjectNode obj, String location, ParseResult result) {
+		return getServer(obj, location, result, null);
+	}
 
-    public Server getServer(ObjectNode obj, String location, ParseResult result) {
+    public Server getServer(ObjectNode obj, String location, ParseResult result, String path) {
         if (obj == null) {
             return null;
         }
@@ -362,6 +378,18 @@ public class OpenAPIDeserializer {
 
         String value = getString("url", obj, true, location, result);
         if(StringUtils.isNotBlank(value)) {
+        	File file = new File(value);
+			if(!isValidURL(value) && !file.isAbsolute() && path != null){
+				try {
+					final URI absURI = new URI(path);
+					if("http".equals(absURI.getScheme()) || "https".equals(absURI.getScheme())){
+						value = absURI.resolve(new URI(value)).toString();
+					}
+				} catch (URISyntaxException e) {
+					e.printStackTrace();
+				}
+
+			}
             server.setUrl(value);
         }
 
@@ -393,6 +421,16 @@ public class OpenAPIDeserializer {
 
         return server;
     }
+    
+    boolean isValidURL(String urlString){
+		try {
+			URL url = new URL(urlString);
+			url.toURI();
+			return true;
+		} catch (Exception exception) {
+			return false;
+		}
+	}
 
     public ServerVariables getServerVariables(ObjectNode obj, String location, ParseResult result){
         ServerVariables serverVariables = new ServerVariables();
diff --git a/modules/swagger-parser/pom.xml b/modules/swagger-parser/pom.xml
index 06ae69f4..18737a5e 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.2-SNAPSHOT</version>
+        <version>2.0.1</version>
         <relativePath>../..</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>
diff --git a/pom.xml b/pom.xml
index 5562d6e9..376ecdda 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.2-SNAPSHOT</version>
+    <version>2.0.1</version>
     <packaging>pom</packaging>
     <name>swagger-parser-project</name>
     <developers>


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 13dd389e..cad5c1e6 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
@@ -1408,7 +1408,7 @@ public class OpenAPIV3ParserTest {
         String yaml = Files.readFile(new File("src/test/resources/over-quoted-example.yaml"));
         JsonNode rootNode = Yaml.mapper().readValue(yaml, JsonNode.class);
         OpenAPIV3Parser parser = new OpenAPIV3Parser();
-        OpenAPI openAPI = (parser.readWithInfo(rootNode)).getOpenAPI();
+        OpenAPI openAPI = (parser.readWithInfo(null, rootNode)).getOpenAPI();
 
         Map<String, Schema> definitions = openAPI.getComponents().getSchemas();
         assertEquals("NoQuotePlease", definitions.get("CustomerType").getExample());
diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/util/InlineModelResolverTest.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/util/InlineModelResolverTest.java
index 768b1aa8..99ff7e90 100644
--- a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/util/InlineModelResolverTest.java
+++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/util/InlineModelResolverTest.java
@@ -16,8 +16,6 @@ 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.parser.OpenAPIV3Parser;
-import io.swagger.v3.parser.core.models.ParseOptions;
 import org.testng.annotations.Test;
 
 
@@ -31,17 +29,6 @@ import static org.testng.AssertJUnit.*;
 
 @SuppressWarnings("static-method")
 public class InlineModelResolverTest {
-
-    @Test
-    public void testIssue705() throws Exception {
-        ParseOptions options = new ParseOptions();
-        options.setFlatten(true);
-        OpenAPI openAPI = new OpenAPIV3Parser().read("issue-705.yaml",null, options);
-        assertNotNull(openAPI);
-        assertNotNull(openAPI.getComponents().getSchemas().get("inline_response_200").getType());
-    }
-
-
     @Test
     public void resolveInlineModelTestWithoutTitle() throws Exception {
         OpenAPI openAPI = new OpenAPI();
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-705.yaml b/modules/swagger-parser-v3/src/test/resources/issue-705.yaml
deleted file mode 100644
index c2b4c4b7..00000000
--- a/modules/swagger-parser-v3/src/test/resources/issue-705.yaml
+++ /dev/null
@@ -1,41 +0,0 @@
-openapi: 3.0.0
-info:
-  version: 1.0.0
-  title: Swagger Petstore
-  license:
-    name: MIT
-paths:
-  /pets:
-    get:
-      summary: List all pets
-      operationId: listPets
-      tags:
-        - pets
-      parameters:
-        - name: limit
-          in: query
-          description: How many items to return at one time (max 100)
-          required: false
-          schema:
-            type: integer
-            format: int32
-      responses:
-        '200':
-          description: An paged array of pets
-          headers:
-            x-next:
-              description: A link to the next page of responses
-              schema:
-                type: string
-          content:
-            application/json:
-              schema:
-                 type: object
-                 properties:
-                    id:
-                      type: integer
-                      format: int64
-                    name:
-                      type: string
-                    tag:
-                      type: string
\ No newline at end of file