use of org.apache.servicecomb.swagger.generator.core.SwaggerGenerator in project incubator-servicecomb-java-chassis by apache.
the class SwaggerDefinitionProcessorTest method testProcess.
@Test
public void testProcess() {
SwaggerGenerator swaggerGenerator = new SwaggerGenerator(Mockito.mock(SwaggerGeneratorContext.class), null);
swaggerDefinitionProcessor.process(SwaggerTestTarget.class.getAnnotation(SwaggerDefinition.class), swaggerGenerator);
Swagger swagger = swaggerGenerator.getSwagger();
assertEquals(1, swagger.getTags().size());
io.swagger.models.Tag tag = swagger.getTags().get(0);
assertEquals("testTag", tag.getName());
assertEquals("desc", tag.getDescription());
assertEquals("testValue", tag.getExternalDocs().getDescription());
assertEquals("testUrl", tag.getExternalDocs().getUrl());
assertEquals("127.0.0.1", swagger.getHost());
assertThat(swagger.getSchemes(), contains(io.swagger.models.Scheme.HTTP, io.swagger.models.Scheme.HTTPS));
io.swagger.models.Info info = swagger.getInfo();
assertEquals("title", info.getTitle());
assertEquals("version", info.getVersion());
assertEquals("desc", info.getDescription());
assertEquals("contactName", info.getContact().getName());
assertEquals("licenseName", info.getLicense().getName());
}
use of org.apache.servicecomb.swagger.generator.core.SwaggerGenerator in project incubator-servicecomb-java-chassis by apache.
the class AbstractSchemaFactory method generateSwagger.
protected SwaggerGenerator generateSwagger(CONTEXT context) {
SwaggerGeneratorContext generatorContext = compositeSwaggerGeneratorContext.selectContext(context.getProviderClass());
SwaggerGenerator generator = new SwaggerGenerator(generatorContext, context.getProviderClass());
generator.setClassLoader(context.getMicroserviceMeta().getClassLoader());
generator.setPackageName(SchemaUtils.generatePackageName(context.getMicroserviceMeta(), context.getSchemaId()));
generator.generate();
// 确保接口是存在的
ClassUtils.getOrCreateInterface(generator);
return generator;
}
use of org.apache.servicecomb.swagger.generator.core.SwaggerGenerator in project incubator-servicecomb-java-chassis by apache.
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, TestRestEngineSchemaListenerSchemaImpl.class);
Swagger swagger = generator.generate();
swagger.setBasePath("");
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.assertSame(sm1, spm.consumerLocateOperation("/add/", "POST").getOperation().getOperationMeta().getSchemaMeta());
}
use of org.apache.servicecomb.swagger.generator.core.SwaggerGenerator in project incubator-servicecomb-java-chassis by apache.
the class TestOperationInstancesDiscoveryFilter method regMicroservice.
private Microservice regMicroservice(String serviceId, String version, Class<?> schemaCls, int instanceCount) {
String schemaId = "sid";
Microservice microservice = new Microservice();
microservice.setServiceId(serviceId);
microservice.setAppId(appId);
microservice.setServiceName(microserviceName);
microservice.setVersion(version);
microservice.setSchemas(Arrays.asList(schemaId));
serviceRegistry.getServiceRegistryClient().registerMicroservice(microservice);
SwaggerGenerator generator = new SwaggerGenerator(swaggerGeneratorContext, schemaCls);
String schemaContent = SwaggerUtils.swaggerToString(generator.generate());
serviceRegistry.getServiceRegistryClient().registerSchema(serviceId, schemaId, schemaContent);
for (int idx = 0; idx < instanceCount; idx++) {
MicroserviceInstance instance = createInstance(serviceId);
serviceRegistry.getServiceRegistryClient().registerMicroserviceInstance(instance);
}
return microservice;
}
use of org.apache.servicecomb.swagger.generator.core.SwaggerGenerator in project incubator-servicecomb-java-chassis by apache.
the class ApiProcessorTest method processOnNoTag.
@Test
public void processOnNoTag() {
SwaggerGenerator swaggerGenerator = new SwaggerGenerator(Mockito.mock(SwaggerGeneratorContext.class), null);
apiProcessor.process(SwaggerTestTargetWithNoTag.class.getAnnotation(Api.class), swaggerGenerator);
Set<String> tags = swaggerGenerator.getDefaultTags();
assertEquals(0, tags.size());
}
Aggregations