use of io.swagger.models.ArrayModel in project swagger-core by swagger-api.
the class PostParamTest method findPostOperationWithObjectsCollection.
@Test(description = "find a Post operation with collection of objects")
public void findPostOperationWithObjectsCollection() {
Path petPath = getPath("collectionOfObjects");
assertNotNull(petPath);
Operation petPost = petPath.getPost();
assertNotNull(petPost);
assertEquals(petPost.getParameters().size(), 1);
BodyParameter petPostBodyParam = (BodyParameter) petPost.getParameters().get(0);
assertEquals(petPostBodyParam.getName(), BODY);
Model inputModel = petPostBodyParam.getSchema();
assertTrue(inputModel instanceof ArrayModel);
ArrayModel ap = (ArrayModel) inputModel;
Property inputSchema = ap.getItems();
assertTrue(inputSchema instanceof RefProperty);
RefProperty rm = (RefProperty) inputSchema;
assertEquals(rm.getSimpleRef(), PET);
}
use of io.swagger.models.ArrayModel in project swagger-core by swagger-api.
the class PostParamTest method findAPostOperationWithStringsList.
@Test(description = "find a Post operation with list of strings")
public void findAPostOperationWithStringsList() {
Path petPath = getPath("listOfStrings");
assertNotNull(petPath);
Operation petPost = petPath.getPost();
assertNotNull(petPost);
assertEquals(petPost.getParameters().size(), 1);
BodyParameter petPostBodyParam = (BodyParameter) petPost.getParameters().get(0);
assertEquals(petPostBodyParam.getName(), BODY);
Model inputModel = petPostBodyParam.getSchema();
assertTrue(inputModel instanceof ArrayModel);
ArrayModel ap = (ArrayModel) inputModel;
Property inputSchema = ap.getItems();
assertTrue(inputSchema instanceof StringProperty);
}
use of io.swagger.models.ArrayModel in project swagger-parser by swagger-api.
the class SwaggerParserTest method testPetstore.
@Test
public void testPetstore() throws Exception {
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult result = parser.readWithInfo("src/test/resources/petstore.json", null, true);
assertNotNull(result);
assertTrue(result.getMessages().isEmpty());
Swagger swagger = result.getSwagger();
Map<String, Model> definitions = swagger.getDefinitions();
Set<String> expectedDefinitions = new HashSet<String>();
expectedDefinitions.add("User");
expectedDefinitions.add("Category");
expectedDefinitions.add("Pet");
expectedDefinitions.add("Tag");
expectedDefinitions.add("Order");
expectedDefinitions.add("PetArray");
assertEquals(definitions.keySet(), expectedDefinitions);
Model petModel = definitions.get("Pet");
Set<String> expectedPetProps = new HashSet<String>();
expectedPetProps.add("id");
expectedPetProps.add("category");
expectedPetProps.add("name");
expectedPetProps.add("photoUrls");
expectedPetProps.add("tags");
expectedPetProps.add("status");
assertEquals(petModel.getProperties().keySet(), expectedPetProps);
ArrayModel petArrayModel = (ArrayModel) definitions.get("PetArray");
assertEquals(petArrayModel.getType(), "array");
RefProperty refProp = (RefProperty) petArrayModel.getItems();
assertEquals(refProp.get$ref(), "#/definitions/Pet");
assertNull(petArrayModel.getProperties());
}
use of io.swagger.models.ArrayModel in project swagger-parser by swagger-api.
the class SwaggerParserTest method testIssue594.
@Test
public void testIssue594() {
String yaml = "swagger: '2.0'\n" + "paths:\n" + " /test:\n" + " post:\n" + " parameters:\n" + " - name: body\n" + " in: body\n" + " description: Hello world\n" + " schema:\n" + " type: array\n" + " minItems: 1\n" + " maxItems: 1\n" + " items: \n" + " $ref: \"#/definitions/Pet\"\n" + " responses:\n" + " 200:\n" + " description: 'OK'\n";
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo(yaml);
assertNotNull(result.getSwagger());
ArrayModel schema = (ArrayModel) ((BodyParameter) result.getSwagger().getPaths().get("/test").getPost().getParameters().get(0)).getSchema();
assertEquals(((RefProperty) schema.getItems()).get$ref(), "#/definitions/Pet");
assertNotNull(schema.getMaxItems());
assertNotNull(schema.getMinItems());
}
use of io.swagger.models.ArrayModel in project swagger-parser by swagger-api.
the class SwaggerCompatConverter method modelFromExtendedTypedObject.
public Model modelFromExtendedTypedObject(ExtendedTypedObject obj) {
String type = obj.getType() == null ? null : obj.getType().toString();
String format = obj.getFormat() == null ? null : obj.getFormat().toString();
Model output = null;
if (obj.getRef() != null) {
output = new RefModel().asDefault(obj.getRef());
} else {
if ("array".equals(type)) {
ArrayModel am = new ArrayModel();
Items items = obj.getItems();
type = items.getType() == null ? null : items.getType().toString();
format = items.getFormat() == null ? null : items.getFormat().toString();
Property innerType = PropertyBuilder.build(type, format, null);
if (innerType != null) {
am.setItems(innerType);
}
if (items.getRef() != null) {
am.setItems(new RefProperty(items.getRef()));
} else {
am.setItems(new RefProperty(type));
}
output = am;
} else {
Property input = PropertyBuilder.build(type, format, null);
if (input != null) {
output = PropertyBuilder.toModel(input);
} else if (!"void".equals(type)) {
// use ref model
output = new RefModel().asDefault(type);
}
}
}
return output;
}
Aggregations