use of io.swagger.parser.util.SwaggerDeserializationResult 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.parser.util.SwaggerDeserializationResult 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"));
}
use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class SwaggerParserTest method testIssue450.
@Test
public void testIssue450() {
String desc = "An array of Pets";
String xTag = "x-my-tag";
String xVal = "An extension tag";
String yaml = "swagger: \"2.0\"\n" + "info:\n" + " version: 0.0.0\n" + " title: Simple API\n" + "paths:\n" + " /:\n" + " get:\n" + " responses:\n" + " '200':\n" + " description: OK\n" + "definitions:\n" + " PetArray:\n" + " type: array\n" + " items:\n" + " $ref: \"#/definitions/Pet\"\n" + " description: " + desc + "\n" + " " + xTag + ": " + xVal + "\n" + " Pet:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: string";
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo(yaml);
assertNotNull(result.getSwagger());
final Swagger swagger = result.getSwagger();
Model petArray = swagger.getDefinitions().get("PetArray");
assertNotNull(petArray);
assertTrue(petArray instanceof ArrayModel);
assertEquals(petArray.getDescription(), desc);
assertNotNull(petArray.getVendorExtensions());
assertNotNull(petArray.getVendorExtensions().get(xTag));
assertEquals(petArray.getVendorExtensions().get(xTag), xVal);
}
use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class SwaggerParserTest method testIssue292WithCSVCollectionFormat.
@Test
public void testIssue292WithCSVCollectionFormat() {
String yaml = "swagger: '2.0'\n" + "info:\n" + " version: '0.0.0'\n" + " title: nada\n" + "paths:\n" + " /persons:\n" + " get:\n" + " parameters:\n" + " - name: testParam\n" + " in: query\n" + " type: array\n" + " items:\n" + " type: string\n" + " collectionFormat: csv\n" + " responses:\n" + " 200:\n" + " description: Successful response";
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult result = parser.readWithInfo(yaml);
Swagger swagger = result.getSwagger();
Parameter param = swagger.getPaths().get("/persons").getGet().getParameters().get(0);
QueryParameter qp = (QueryParameter) param;
assertEquals(qp.getCollectionFormat(), "csv");
}
use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class SwaggerParserTest method testConverterIssue17.
@Test
public void testConverterIssue17() throws Exception {
String yaml = "swagger: '2.0'\n" + "info:\n" + " version: '0.0.0'\n" + " title: nada\n" + "paths:\n" + " /persons:\n" + " get:\n" + " parameters:\n" + " - name: testParam\n" + " in: query\n" + " type: array\n" + " items:\n" + " type: string\n" + " collectionFormat: csv\n" + " responses:\n" + " 200:\n" + " description: Successful response\n" + " schema:\n" + " $ref: '#/definitions/Content'\n" + "definitions:\n" + " Content:\n" + " type: object";
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo(yaml, Boolean.FALSE);
assertNotNull(result.getSwagger());
assertEquals(((RefProperty) result.getSwagger().getPaths().get("/persons").getGet().getResponses().get("200").getSchema()).get$ref(), "#/definitions/Content");
}
Aggregations