use of io.swagger.models.Response in project java-chassis by ServiceComb.
the class TestApiResponse method checkResponseHeader.
@Test
public void checkResponseHeader() {
SwaggerOperation swaggerOperation = swaggerOperations.findOperation("testResponseHeader");
Assert.assertEquals("/testResponseHeader", swaggerOperation.getPath());
Response response = swaggerOperation.getOperation().getResponses().get("200");
Property property = response.getHeaders().get("k1");
Assert.assertEquals("integer", property.getType());
Assert.assertEquals("int32", property.getFormat());
}
use of io.swagger.models.Response in project java-chassis by ServiceComb.
the class TestApiResponse method checkResponseDesc.
@Test
public void checkResponseDesc() {
SwaggerOperation swaggerOperation = swaggerOperations.findOperation("testMulti");
Assert.assertEquals("/testMulti", swaggerOperation.getPath());
Response response1 = swaggerOperation.getOperation().getResponses().get("200");
Response response2 = swaggerOperation.getOperation().getResponses().get("301");
Assert.assertEquals("msg1", response1.getDescription());
Assert.assertEquals("msg2", response2.getDescription());
}
use of io.swagger.models.Response in project java-chassis by ServiceComb.
the class TestOperationGenerator method apiOperationThenResponse.
@Test
public void apiOperationThenResponse() throws NoSuchMethodException {
SwaggerOperation swaggerOperation = swaggerOperations.findOperation("apiOperationThenResponse");
List<String> tags = swaggerOperation.getOperation().getTags();
assertThat(tags, contains("tag1", "tag2"));
Response response = swaggerOperation.getOperation().getResponses().get("200");
assertEquals("200 is ok............", response.getDescription());
Assert.assertNull(response.getHeaders().get("x-user-domain"));
Assert.assertNotNull(response.getHeaders().get("x-user-name"));
Assert.assertNotNull(swaggerOperation.getOperation().getVendorExtensions().get("x-class-name"));
}
use of io.swagger.models.Response in project java-chassis by ServiceComb.
the class AbstractOperationGenerator method scanResponse.
public void scanResponse() {
if (swaggerOperation.getResponses() != null) {
Response successResponse = swaggerOperation.getResponses().get(SwaggerConst.SUCCESS_KEY);
if (successResponse != null) {
if (successResponse.getResponseSchema() == null) {
// 标注已经定义了response,但是是void,这可能是在标注上未定义
// 根据函数原型来处理response
Model model = createResponseModel();
successResponse.setResponseSchema(model);
}
return;
}
}
Model model = createResponseModel();
Response response = new Response();
response.setResponseSchema(model);
swaggerOperation.addResponse(SwaggerConst.SUCCESS_KEY, response);
}
use of io.swagger.models.Response in project java-chassis by ServiceComb.
the class ResponsesMeta method init.
public void init(Swagger swagger, Operation operation) {
if (responseMap.isEmpty()) {
responseMap.put(Status.OK.getStatusCode(), OBJECT_JAVA_TYPE);
initGlobalDefaultMapper();
}
for (Entry<String, Response> entry : operation.getResponses().entrySet()) {
JavaType javaType = ConverterMgr.findJavaType(swagger, entry.getValue().getResponseSchema());
if ("default".equals(entry.getKey())) {
defaultResponse = javaType;
continue;
}
Integer statusCode = Integer.parseInt(entry.getKey());
JavaType existing = responseMap.get(statusCode);
if (existing == null || !isVoid(javaType)) {
responseMap.put(statusCode, javaType);
}
}
responseMap.putIfAbsent(ExceptionFactory.CONSUMER_INNER_STATUS_CODE, COMMON_EXCEPTION_JAVA_TYPE);
responseMap.putIfAbsent(ExceptionFactory.PRODUCER_INNER_STATUS_CODE, COMMON_EXCEPTION_JAVA_TYPE);
responseMap.putIfAbsent(Status.TOO_MANY_REQUESTS.getStatusCode(), COMMON_EXCEPTION_JAVA_TYPE);
responseMap.putIfAbsent(Status.REQUEST_TIMEOUT.getStatusCode(), COMMON_EXCEPTION_JAVA_TYPE);
responseMap.putIfAbsent(Status.SERVICE_UNAVAILABLE.getStatusCode(), COMMON_EXCEPTION_JAVA_TYPE);
if (defaultResponse == null) {
// swagger中没有定义default,加上default专用于处理exception
defaultResponse = OBJECT_JAVA_TYPE;
}
}
Aggregations