use of io.swagger.models.properties.RefProperty in project swagger-parser by swagger-api.
the class FileReferenceTests method testIssue316.
@Test
public void testIssue316() {
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("./src/test/resources/nested-file-references/issue-316.yaml", null, true);
assertNotNull(result.getSwagger());
Swagger swagger = result.getSwagger();
assertNotNull(swagger.getPath("/events"));
Path path = swagger.getPath("/events");
assertNotNull(path.getGet());
Operation get = path.getGet();
assertEquals(get.getOperationId(), "getEvents");
assertTrue(swagger.getDefinitions().size() == 3);
assertTrue(swagger.getDefinitions().get("Foobar").getProperties().size() == 1);
assertTrue(swagger.getDefinitions().get("StatusResponse").getProperties().size() == 1);
assertTrue(swagger.getDefinitions().get("Paging2").getProperties().size() == 2);
Model model = swagger.getDefinitions().get("Paging2");
Property property = model.getProperties().get("foobar");
assertTrue(property instanceof RefProperty);
RefProperty ref = (RefProperty) property;
assertEquals(ref.get$ref(), "#/definitions/Foobar");
}
use of io.swagger.models.properties.RefProperty in project swagger-parser by swagger-api.
the class FileReferenceTests method testRelativeRefIssue421.
@Test
public void testRelativeRefIssue421() {
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("./src/test/resources/main.yaml", null, true);
assertNotNull(result.getSwagger());
Swagger swagger = result.getSwagger();
assertNotNull(swagger);
assertNotNull(swagger.getPath("pets"));
assertNotNull(swagger.getPath("pets").getGet());
assertNotNull(swagger.getPath("pets").getGet().getResponses());
assertNotNull(swagger.getPath("pets").getGet().getResponses().get("200"));
assertNotNull(swagger.getPath("pets").getGet().getResponses().get("200").getSchema());
assertTrue(swagger.getPath("pets").getGet().getResponses().get("200").getSchema() instanceof RefProperty);
assertEquals(((RefProperty) swagger.getPath("pets").getGet().getResponses().get("200").getSchema()).get$ref(), "#/definitions/Pet");
assertTrue(swagger.getDefinitions().get("Pet") instanceof ModelImpl);
assertTrue(swagger.getDefinitions().get("Pet").getProperties().size() == 2);
}
use of io.swagger.models.properties.RefProperty 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.properties.RefProperty in project swagger-parser by swagger-api.
the class SwaggerParserTest method testIssue286.
@Test
public void testIssue286() {
SwaggerParser parser = new SwaggerParser();
Swagger swagger = parser.read("issue_286.yaml");
Property response = swagger.getPath("/").getGet().getResponses().get("200").getSchema();
assertTrue(response instanceof RefProperty);
assertEquals(((RefProperty) response).getSimpleRef(), "issue_286_PetList");
assertNotNull(swagger.getDefinitions().get("issue_286_Allergy"));
}
use of io.swagger.models.properties.RefProperty in project swagger-parser by swagger-api.
the class SwaggerParserTest method doRelativeFileTest.
private Swagger doRelativeFileTest(String location) {
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult readResult = parser.readWithInfo(location, null, true);
if (readResult.getMessages().size() > 0) {
Json.prettyPrint(readResult.getMessages());
}
final Swagger swagger = readResult.getSwagger();
final Path path = swagger.getPath("/health");
// we successfully converted the RefPath to a Path
assertEquals(path.getClass(), Path.class);
final List<Parameter> parameters = path.getParameters();
assertParamDetails(parameters, 0, QueryParameter.class, "param1", "query");
assertParamDetails(parameters, 1, HeaderParameter.class, "param2", "header");
final Operation operation = path.getGet();
final List<Parameter> operationParams = operation.getParameters();
assertParamDetails(operationParams, 0, PathParameter.class, "param3", "path");
assertParamDetails(operationParams, 1, HeaderParameter.class, "param4", "header");
assertParamDetails(operationParams, 2, BodyParameter.class, "body", "body");
final BodyParameter bodyParameter = (BodyParameter) operationParams.get(2);
assertEquals(((RefModel) bodyParameter.getSchema()).get$ref(), "#/definitions/health");
final Map<String, Response> responsesMap = operation.getResponses();
assertResponse(swagger, responsesMap, "200", "Health information from the server", "#/definitions/health");
assertResponse(swagger, responsesMap, "400", "Your request was not valid", "#/definitions/error");
assertResponse(swagger, responsesMap, "500", "An unexpected error occur during processing", "#/definitions/error");
final Map<String, Model> definitions = swagger.getDefinitions();
final ModelImpl refInDefinitions = (ModelImpl) definitions.get("refInDefinitions");
assertEquals(refInDefinitions.getDescription(), "The example model");
expectedPropertiesInModel(refInDefinitions, "foo", "bar");
final ArrayModel arrayModel = (ArrayModel) definitions.get("arrayModel");
final RefProperty arrayModelItems = (RefProperty) arrayModel.getItems();
assertEquals(arrayModelItems.get$ref(), "#/definitions/foo");
final ModelImpl fooModel = (ModelImpl) definitions.get("foo");
assertEquals(fooModel.getDescription(), "Just another model");
expectedPropertiesInModel(fooModel, "hello", "world");
final ComposedModel composedCat = (ComposedModel) definitions.get("composedCat");
final ModelImpl child = (ModelImpl) composedCat.getChild();
expectedPropertiesInModel(child, "huntingSkill", "prop2", "reflexes", "reflexMap");
final ArrayProperty reflexes = (ArrayProperty) child.getProperties().get("reflexes");
final RefProperty reflexItems = (RefProperty) reflexes.getItems();
assertEquals(reflexItems.get$ref(), "#/definitions/reflex");
assertTrue(definitions.containsKey(reflexItems.getSimpleRef()));
final MapProperty reflexMap = (MapProperty) child.getProperties().get("reflexMap");
final RefProperty reflexMapAdditionalProperties = (RefProperty) reflexMap.getAdditionalProperties();
assertEquals(reflexMapAdditionalProperties.get$ref(), "#/definitions/reflex");
assertEquals(composedCat.getInterfaces().size(), 2);
assertEquals(composedCat.getInterfaces().get(0).get$ref(), "#/definitions/pet");
assertEquals(composedCat.getInterfaces().get(1).get$ref(), "#/definitions/foo_2");
return swagger;
}
Aggregations