use of io.swagger.models.parameters.BodyParameter in project swagger-core by swagger-api.
the class SimpleReaderTest method checkResponseModelsProcessing.
@Test(description = "check response models processing")
public void checkResponseModelsProcessing() {
Swagger swagger = getSwagger(ResourceWithTypedResponses.class);
assertEquals(swagger.getDefinitions().keySet(), Arrays.asList("Tag"));
for (Map.Entry<String, Path> entry : swagger.getPaths().entrySet()) {
String name = entry.getKey().substring(entry.getKey().lastIndexOf("/") + 1);
if ("testPrimitiveResponses".equals(name)) {
Map<String, String[]> expected = ImmutableMap.of("400", new String[] { "string", "uri" }, "401", new String[] { "string", "url" }, "402", new String[] { "string", "uuid" }, "403", new String[] { "integer", "int64" }, "404", new String[] { "string", null });
assertEquals(entry.getValue().getGet().getResponses().size(), expected.size());
for (Map.Entry<String, Response> responseEntry : entry.getValue().getGet().getResponses().entrySet()) {
String[] expectedProp = expected.get(responseEntry.getKey());
Property property = responseEntry.getValue().getSchema();
assertEquals(property.getType(), expectedProp[0]);
assertEquals(property.getFormat(), expectedProp[1]);
}
} else {
Operation op = entry.getValue().getGet();
Property response = op.getResponses().get("200").getSchema();
Model model = ((BodyParameter) op.getParameters().get(0)).getSchema();
assertEquals(op.getParameters().size(), 1);
if ("testObjectResponse".equals(name)) {
assertEquals(((RefProperty) response).getSimpleRef(), "Tag");
assertEquals(((RefModel) model).getSimpleRef(), "Tag");
} else if ("testObjectsResponse".equals(name)) {
assertEquals(((RefProperty) ((ArrayProperty) response).getItems()).getSimpleRef(), "Tag");
assertEquals(((RefProperty) ((ArrayModel) model).getItems()).getSimpleRef(), "Tag");
} else if ("testStringResponse".equals(name)) {
assertEquals(response.getClass(), StringProperty.class);
assertEquals(((ModelImpl) model).getType(), "string");
} else if ("testStringsResponse".equals(name)) {
assertEquals(((ArrayProperty) response).getItems().getClass(), StringProperty.class);
assertEquals(((ArrayModel) model).getItems().getClass(), StringProperty.class);
} else if ("testMapResponse".equals(name)) {
assertEquals(((RefProperty) ((MapProperty) response).getAdditionalProperties()).getSimpleRef(), "Tag");
assertNull(model.getProperties());
assertEquals(((RefProperty) ((ModelImpl) model).getAdditionalProperties()).getSimpleRef(), "Tag");
} else {
fail(String.format("Unexpected property: %s", name));
}
}
}
}
use of io.swagger.models.parameters.BodyParameter in project swagger-core by swagger-api.
the class SimpleReaderTest method scanResourceWithBodyParameters.
@Test(description = "scan a resource with body parameters")
public void scanResourceWithBodyParameters() {
Swagger swagger = getSwagger(ResourceWithBodyParams.class);
BodyParameter param = (BodyParameter) getPostParameters(swagger, "/testShort").get(0);
assertEquals(param.getDescription(), "a short input");
ModelImpl schema = (ModelImpl) param.getSchema();
assertEquals(schema.getType(), "integer");
assertEquals(schema.getFormat(), "int32");
assertEquals(swagger.getDefinitions().keySet(), Arrays.asList("Tag"));
testString(swagger, "/testApiString", "input", "String parameter");
testString(swagger, "/testString", "body", null);
testObject(swagger, "/testApiObject", "input", "Object parameter");
testObject(swagger, "/testObject", "body", null);
List<Operation> operations = new ArrayList<Operation>();
for (Path item : swagger.getPaths().values()) {
Operation op = item.getPost();
if (op.getOperationId().startsWith("testPrimitive")) {
operations.add(op);
}
}
assertEquals(operations.size(), 16);
for (Operation item : operations) {
assertEquals(item.getParameters().size(), 1);
}
}
use of io.swagger.models.parameters.BodyParameter in project swagger-core by swagger-api.
the class SimpleReaderTest method testParam.
private Model testParam(Swagger swagger, String path, String name, String description) {
BodyParameter param = (BodyParameter) getPostParameters(swagger, path).get(0);
assertEquals(param.getIn(), "body");
assertEquals(param.getName(), name);
assertEquals(param.getDescription(), description);
return param.getSchema();
}
use of io.swagger.models.parameters.BodyParameter in project swagger-core by swagger-api.
the class GenericsTest method checkCollectionsOfStringsAsBodyParameter.
@Test(description = "check collection of strings as body parameter")
public void checkCollectionsOfStringsAsBodyParameter() {
Operation op = getOperation("testStringsInBody");
assertEquals(op.getParameters().size(), 1);
BodyParameter p = getBodyParameter(op, 0);
ArrayModel strArray = (ArrayModel) p.getSchema();
assertEquals(strArray.getItems().getType(), "string");
}
use of io.swagger.models.parameters.BodyParameter in project swagger-core by swagger-api.
the class GenericsTest method checkCollectionsOfEnumerationsAsBodyParameter.
@Test(description = "check collection of enumerations as body parameter")
public void checkCollectionsOfEnumerationsAsBodyParameter() {
Operation op = getOperation("testEnumsInBody");
assertEquals(op.getParameters().size(), 1);
BodyParameter p = getBodyParameter(op, 0);
ArrayModel enumArray = (ArrayModel) p.getSchema();
assertEquals(((StringProperty) enumArray.getItems()).getEnum(), enumValues);
}
Aggregations