use of io.servicecomb.swagger.generator.core.SwaggerGenerator in project java-chassis by ServiceComb.
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 io.servicecomb.swagger.generator.core.SwaggerGenerator in project java-chassis by ServiceComb.
the class TestResponsesMeta method test.
@Test
public void test() {
SwaggerGenerator generator = UnitTestSwaggerUtils.generateSwagger(ResponseMetaImpl.class);
Swagger swagger = generator.getSwagger();
Operation operation = swagger.getPath("/add").getPost();
ResponsesMeta meta = new ResponsesMeta();
meta.init(null, "gen", swagger, operation, int.class);
ResponseMeta resp = meta.findResponseMeta(200);
Assert.assertEquals(int.class, resp.getJavaType().getRawClass());
resp = meta.findResponseMeta(201);
Assert.assertEquals(int.class, resp.getJavaType().getRawClass());
resp = meta.findResponseMeta(400);
Assert.assertEquals(String.class, resp.getJavaType().getRawClass());
resp = meta.findResponseMeta(401);
Assert.assertEquals(Long.class, resp.getJavaType().getRawClass());
Assert.assertEquals(Integer.class, resp.getHeaders().get("h1").getRawClass());
resp = meta.findResponseMeta(500);
Assert.assertEquals(CommonExceptionData.class, resp.getJavaType().getRawClass());
}
use of io.servicecomb.swagger.generator.core.SwaggerGenerator in project java-chassis by ServiceComb.
the class TestRestEngineSchemaListener method test.
@Test
public void test() {
BeanUtils.setContext(Mockito.mock(ApplicationContext.class));
MicroserviceMeta mm = new MicroserviceMeta("app:ms");
List<SchemaMeta> smList = new ArrayList<>();
SwaggerGenerator generator = new SwaggerGenerator(context, Impl.class);
Swagger swagger = generator.generate();
SchemaMeta sm1 = new SchemaMeta(swagger, mm, "sid1");
smList.add(sm1);
RestEngineSchemaListener listener = new RestEngineSchemaListener();
SchemaMeta[] smArr = smList.toArray(new SchemaMeta[smList.size()]);
listener.onSchemaLoaded(smArr);
// 重复调用,不应该出异常
listener.onSchemaLoaded(smArr);
ServicePathManager spm = ServicePathManager.getServicePathManager(mm);
Assert.assertEquals(mm, spm.getMicroserviceMeta());
Assert.assertNotNull(spm.getStaticPathOperationMap().get("Impl/add/"));
}
Aggregations