use of io.swagger.models.Response in project java-chassis by ServiceComb.
the class ClassUtils method createInterface.
private static Class<?> createInterface(Swagger swagger, ClassLoader classLoader, String packageName, String intfName) {
ClassConfig classConfig = new ClassConfig();
classConfig.setClassName(intfName);
classConfig.setIntf(true);
StringBuilder sbMethod = new StringBuilder();
StringBuilder sbMethodGenericSignature = new StringBuilder();
for (Path path : swagger.getPaths().values()) {
for (Operation operation : path.getOperations()) {
boolean hasGenericSignature = false;
sbMethod.setLength(0);
sbMethodGenericSignature.setLength(0);
Response result = operation.getResponses().get(SwaggerConst.SUCCESS_KEY);
JavaType resultJavaType = ConverterMgr.findJavaType(classLoader, packageName, swagger, result.getSchema());
hasGenericSignature = hasGenericSignature || resultJavaType.hasGenericTypes();
sbMethod.append(JavassistUtils.getNameForGenerateCode(resultJavaType)).append(" ").append(operation.getOperationId()).append("(");
sbMethodGenericSignature.append("(");
for (Parameter parameter : operation.getParameters()) {
String paramName = parameter.getName();
paramName = correctMethodParameterName(paramName);
JavaType paramJavaType = ConverterMgr.findJavaType(classLoader, packageName, swagger, parameter);
hasGenericSignature = hasGenericSignature || paramJavaType.hasGenericTypes();
String code = String.format("%s %s,", paramJavaType.getRawClass().getName(), paramName);
sbMethod.append(code);
sbMethodGenericSignature.append(paramJavaType.getGenericSignature());
}
if (!operation.getParameters().isEmpty()) {
sbMethod.setLength(sbMethod.length() - 1);
}
sbMethod.append(");");
sbMethodGenericSignature.append(")");
sbMethodGenericSignature.append(resultJavaType.getGenericSignature());
if (hasGenericSignature) {
classConfig.addMethod(sbMethod.toString(), sbMethodGenericSignature.toString());
} else {
classConfig.addMethod(sbMethod.toString(), null);
}
}
}
return JavassistUtils.createClass(classLoader, classConfig);
}
use of io.swagger.models.Response in project java-chassis by ServiceComb.
the class OperationGenerator method scanResponse.
public void scanResponse() {
if (operation.getResponses() != null) {
Response successResponse = operation.getResponses().get(SwaggerConst.SUCCESS_KEY);
if (successResponse != null) {
if (successResponse.getSchema() == null) {
// 标注已经定义了response,但是是void,这可能是在标注上未定义
// 根据函数原型来处理response
Property property = createResponseProperty();
successResponse.setSchema(property);
}
return;
}
}
Property property = createResponseProperty();
Response response = new Response();
response.setSchema(property);
operation.addResponse(SwaggerConst.SUCCESS_KEY, response);
}
use of io.swagger.models.Response in project java-chassis by ServiceComb.
the class TestApiResponse method checkApiResponseHeader.
private void checkApiResponseHeader(SwaggerGenerator generator) {
Swagger swagger = generator.getSwagger();
Path path = swagger.getPaths().get("/testApiResponseHeader");
Operation operation = path.getOperations().get(0);
Assert.assertEquals("testApiResponseHeader", operation.getOperationId());
Response response = operation.getResponses().get("200");
Property property = response.getHeaders().get("k1");
Assert.assertEquals(Integer.class, ConverterMgr.findJavaType(generator, property).getRawClass());
property = response.getHeaders().get("k2");
Assert.assertEquals(String.class, ConverterMgr.findJavaType(generator, property).getRawClass());
}
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);
}
Aggregations