Search in sources :

Example 51 with Response

use of io.swagger.models.Response in project swagger-core by swagger-api.

the class SimpleReaderTest method scanResourceWithResponseHeaders.

@Test(description = "scan a resource with response headers")
public void scanResourceWithResponseHeaders() {
    Swagger swagger = getSwagger(ResourceWithResponseHeaders.class);
    Map<String, Response> responses = getGetResponses(swagger, "/{id}");
    Map<String, Property> headers200 = responses.get("200").getHeaders();
    assertEquals(headers200.size(), 1);
    assertEquals(headers200.get("foo").getDescription(), "description");
    assertEquals(headers200.get("foo").getType(), "string");
    Map<String, Property> headers400 = responses.get("400").getHeaders();
    assertEquals(headers400.size(), 2);
    assertEquals(headers400.get("X-Rack-Cache").getDescription(), "Explains whether or not a cache was used");
    assertEquals(headers400.get("X-Rack-Cache").getType(), "boolean");
    Iterator<String> keyItr = headers400.keySet().iterator();
    assertEquals(keyItr.next(), "X-Rack-Cache");
    assertEquals(keyItr.next(), "X-After-Rack-Cache");
}
Also used : ResourceWithResponse(io.swagger.resources.ResourceWithResponse) Response(io.swagger.models.Response) Swagger(io.swagger.models.Swagger) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) MapProperty(io.swagger.models.properties.MapProperty) RefProperty(io.swagger.models.properties.RefProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) Test(org.testng.annotations.Test)

Example 52 with Response

use of io.swagger.models.Response in project swagger-core by swagger-api.

the class SimpleReaderTest method scanResourceWithGenerics.

@Test(description = "scan a resource with generics per 653")
public void scanResourceWithGenerics() {
    Swagger swagger = getSwagger(Resource653.class);
    Operation get = getGet(swagger, "/external/info");
    assertNotNull(get);
    Map<String, Response> responses = get.getResponses();
    assertNotNull(responses);
    Response response = responses.get("default");
    assertNotNull(response);
    assertNull(response.getSchema());
}
Also used : ResourceWithResponse(io.swagger.resources.ResourceWithResponse) Response(io.swagger.models.Response) Swagger(io.swagger.models.Swagger) Operation(io.swagger.models.Operation) NicknamedOperation(io.swagger.resources.NicknamedOperation) Test(org.testng.annotations.Test)

Example 53 with Response

use of io.swagger.models.Response in project java-chassis by ServiceComb.

the class TestApiOperation method testBase.

private void testBase(Path path) {
    Assert.assertEquals(1, path.getOperations().size());
    Operation operation = path.getGet();
    Assert.assertEquals("summary", operation.getSummary());
    Assert.assertEquals("notes", operation.getDescription());
    Assert.assertEquals(Arrays.asList("tag1", "tag2"), operation.getTags());
    Assert.assertEquals(Arrays.asList("application/json"), operation.getProduces());
    Assert.assertEquals(Arrays.asList("application/json"), operation.getConsumes());
    Assert.assertEquals(Arrays.asList(Scheme.HTTP, Scheme.HTTPS), operation.getSchemes());
    Map<String, Response> responseMap = operation.getResponses();
    Assert.assertEquals(2, responseMap.size());
    Response response = responseMap.get(SwaggerConst.SUCCESS_KEY);
    Assert.assertNotNull(response);
    Assert.assertEquals(null, response.getSchema());
    response = responseMap.get("202");
    Assert.assertNotNull(response);
    Assert.assertEquals(null, response.getSchema());
    Assert.assertEquals(1, response.getHeaders().size());
    Assert.assertEquals("integer", response.getHeaders().get("h1").getType());
}
Also used : Response(io.swagger.models.Response) ApiOperation(io.swagger.annotations.ApiOperation) Operation(io.swagger.models.Operation)

Example 54 with Response

use of io.swagger.models.Response in project java-chassis by ServiceComb.

the class TestApiResponse method checkSingle.

public void checkSingle(SwaggerGenerator generator) {
    Swagger swagger = generator.getSwagger();
    Path path = swagger.getPaths().get("/testSingle");
    Operation operation = path.getOperations().get(0);
    Assert.assertEquals("testSingle", operation.getOperationId());
    Response response = operation.getResponses().get("200");
    Assert.assertEquals(Integer.class, ConverterMgr.findJavaType(generator, response.getSchema()).getRawClass());
}
Also used : Path(io.swagger.models.Path) Response(io.swagger.models.Response) ApiResponse(io.swagger.annotations.ApiResponse) Swagger(io.swagger.models.Swagger) Operation(io.swagger.models.Operation)

Example 55 with Response

use of io.swagger.models.Response in project java-chassis by ServiceComb.

the class TestApiResponse method checkMulti.

public void checkMulti(SwaggerGenerator generator) {
    Swagger swagger = generator.getSwagger();
    Path path = swagger.getPaths().get("/testMulti");
    Operation operation = path.getOperations().get(0);
    Assert.assertEquals("testMulti", operation.getOperationId());
    Response response = operation.getResponses().get("200");
    Assert.assertEquals(Integer.class, ConverterMgr.findJavaType(generator, response.getSchema()).getRawClass());
    response = operation.getResponses().get("301");
    Assert.assertEquals(String.class, ConverterMgr.findJavaType(generator, response.getSchema()).getRawClass());
}
Also used : Path(io.swagger.models.Path) Response(io.swagger.models.Response) ApiResponse(io.swagger.annotations.ApiResponse) Swagger(io.swagger.models.Swagger) Operation(io.swagger.models.Operation)

Aggregations

Response (io.swagger.models.Response)93 Operation (io.swagger.models.Operation)51 Property (io.swagger.models.properties.Property)30 Path (io.swagger.models.Path)29 Swagger (io.swagger.models.Swagger)29 ApiResponse (io.swagger.annotations.ApiResponse)24 Test (org.testng.annotations.Test)23 RefProperty (io.swagger.models.properties.RefProperty)21 ArrayProperty (io.swagger.models.properties.ArrayProperty)20 Test (org.junit.Test)17 MapProperty (io.swagger.models.properties.MapProperty)14 Parameter (io.swagger.models.parameters.Parameter)13 Model (io.swagger.models.Model)12 BodyParameter (io.swagger.models.parameters.BodyParameter)12 StringProperty (io.swagger.models.properties.StringProperty)12 HashMap (java.util.HashMap)12 RefModel (io.swagger.models.RefModel)10 PathParameter (io.swagger.models.parameters.PathParameter)10 IntegerProperty (io.swagger.models.properties.IntegerProperty)10 QueryParameter (io.swagger.models.parameters.QueryParameter)9