use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class SwaggerConverter method readContents.
@Override
public SwaggerParseResult readContents(String swaggerAsString, List<AuthorizationValue> auth, ParseOptions options) {
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo(swaggerAsString, options == null ? true : options.isResolve());
if (options != null) {
if (options.isResolve()) {
Swagger resolved = new SwaggerResolver(result.getSwagger(), convert(auth)).resolve();
result.setSwagger(resolved);
}
}
return readResult(result, auth, options);
}
use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class SwaggerConverter method readLocation.
@Override
public SwaggerParseResult readLocation(String url, List<AuthorizationValue> auths, ParseOptions options) {
boolean resolve = false;
if (options != null) {
resolve = options.isResolve();
}
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo(url, convert(auths), resolve);
return readResult(result, auths, options);
}
use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class LegacyConverterTest method testIssue43.
@Test
public void testIssue43() throws Exception {
new Expectations() {
{
remoteUrl.urlToString("http://gateway.marvel.com/docs", new ArrayList<AuthorizationValue>());
result = marvel_json;
remoteUrl.urlToString("http://gateway.marvel.com/docs/public", new ArrayList<AuthorizationValue>());
result = public_json;
}
};
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult result = parser.readWithInfo("http://gateway.marvel.com/docs", null, true);
Assert.assertNotNull(result.getSwagger());
}
use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class LegacyConverterTest method testIssueFun.
@Test
public void testIssueFun() throws Exception {
new Expectations() {
{
remoteUrl.urlToString("http://localhost:8080/api-docs", new ArrayList<AuthorizationValue>());
result = resources_json;
remoteUrl.urlToString("http://localhost:8080/api-docs/pet", new ArrayList<AuthorizationValue>());
result = pet_json;
remoteUrl.urlToString("http://localhost:8080/api-docs/store", new ArrayList<AuthorizationValue>());
result = store_json;
remoteUrl.urlToString("http://localhost:8080/api-docs/user", new ArrayList<AuthorizationValue>());
result = user_json;
remoteUrl.urlToString("http://localhost:8080/api-docs", null);
result = resources_json;
remoteUrl.urlToString("http://localhost:8080/api-docs/pet", null);
result = pet_json;
remoteUrl.urlToString("http://localhost:8080/api-docs/store", null);
result = store_json;
remoteUrl.urlToString("http://localhost:8080/api-docs/user", null);
result = user_json;
}
};
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult result = parser.readWithInfo("http://localhost:8080/api-docs", null, true);
Swagger swagger = parser.read("http://localhost:8080/api-docs");
Assert.assertNotNull(swagger);
}
use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class Swagger20Parser method readWithInfo.
@Override
public SwaggerDeserializationResult readWithInfo(String location, List<AuthorizationValue> auths) {
String data;
try {
location = location.replaceAll("\\\\", "/");
if (location.toLowerCase().startsWith("http")) {
data = RemoteUrl.urlToString(location, auths);
} else {
final String fileScheme = "file:";
Path path;
if (location.toLowerCase().startsWith(fileScheme)) {
path = Paths.get(URI.create(location));
} else {
path = Paths.get(location);
}
if (Files.exists(path)) {
data = FileUtils.readFileToString(path.toFile(), "UTF-8");
} else {
data = ClasspathHelper.loadFileFromClasspath(location);
}
}
JsonNode rootNode;
if (data.trim().startsWith("{")) {
ObjectMapper mapper = Json.mapper();
rootNode = mapper.readTree(data);
} else {
rootNode = DeserializationUtils.readYamlTree(data);
}
return readWithInfo(rootNode);
} catch (SSLHandshakeException e) {
SwaggerDeserializationResult output = new SwaggerDeserializationResult();
output.message("unable to read location `" + location + "` due to a SSL configuration error. " + "It is possible that the server SSL certificate is invalid, self-signed, or has an untrusted " + "Certificate Authority.");
return output;
} catch (Exception e) {
SwaggerDeserializationResult output = new SwaggerDeserializationResult();
output.message("unable to read location `" + location + "`");
return output;
}
}
Aggregations