use of org.apache.servicecomb.swagger.generator.core.SwaggerGenerator in project incubator-servicecomb-java-chassis by apache.
the class ProducerSchemaFactory method createSchema.
protected SchemaMeta createSchema(ProducerSchemaContext context) {
// 尝试从规划的目录加载契约
Swagger swagger = loadSwagger(context);
if (swagger == null) {
Set<String> combinedNames = RegistryUtils.getServiceRegistry().getCombinedMicroserviceNames();
for (String name : combinedNames) {
swagger = loadSwagger(name, context.getSchemaId());
if (swagger != null) {
break;
}
}
}
// 根据class动态产生契约
SwaggerGenerator generator = generateSwagger(context);
if (swagger == null) {
swagger = generator.getSwagger();
String swaggerContent = getSwaggerContent(swagger);
LOGGER.info("generate swagger for {}/{}/{}, swagger: {}", context.getMicroserviceMeta().getAppId(), context.getMicroserviceName(), context.getSchemaId(), swaggerContent);
}
// 注册契约
return schemaLoader.registerSchema(context.getMicroserviceMeta(), context.getSchemaId(), swagger);
}
use of org.apache.servicecomb.swagger.generator.core.SwaggerGenerator in project incubator-servicecomb-java-chassis by apache.
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 org.apache.servicecomb.swagger.generator.core.SwaggerGenerator in project incubator-servicecomb-java-chassis by apache.
the class SwaggerEnvironment method createProducer.
public SwaggerProducer createProducer(Object producerInstance) {
Class<?> producerCls = BeanUtils.getImplClassFromBean(producerInstance);
SwaggerGenerator producerGenerator = UnitTestSwaggerUtils.generateSwagger(producerCls);
Swagger swagger = producerGenerator.getSwagger();
return createProducer(producerInstance, swagger);
}
Aggregations