|
53 | 53 | import io.swagger.models.resourcelisting.ImplicitGrant; |
54 | 54 | import io.swagger.models.resourcelisting.OAuth2Authorization; |
55 | 55 | import io.swagger.models.resourcelisting.ResourceListing; |
| 56 | +import io.swagger.parser.util.ClasspathHelper; |
56 | 57 | import io.swagger.parser.util.RemoteUrl; |
57 | 58 | import io.swagger.parser.util.SwaggerDeserializationResult; |
58 | 59 | import io.swagger.report.MessageBuilder; |
59 | 60 | import io.swagger.transform.migrate.ApiDeclarationMigrator; |
60 | 61 | import io.swagger.transform.migrate.ResourceListingMigrator; |
61 | 62 | import io.swagger.util.Json; |
| 63 | +import org.apache.commons.io.FileUtils; |
62 | 64 | import org.slf4j.Logger; |
63 | 65 | import org.slf4j.LoggerFactory; |
64 | 66 |
|
65 | 67 | import java.io.File; |
66 | 68 | import java.io.IOException; |
67 | 69 | import java.math.BigDecimal; |
| 70 | +import java.net.URI; |
| 71 | +import java.nio.file.Files; |
| 72 | +import java.nio.file.Paths; |
68 | 73 | import java.util.ArrayList; |
69 | 74 | import java.util.HashMap; |
70 | 75 | import java.util.List; |
@@ -187,7 +192,22 @@ public ResourceListing readResourceListing(String input, MessageBuilder messages |
187 | 192 | String json = RemoteUrl.urlToString(input, auths); |
188 | 193 | jsonNode = Json.mapper().readTree(json); |
189 | 194 | } else { |
190 | | - jsonNode = Json.mapper().readTree(new File(input)); |
| 195 | + final String fileScheme = "file:"; |
| 196 | + java.nio.file.Path path; |
| 197 | + if (input.toLowerCase().startsWith(fileScheme)) { |
| 198 | + path = Paths.get(URI.create(input)); |
| 199 | + } else { |
| 200 | + path = Paths.get(input); |
| 201 | + } |
| 202 | + String json; |
| 203 | + if (Files.exists(path)) { |
| 204 | + json= FileUtils.readFileToString(path.toFile(), "UTF-8"); |
| 205 | + } else { |
| 206 | + json = ClasspathHelper.loadFileFromClasspath(input ); |
| 207 | + } |
| 208 | + |
| 209 | + jsonNode = Json.mapper().readTree(json); |
| 210 | + |
191 | 211 | } |
192 | 212 | if (jsonNode.get("swaggerVersion") == null) { |
193 | 213 | return null; |
@@ -490,7 +510,21 @@ public ApiDeclaration readDeclaration(String input, MessageBuilder messages, Lis |
490 | 510 | String json = RemoteUrl.urlToString(input, auths); |
491 | 511 | jsonNode = Json.mapper().readTree(json); |
492 | 512 | } else { |
493 | | - jsonNode = Json.mapper().readTree(new java.io.File(input)); |
| 513 | + final String fileScheme = "file:"; |
| 514 | + java.nio.file.Path path; |
| 515 | + if (input.toLowerCase().startsWith(fileScheme)) { |
| 516 | + path = Paths.get(URI.create(input)); |
| 517 | + } else { |
| 518 | + path = Paths.get(input); |
| 519 | + } |
| 520 | + String json; |
| 521 | + if (Files.exists(path)) { |
| 522 | + json= FileUtils.readFileToString(path.toFile(), "UTF-8"); |
| 523 | + } else { |
| 524 | + json = ClasspathHelper.loadFileFromClasspath(input ); |
| 525 | + } |
| 526 | + |
| 527 | + jsonNode = Json.mapper().readTree(json); |
494 | 528 | } |
495 | 529 |
|
496 | 530 | // this should be moved to a json patch |
|
0 commit comments