use of io.swagger.models.Response in project incubator-servicecomb-java-chassis by apache.
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());
}
use of io.swagger.models.Response in project incubator-servicecomb-java-chassis by apache.
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"));
}
use of io.swagger.models.Response in project incubator-servicecomb-java-chassis by apache.
the class TestSwaggerUtils method correctResponsesOperationFixEmptyDescription.
@Test
public void correctResponsesOperationFixEmptyDescription() {
Response response = new Response();
Operation operation = new Operation();
operation.addResponse("200", response);
SwaggerUtils.correctResponses(operation);
Assert.assertEquals("response of 200", response.getDescription());
}
use of io.swagger.models.Response in project incubator-servicecomb-java-chassis by apache.
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);
}
}
use of io.swagger.models.Response in project incubator-servicecomb-java-chassis by apache.
the class AnnotationUtils method generateResponse.
private static void generateResponse(Swagger swagger, ResponseConfig responseConfig) {
Response response = new Response();
Property property = generateResponseProperty(swagger, responseConfig);
response.setSchema(property);
response.setDescription(responseConfig.getDescription());
if (responseConfig.getResponseHeaders() != null) {
Map<String, Property> headers = generateResponseHeader(swagger, responseConfig.getResponseHeaders());
response.setHeaders(headers);
}
responseConfig.setResponse(response);
}
Aggregations