use of io.swagger.transform.migrate.ApiDeclarationMigrator in project swagger-parser by swagger-api.
the class SwaggerLegacyParser method read.
public ApiDeclaration read(String url, String resourcePath, Authentication authentication) {
MessageBuilder messageBuilder = new MessageBuilder();
SwaggerReader swaggerReader = new SwaggerReaderFactory(new SwaggerReaderConfiguration()).newReader();
JsonNode jsonNode = null;
try {
String resourceListingURL = getResourceListingURL(url, resourcePath);
jsonNode = swaggerReader.read(resourceListingURL, authentication, messageBuilder);
} catch (URISyntaxException e) {
messageBuilder.append(new Message("", e.getMessage(), Severity.ERROR));
}
validateMessageReport(messageBuilder);
ApiDeclarationMigrator apiDeclarationMigrator = new ApiDeclarationMigrator();
jsonNode = apiDeclarationMigrator.migrate(messageBuilder, jsonNode);
validateMessageReport(messageBuilder);
ApiDeclarationJsonValidator apiDeclarationJsonValidator = new ApiDeclarationJsonValidator();
apiDeclarationJsonValidator.validate(messageBuilder, jsonNode);
validateMessageReport(messageBuilder);
ApiDeclarationDeserializer apiDeclarationDeserializer = new ApiDeclarationDeserializer();
ApiDeclaration apiDeclaration = apiDeclarationDeserializer.deserialize(jsonNode, messageBuilder);
validateMessageReport(messageBuilder);
return apiDeclaration;
}
use of io.swagger.transform.migrate.ApiDeclarationMigrator in project swagger-parser by swagger-api.
the class SwaggerCompatConverter method readDeclaration.
public ApiDeclaration readDeclaration(String input, MessageBuilder messages, List<AuthorizationValue> auths) {
ApiDeclaration output = null;
try {
JsonNode jsonNode = null;
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);
}
// this should be moved to a json patch
if (jsonNode.isObject()) {
((ObjectNode) jsonNode).remove("authorizations");
}
ApiDeclarationMigrator migrator = new ApiDeclarationMigrator();
JsonNode transformed = migrator.migrate(messages, jsonNode);
output = Json.mapper().convertValue(transformed, ApiDeclaration.class);
} catch (java.lang.IllegalArgumentException e) {
return null;
} catch (Exception e) {
LOGGER.error("failed to read api declaration", e);
}
return output;
}
Aggregations