use of io.swagger.models.ArrayModel in project swagger-parser by swagger-api.
the class SwaggerCompatConverterTest method testIssue_641.
@Test
public void testIssue_641() throws IOException {
SwaggerCompatConverter converter = new SwaggerCompatConverter();
Swagger swagger2 = converter.read("specs/v1_2/issue-641.json");
assertNotNull(swagger2);
BodyParameter bodyParameter = (BodyParameter) swagger2.getPaths().get("/user/createWithArray").getPost().getParameters().get(0);
assertEquals(((RefProperty) ((ArrayModel) bodyParameter.getSchema()).getItems()).get$ref(), "#/definitions/User");
}
use of io.swagger.models.ArrayModel 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.models.ArrayModel in project swagger-parser by swagger-api.
the class SwaggerParserTest method testDefinitionExample.
@Test
public void testDefinitionExample() throws Exception {
SwaggerParser parser = new SwaggerParser();
final Swagger swagger = parser.read(TestUtils.getResourceAbsolutePath("/definition_example.yaml"));
ModelImpl model;
ArrayModel arrayModel;
model = (ModelImpl) swagger.getDefinitions().get("NumberType");
assertEquals((Double) model.getExample(), 2.0d, 0d);
model = (ModelImpl) swagger.getDefinitions().get("IntegerType");
assertEquals((int) model.getExample(), 2);
model = (ModelImpl) swagger.getDefinitions().get("StringType");
assertEquals((String) model.getExample(), "2");
model = (ModelImpl) swagger.getDefinitions().get("ObjectType");
assertTrue(model.getExample() instanceof Map);
Map objectExample = (Map) model.getExample();
assertEquals((String) objectExample.get("propertyA"), "valueA");
assertEquals((Integer) objectExample.get("propertyB"), new Integer(123));
arrayModel = (ArrayModel) swagger.getDefinitions().get("ArrayType");
assertTrue(arrayModel.getExample() instanceof List);
List<Map> arrayExample = (List<Map>) arrayModel.getExample();
assertEquals((String) arrayExample.get(0).get("propertyA"), "valueA1");
assertEquals((Integer) arrayExample.get(0).get("propertyB"), new Integer(123));
assertEquals((String) arrayExample.get(1).get("propertyA"), "valueA2");
assertEquals((Integer) arrayExample.get(1).get("propertyB"), new Integer(456));
model = (ModelImpl) swagger.getDefinitions().get("NumberTypeStringExample");
assertEquals((String) model.getExample(), "2.0");
model = (ModelImpl) swagger.getDefinitions().get("IntegerTypeStringExample");
assertEquals((String) model.getExample(), "2");
model = (ModelImpl) swagger.getDefinitions().get("StringTypeStringExample");
assertEquals((String) model.getExample(), "2");
model = (ModelImpl) swagger.getDefinitions().get("ObjectTypeStringExample");
assertEquals((String) model.getExample(), "{\"propertyA\": \"valueA\", \"propertyB\": 123}");
arrayModel = (ArrayModel) swagger.getDefinitions().get("ArrayTypeStringExample");
assertEquals((String) arrayModel.getExample(), "[{\"propertyA\": \"valueA1\", \"propertyB\": 123}, {\"propertyA\": \"valueA2\", \"propertyB\": 456}]");
}
use of io.swagger.models.ArrayModel in project swagger-parser by swagger-api.
the class SwaggerParserTest method testIssue75.
@Test
public void testIssue75() {
SwaggerParser parser = new SwaggerParser();
final Swagger swagger = parser.read("src/test/resources/issue99.json");
BodyParameter param = (BodyParameter) swagger.getPaths().get("/albums").getPost().getParameters().get(0);
Model model = param.getSchema();
assertNotNull(model);
assertTrue(model instanceof ArrayModel);
ArrayModel am = (ArrayModel) model;
assertTrue(am.getItems() instanceof ByteArrayProperty);
assertEquals(am.getItems().getFormat(), "byte");
}
use of io.swagger.models.ArrayModel 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