use of org.apache.servicecomb.swagger.generator.core.SwaggerGenerator in project incubator-servicecomb-java-chassis by apache.
the class UnitTestSwaggerUtils method generateSwagger.
public static SwaggerGenerator generateSwagger(Class<?> cls) {
SwaggerGeneratorContext context = compositeContext.selectContext(cls);
SwaggerGenerator generator = new SwaggerGenerator(context, cls);
generator.generate();
return generator;
}
use of org.apache.servicecomb.swagger.generator.core.SwaggerGenerator in project incubator-servicecomb-java-chassis by apache.
the class ClassUtils method getOrCreateBodyClass.
// 将一系列body parameter包装成一个class
public static Class<?> getOrCreateBodyClass(OperationGenerator operationGenerator, List<BodyParameter> bodyParameters) {
SwaggerGenerator swaggerGenerator = operationGenerator.getSwaggerGenerator();
Method method = operationGenerator.getProviderMethod();
String clsName = swaggerGenerator.ensureGetPackageName() + "." + method.getName() + "Body";
Class<?> cls = getClassByName(swaggerGenerator.getClassLoader(), clsName);
if (cls != null) {
return cls;
}
ClassConfig classConfig = new ClassConfig();
classConfig.setClassName(clsName);
// 2.预备body与明确body混合
for (BodyParameter bp : bodyParameters) {
JavaType javaType = ConverterMgr.findJavaType(swaggerGenerator.getClassLoader(), swaggerGenerator.ensureGetPackageName(), swaggerGenerator.getSwagger(), bp);
classConfig.addField(bp.getName(), javaType);
}
return JavassistUtils.createClass(swaggerGenerator.getClassLoader(), classConfig);
}
use of org.apache.servicecomb.swagger.generator.core.SwaggerGenerator in project incubator-servicecomb-java-chassis by apache.
the class ApiOperationProcessorTest method testConvertTags.
@Test
public void testConvertTags() throws NoSuchMethodException {
ApiOperationProcessor apiOperationProcessor = new ApiOperationProcessor();
Method function = TestClass.class.getMethod("function");
SwaggerGenerator swaggerGenerator = new SwaggerGenerator(new PojoSwaggerGeneratorContext(), TestClass.class);
OperationGenerator operationGenerator = new OperationGenerator(swaggerGenerator, function);
apiOperationProcessor.process(function.getAnnotation(ApiOperation.class), operationGenerator);
assertThat(operationGenerator.getOperation().getTags(), containsInAnyOrder("tag1", "tag2"));
}
use of org.apache.servicecomb.swagger.generator.core.SwaggerGenerator in project incubator-servicecomb-java-chassis by apache.
the class ApiOperationProcessorTest method testConvertTagsOnMethodWithNoTag.
@Test
public void testConvertTagsOnMethodWithNoTag() throws NoSuchMethodException {
ApiOperationProcessor apiOperationProcessor = new ApiOperationProcessor();
Method function = TestClass.class.getMethod("functionWithNoTag");
SwaggerGenerator swaggerGenerator = new SwaggerGenerator(new PojoSwaggerGeneratorContext(), TestClass.class);
OperationGenerator operationGenerator = new OperationGenerator(swaggerGenerator, function);
apiOperationProcessor.process(function.getAnnotation(ApiOperation.class), operationGenerator);
List<String> tagList = operationGenerator.getOperation().getTags();
assertNull(tagList);
}
use of org.apache.servicecomb.swagger.generator.core.SwaggerGenerator in project incubator-servicecomb-java-chassis by apache.
the class ApiProcessorTest method process.
@Test
public void process() {
SwaggerGenerator swaggerGenerator = new SwaggerGenerator(Mockito.mock(SwaggerGeneratorContext.class), null);
apiProcessor.process(SwaggerTestTarget.class.getAnnotation(Api.class), swaggerGenerator);
assertThat(swaggerGenerator.getDefaultTags(), contains("tag1", "tag2"));
}
Aggregations