use of io.swagger.models.Response in project swagger-core by swagger-api.
the class SimpleScannerWithDecoratorExtensionTest method scanSimpleResourceWithDecorator.
/**
* Test for method annotated with vendor annotation which could be used for swagger documentation.
*/
@Test(description = "scan a simple resource with custom decorator")
public void scanSimpleResourceWithDecorator() {
final Swagger swagger = getSwagger(SimpleResourceWithVendorAnnotation.class);
assertEquals(swagger.getPaths().size(), 2);
final Operation get = getGet(swagger, "/{id}");
assertNotNull(get);
assertEquals(get.getParameters().size(), 2);
final Response response = get.getResponses().get(RESPONSE_STATUS_401);
assertNotNull(response);
assertEquals(response.getDescription(), RESPONSE_DESCRIPTION);
}
use of io.swagger.models.Response in project swagger-core by swagger-api.
the class SimpleReaderTest method scanResourceWithMapReturnType.
@Test(description = "scan a resource with map return type")
public void scanResourceWithMapReturnType() {
Swagger swagger = getSwagger(ResourceWithMapReturnValue.class);
Operation get = getGet(swagger, "/{id}");
assertNotNull(get);
assertNotNull(get.getResponses());
Response response = get.getResponses().get("200");
assertNotNull(response);
Property schema = response.getSchema();
assertEquals(schema.getClass(), MapProperty.class);
}
use of io.swagger.models.Response in project swagger-core by swagger-api.
the class SimpleReaderTest method scanResourceWithApiResponseResponseContainerValue.
@Test(description = "scan resource with ApiResponse.responseContainer() value")
public void scanResourceWithApiResponseResponseContainerValue() {
Swagger swagger = getSwagger(ResourceWithApiResponseResponseContainer.class);
Path paths = swagger.getPaths().get("/{id}");
Map<String, Response> responses1 = paths.getGet().getResponses();
assertEquals(responses1.get("200").getSchema().getClass(), MapProperty.class);
assertEquals(responses1.get("400").getSchema().getClass(), ArrayProperty.class);
Map<String, Response> responses2 = paths.getPut().getResponses();
assertEquals(responses2.get("201").getSchema().getClass(), RefProperty.class);
assertEquals(responses2.get("401").getSchema().getClass(), ArrayProperty.class);
Map<String, Response> responses3 = paths.getPost().getResponses();
assertEquals(responses3.get("202").getSchema().getClass(), RefProperty.class);
assertEquals(responses3.get("402").getSchema().getClass(), RefProperty.class);
Map<String, Response> responses4 = paths.getDelete().getResponses();
assertEquals(responses4.get("203").getSchema().getClass(), RefProperty.class);
assertEquals(responses4.get("403").getSchema().getClass(), RefProperty.class);
Path paths2 = swagger.getPaths().get("/{id}/name");
Map<String, Response> responses5 = paths2.getGet().getResponses();
assertEquals(responses5.get("203").getSchema().getClass(), ArrayProperty.class);
assertNull(((ArrayProperty) responses5.get("203").getSchema()).getUniqueItems());
assertNotEquals(responses5.get("203").getHeaders().get("foo").getClass(), MapProperty.class);
assertEquals(responses5.get("403").getSchema().getClass(), ArrayProperty.class);
assertEquals(((ArrayProperty) responses5.get("403").getSchema()).getUniqueItems(), Boolean.TRUE);
Map<String, Response> responses6 = paths2.getPut().getResponses();
assertEquals(responses6.get("203").getSchema().getClass(), ArrayProperty.class);
assertEquals(((ArrayProperty) responses6.get("203").getSchema()).getUniqueItems(), Boolean.TRUE);
assertEquals(responses6.get("203").getHeaders().get("foo").getClass(), ArrayProperty.class);
assertEquals(((ArrayProperty) responses6.get("203").getHeaders().get("foo")).getUniqueItems(), Boolean.TRUE);
assertEquals(responses6.get("403").getSchema().getClass(), ArrayProperty.class);
}
use of io.swagger.models.Response in project swagger-core by swagger-api.
the class SimpleReaderTest method scanResourceWithApiOperationCodeValue.
@Test(description = "scan resource with ApiOperation.code() value")
public void scanResourceWithApiOperationCodeValue() {
Swagger swagger = getSwagger(ResourceWithApiOperationCode.class);
Map<String, Response> responses1 = getGetResponses(swagger, "/{id}");
assertEquals(responses1.size(), 3);
assertTrue(responses1.containsKey("202"));
assertFalse(responses1.containsKey("200"));
assertEquals(responses1.get("202").getDescription(), "successful operation");
Map<String, Response> responses2 = getPutResponses(swagger, "/{id}");
assertEquals(responses2.size(), 3);
assertTrue(responses2.containsKey("200"));
assertEquals(responses2.get("200").getDescription(), "successful operation");
}
use of io.swagger.models.Response in project swagger-core by swagger-api.
the class SwaggerSerializerTest method convertSpec.
@Test(description = "it should convert a spec")
public void convertSpec() throws IOException {
final Model personModel = ModelConverters.getInstance().read(Person.class).get("Person");
final Model errorModel = ModelConverters.getInstance().read(Error.class).get("Error");
final Info info = new Info().version("1.0.0").title("Swagger Petstore");
final Contact contact = new Contact().name("Swagger API Team").email("foo@bar.baz").url("http://swagger.io");
info.setContact(contact);
final Map<String, Object> map = new HashMap<String, Object>();
map.put("name", "value");
info.setVendorExtension("x-test2", map);
info.setVendorExtension("x-test", "value");
final Swagger swagger = new Swagger().info(info).host("petstore.swagger.io").securityDefinition("api-key", new ApiKeyAuthDefinition("key", In.HEADER)).scheme(Scheme.HTTP).consumes("application/json").produces("application/json").model("Person", personModel).model("Error", errorModel);
final Operation get = new Operation().produces("application/json").summary("finds pets in the system").description("a longer description").tag("Pet Operations").operationId("get pet by id").deprecated(true);
get.parameter(new QueryParameter().name("tags").description("tags to filter by").required(false).property(new StringProperty()));
get.parameter(new PathParameter().name("petId").description("pet to fetch").property(new LongProperty()));
final Response response = new Response().description("pets returned").schema(new RefProperty().asDefault("Person")).example("application/json", "fun!");
final Response errorResponse = new Response().description("error response").schema(new RefProperty().asDefault("Error"));
get.response(200, response).defaultResponse(errorResponse);
final Operation post = new Operation().summary("adds a new pet").description("you can add a new pet this way").tag("Pet Operations").operationId("add pet").defaultResponse(errorResponse).parameter(new BodyParameter().description("the pet to add").schema(new RefModel().asDefault("Person")));
swagger.path("/pets", new Path().get(get).post(post));
final String swaggerJson = Json.mapper().writeValueAsString(swagger);
final Swagger rebuilt = Json.mapper().readValue(swaggerJson, Swagger.class);
SerializationMatchers.assertEqualsToJson(rebuilt, swaggerJson);
}
Aggregations