use of io.swagger.models.auth.AuthorizationValue in project swagger-parser by swagger-api.
the class SwaggerParser method readWithInfo.
public SwaggerDeserializationResult readWithInfo(String swaggerAsString, boolean resolve) {
if (swaggerAsString == null) {
return new SwaggerDeserializationResult().message("empty or null swagger supplied");
}
try {
JsonNode node;
if (swaggerAsString.trim().startsWith("{")) {
ObjectMapper mapper = Json.mapper();
node = mapper.readTree(swaggerAsString);
} else {
node = DeserializationUtils.readYamlTree(swaggerAsString);
}
SwaggerDeserializationResult result = new Swagger20Parser().readWithInfo(node);
if (result != null) {
if (resolve) {
result.setSwagger(new SwaggerResolver(result.getSwagger(), new ArrayList<AuthorizationValue>(), null).resolve());
}
} else {
result = new SwaggerDeserializationResult().message("Definition does not appear to be a valid Swagger format");
}
return result;
} catch (Exception e) {
return new SwaggerDeserializationResult().message("malformed or unreadable swagger supplied");
}
}
use of io.swagger.models.auth.AuthorizationValue in project swagger-parser by swagger-api.
the class NetworkReferenceTests method testIssue335.
@Test
public void testIssue335() throws Exception {
new Expectations() {
{
remoteUrl.urlToString("http://server1/resources/swagger.json", new ArrayList<AuthorizationValue>());
result = issue_335_json;
remoteUrl.urlToString("http://server1/resources/Bar.json", new ArrayList<AuthorizationValue>());
result = issue_335_bar_json;
}
};
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("http://server1/resources/swagger.json", null, true);
Swagger swagger = result.getSwagger();
assertNotNull(swagger);
assertNotNull(swagger.getDefinitions());
assertNotNull(swagger.getDefinitions().get("BarData"));
assertNotNull(swagger.getDefinitions().get("BarSettingsRequest"));
}
use of io.swagger.models.auth.AuthorizationValue in project swagger-parser by swagger-api.
the class NetworkReferenceTests method testPathReference.
@Test
public void testPathReference() throws Exception {
new Expectations() {
{
remoteUrl.urlToString("http://petstore.swagger.io/v2/swagger.json", new ArrayList<AuthorizationValue>());
result = issue_407_json;
}
};
SwaggerParser parser = new SwaggerParser();
String yaml = "swagger: '2.0'\n" + "info:\n" + " description: |\n" + " version: 1.0.0\n" + " title: testing\n" + "paths:\n" + " /foo:\n" + " $ref: 'http://petstore.swagger.io/v2/swagger.json#/paths/~1pet'\n" + " /bar:\n" + " $ref: 'http://petstore.swagger.io/v2/swagger.json#/paths/~1pet'\n" + "schemes:\n" + " - https\n" + " - http";
final SwaggerDeserializationResult result = parser.readWithInfo(yaml);
Assert.assertNotNull(result.getSwagger());
assertTrue(result.getMessages().size() == 0);
assertTrue(result.getSwagger().getDefinitions().size() == 3);
}
use of io.swagger.models.auth.AuthorizationValue in project swagger-parser by swagger-api.
the class NetworkReferenceTests method testIssue411.
@Test
public void testIssue411() throws Exception {
final List<AuthorizationValue> auths = new ArrayList<>();
AuthorizationValue auth = new AuthorizationValue("Authorization", "OMG_SO_SEKR3T", "header");
auths.add(auth);
new Expectations() {
{
remoteUrl.urlToString("http://remote1/resources/swagger.json", auths);
result = issue_411_server;
remoteUrl.urlToString("http://remote2/resources/foo", auths);
result = issue_411_components;
}
};
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult result = parser.readWithInfo("http://remote1/resources/swagger.json", auths, true);
Json.prettyPrint(result);
Swagger swagger = result.getSwagger();
assertNotNull(swagger.getPath("/health"));
Path health = swagger.getPath("/health");
assertTrue(health.getGet().getParameters().size() == 0);
Object responseRef = health.getGet().getResponses().get("200").getSchema();
assertTrue(responseRef instanceof RefProperty);
RefProperty refProperty = (RefProperty) responseRef;
assertEquals(refProperty.get$ref(), "#/definitions/Success");
assertNotNull(swagger.getDefinitions().get("Success"));
Parameter param = swagger.getPath("/stuff").getGet().getParameters().get(0);
assertEquals(param.getIn(), "query");
assertEquals(param.getName(), "skip");
Response response = swagger.getPath("/stuff").getGet().getResponses().get("200");
assertNotNull(response);
assertTrue(response.getSchema() instanceof StringProperty);
Response error = swagger.getPath("/stuff").getGet().getResponses().get("400");
assertNotNull(error);
Property errorProp = error.getSchema();
assertNotNull(errorProp);
assertTrue(errorProp instanceof RefProperty);
RefProperty errorProperty = (RefProperty) errorProp;
assertEquals(errorProperty.get$ref(), "#/definitions/Error");
assertTrue(swagger.getDefinitions().get("Error") instanceof ModelImpl);
}
use of io.swagger.models.auth.AuthorizationValue in project swagger-parser by swagger-api.
the class NetworkReferenceTests method testIssue323.
@Test
public void testIssue323() throws Exception {
new Expectations() {
{
remoteUrl.urlToString("http://localhost:8080/nested-file-references/issue-323.yaml", new ArrayList<AuthorizationValue>());
result = issue_323_yaml;
remoteUrl.urlToString("http://localhost:8080/nested-file-references/eventsCase9.yaml", new ArrayList<AuthorizationValue>());
result = issue_323_events_yaml;
remoteUrl.urlToString("http://localhost:8080/nested-file-references/common/pagingWithFolderRef.yaml", new ArrayList<AuthorizationValue>());
result = issue_323_paging_yaml;
remoteUrl.urlToString("http://localhost:8080/nested-file-references/common/common2/bar.yaml", new ArrayList<AuthorizationValue>());
result = issue_323_bar_yaml;
}
};
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("http://localhost:8080/nested-file-references/issue-323.yaml", null, true);
assertNotNull(result.getSwagger());
Swagger swagger = result.getSwagger();
assertNotNull(swagger.getPath("/events"));
assertNotNull(swagger.getDefinitions().get("StatusResponse"));
assertNotNull(swagger.getDefinitions().get("Paging"));
assertNotNull(swagger.getDefinitions().get("Foobar"));
}
Aggregations