Search in sources :

Example 86 with Response

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

the class TestSwaggerUtils method correctResponsesOperation2xxTo200.

@Test
public void correctResponsesOperation2xxTo200() {
    Response response = new Response();
    Operation operation = new Operation();
    operation.addResponse("default", new Response());
    operation.addResponse("201", response);
    operation.addResponse("301", new Response());
    SwaggerUtils.correctResponses(operation);
    Assert.assertSame(response, operation.getResponses().get("200"));
}
Also used : Response(io.swagger.models.Response) Operation(io.swagger.models.Operation) Test(org.junit.Test)

Example 87 with Response

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

the class TestSwaggerUtils method correctResponsesOperationDefaultTo200.

@Test
public void correctResponsesOperationDefaultTo200() {
    Response response = new Response();
    Operation operation = new Operation();
    operation.addResponse("default", response);
    SwaggerUtils.correctResponses(operation);
    Assert.assertSame(response, operation.getResponses().get("200"));
}
Also used : Response(io.swagger.models.Response) Operation(io.swagger.models.Operation) Test(org.junit.Test)

Example 88 with Response

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

the class TestSwaggerUtils method correctResponsesHavePaths.

@Test
public void correctResponsesHavePaths() {
    Response response = new Response();
    Operation operation = new Operation();
    operation.addResponse("200", response);
    Path path = new Path();
    path.set("get", operation);
    Swagger swagger = new Swagger();
    swagger.path("/base", path);
    SwaggerUtils.correctResponses(swagger);
    Assert.assertEquals("response of 200", response.getDescription());
}
Also used : Response(io.swagger.models.Response) Path(io.swagger.models.Path) Swagger(io.swagger.models.Swagger) Operation(io.swagger.models.Operation) Test(org.junit.Test)

Example 89 with Response

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

the class SwaggerUtils method correctResponses.

public static void correctResponses(Operation operation) {
    int okCode = Status.OK.getStatusCode();
    String strOkCode = String.valueOf(okCode);
    Response okResponse = null;
    for (Entry<String, Response> responseEntry : operation.getResponses().entrySet()) {
        Response response = responseEntry.getValue();
        if (StringUtils.isEmpty(response.getDescription())) {
            response.setDescription("response of " + responseEntry.getKey());
        }
        if (operation.getResponses().get(strOkCode) != null) {
            continue;
        }
        int statusCode = NumberUtils.toInt(responseEntry.getKey());
        if ("default".equals(responseEntry.getKey())) {
            statusCode = okCode;
        }
        if (Family.SUCCESSFUL.equals(Family.familyOf(statusCode))) {
            okResponse = response;
        }
    }
    if (okResponse != null) {
        operation.addResponse(strOkCode, okResponse);
    }
}
Also used : Response(io.swagger.models.Response)

Example 90 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.getResponseSchema());
    response = responseMap.get("202");
    Assert.assertNotNull(response);
    Assert.assertEquals(null, response.getResponseSchema());
    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)

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