Search in sources :

Example 6 with ResourceListing

use of io.swagger.models.resourcelisting.ResourceListing 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;
}
Also used : ResourceListing(io.swagger.models.resourcelisting.ResourceListing) ResourceListingMigrator(io.swagger.transform.migrate.ResourceListingMigrator) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException)

Aggregations

ResourceListing (io.swagger.models.resourcelisting.ResourceListing)6 ApiDeclaration (io.swagger.models.apideclaration.ApiDeclaration)4 Swagger (io.swagger.models.Swagger)3 ApiListingReference (io.swagger.models.resourcelisting.ApiListingReference)3 ArrayList (java.util.ArrayList)3 Test (org.testng.annotations.Test)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Info (io.swagger.models.Info)2 File (java.io.File)2 MessageBuilder (io.swagger.report.MessageBuilder)1 ResourceListingMigrator (io.swagger.transform.migrate.ResourceListingMigrator)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1