Skip to content

Commit c1b101c

Browse files
committed
fix for #125, added file:// protocol support
1 parent 348e5f4 commit c1b101c

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

modules/swagger-parser/src/main/java/io/swagger/parser/Swagger20Parser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ public Swagger read(String location, List<AuthorizationValue> auths) throws IOEx
7474
if (location.toLowerCase().startsWith("http")) {
7575
data = RemoteUrl.urlToString(location, auths);
7676
} else {
77+
if (location.toLowerCase().startsWith("file://")) {
78+
location = location.substring("file://".length());
79+
}
7780
final Path path = Paths.get(location);
7881
if(Files.exists(path)) {
7982
data = FileUtils.readFileToString(path.toFile(), "UTF-8");

modules/swagger-parser/src/test/java/io/swagger/parser/SwaggerReaderTest.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
package io.swagger.parser;
22

3-
import static org.testng.Assert.assertEquals;
4-
import static org.testng.Assert.assertNotNull;
5-
63
import io.swagger.matchers.SerializationMatchers;
74
import io.swagger.models.Model;
85
import io.swagger.models.Swagger;
96
import io.swagger.models.parameters.QueryParameter;
10-
import io.swagger.util.Json;
117
import io.swagger.util.ResourceUtils;
12-
138
import org.testng.annotations.Test;
149

1510
import java.io.IOException;
1611

12+
import static org.testng.Assert.assertEquals;
13+
import static org.testng.Assert.assertNotNull;
14+
1715
public class SwaggerReaderTest {
16+
@Test(description = "it should read the uber api with file protocol")
17+
public void readUberApiFromFile() {
18+
final SwaggerParser parser = new SwaggerParser();
19+
final Swagger swagger = parser.read("file://src/test/resources/uber.json");
20+
assertNotNull(swagger);
21+
}
1822

1923
@Test(description = "it should read the uber api")
2024
public void readUberApi() {

0 commit comments

Comments
 (0)