use of io.swagger.transform.migrate.ResourceListingMigrator in project swagger-parser by swagger-api.
the class SwaggerCompatConverter method readResourceListing.
public ResourceListing readResourceListing(String input, MessageBuilder messages, List<AuthorizationValue> auths) {
ResourceListing output = null;
JsonNode jsonNode = null;
try {
if (input.startsWith("http")) {
String json = RemoteUrl.urlToString(input, auths);
jsonNode = Json.mapper().readTree(json);
} else {
final String fileScheme = "file:";
java.nio.file.Path path;
if (input.toLowerCase().startsWith(fileScheme)) {
path = Paths.get(URI.create(input));
} else {
path = Paths.get(input);
}
String json;
if (Files.exists(path)) {
json = FileUtils.readFileToString(path.toFile(), "UTF-8");
} else {
json = ClasspathHelper.loadFileFromClasspath(input);
}
jsonNode = Json.mapper().readTree(json);
}
if (jsonNode.get("swaggerVersion") == null) {
return null;
}
ResourceListingMigrator migrator = new ResourceListingMigrator();
JsonNode transformed = migrator.migrate(messages, jsonNode);
output = Json.mapper().convertValue(transformed, ResourceListing.class);
} catch (java.lang.IllegalArgumentException e) {
return null;
} catch (Exception e) {
LOGGER.error("failed to read resource listing", e);
}
return output;
}
Aggregations