use of io.swagger.models.Response in project swagger-core by swagger-api.
the class Reader method addResponse.
private void addResponse(Operation operation, ApiResponse apiResponse) {
Map<String, Property> responseHeaders = parseResponseHeaders(apiResponse.responseHeaders());
Response response = new Response().description(apiResponse.message()).headers(responseHeaders);
if (apiResponse.code() == 0) {
operation.defaultResponse(response);
} else {
operation.response(apiResponse.code(), response);
}
if (StringUtils.isNotEmpty(apiResponse.reference())) {
response.schema(new RefProperty(apiResponse.reference()));
} else if (!isVoid(apiResponse.response())) {
Type responseType = apiResponse.response();
final Property property = ModelConverters.getInstance().readAsProperty(responseType);
if (property != null) {
response.schema(ContainerWrapper.wrapContainer(apiResponse.responseContainer(), property));
appendModels(responseType);
}
}
}
use of io.swagger.models.Response in project swagger-core by swagger-api.
the class ArrayPropertyDeserializerTest method testArrayDeserialization.
@Test(description = "it should includes the example in the arrayproperty")
public void testArrayDeserialization() throws Exception {
Operation operation = Yaml.mapper().readValue(yaml, Operation.class);
Response response = operation.getResponses().get("200");
assertNotNull(response);
Property responseSchema = response.getSchema();
assertNotNull(responseSchema);
assertTrue(responseSchema instanceof ArrayProperty);
ArrayProperty mp = (ArrayProperty) responseSchema;
assertNotNull(mp.getExample());
assertEquals(mp.getMinItems(), new Integer(3));
assertEquals(mp.getMaxItems(), new Integer(100));
}
use of io.swagger.models.Response in project swagger-core by swagger-api.
the class MapPropertyDeserializerTest method testMapDeserializationVendorExtensions.
@Test(description = "vendor extensions should be included with object type")
public void testMapDeserializationVendorExtensions() throws Exception {
Operation operation = Json.mapper().readValue(json, Operation.class);
Response response = operation.getResponses().get("200");
assertNotNull(response);
Property responseSchema = response.getSchema();
assertNotNull(responseSchema);
MapProperty mp = (MapProperty) responseSchema;
assertTrue(mp.getVendorExtensions().size() > 0);
assertNotNull(mp.getVendorExtensions().get("x-foo"));
assertEquals(mp.getVendorExtensions().get("x-foo"), "vendor x");
}
use of io.swagger.models.Response 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.Response in project swagger-core by swagger-api.
the class SimpleScannerWithDecoratorExtensionTest method scanSimpleResourceWithoutDecorator.
/**
* Test for method annotated without vendor annotation.
*/
@Test(description = "scan a simple resource without custom decorator")
public void scanSimpleResourceWithoutDecorator() {
final Swagger swagger = getSwagger(SimpleResourceWithVendorAnnotation.class);
assertEquals(swagger.getPaths().size(), 2);
final Operation get = getGet(swagger, "/{id}/value");
assertNotNull(get);
assertEquals(get.getParameters().size(), 0);
final Response response = get.getResponses().get(RESPONSE_STATUS_401);
assertNull(response);
}
Aggregations