use of io.swagger.report.MessageBuilder in project swagger-parser by swagger-api.
the class SwaggerCompatConverter method read.
@Override
public Swagger read(String input, List<AuthorizationValue> auths) throws IOException {
Swagger output = null;
MessageBuilder migrationMessages = new MessageBuilder();
SwaggerLegacyParser swaggerParser = new SwaggerLegacyParser();
ResourceListing resourceListing = null;
resourceListing = readResourceListing(input, migrationMessages, auths);
List<ApiDeclaration> apis = new ArrayList<ApiDeclaration>();
if (resourceListing != null) {
List<ApiListingReference> refs = resourceListing.getApis();
boolean readAsSingleFile = false;
if (refs != null) {
for (ApiListingReference ref : refs) {
ApiDeclaration apiDeclaration = null;
JsonNode node = ref.getExtraFields();
JsonNode operations = node.get("operations");
if (operations != null) {
if (!readAsSingleFile) {
// this is a single-file swagger definition
apiDeclaration = readDeclaration(input, migrationMessages, auths);
// avoid doing this again
readAsSingleFile = true;
}
} else {
String location = null;
if (input.startsWith("http")) {
// look up as url
String pathLocation = ref.getPath();
if (pathLocation.startsWith("http")) {
// use as absolute url
location = pathLocation;
} else {
if (pathLocation.startsWith("/")) {
// handle 1.1 specs
if (resourceListing.getSwaggerVersion().equals(SwaggerVersion.V1_1) && resourceListing.getExtraFields().get("basePath") != null) {
String basePath = resourceListing.getExtraFields().get("basePath").textValue();
location = basePath + pathLocation;
} else {
location = input + pathLocation;
}
} else {
location = input + "/" + pathLocation;
}
}
} else {
// file system
File fileLocation = new File(input);
if (ref.getPath().startsWith("/")) {
location = fileLocation.getParent() + ref.getPath();
} else {
location = fileLocation.getParent() + File.separator + ref.getPath();
}
}
if (location.indexOf(".{format}") != -1) {
location = location.replaceAll("\\.\\{format\\}", ".json");
}
apiDeclaration = readDeclaration(location, migrationMessages, auths);
}
if (apiDeclaration != null) {
apis.add(apiDeclaration);
}
}
}
output = convert(resourceListing, apis);
}
return output;
}
use of io.swagger.report.MessageBuilder 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;
}
Aggregations