Search in sources :

Example 6 with SwaggerGenerator

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;
}
Also used : SwaggerGenerator(io.servicecomb.swagger.generator.core.SwaggerGenerator) CompositeSwaggerGeneratorContext(io.servicecomb.swagger.generator.core.CompositeSwaggerGeneratorContext) SwaggerGeneratorContext(io.servicecomb.swagger.generator.core.SwaggerGeneratorContext)

Example 7 with SwaggerGenerator

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());
}
Also used : SwaggerGenerator(io.servicecomb.swagger.generator.core.SwaggerGenerator) Swagger(io.swagger.models.Swagger) Operation(io.swagger.models.Operation) Test(org.junit.Test)

Example 8 with SwaggerGenerator

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/"));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) SwaggerGenerator(io.servicecomb.swagger.generator.core.SwaggerGenerator) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) Swagger(io.swagger.models.Swagger) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta) ArrayList(java.util.ArrayList) ServicePathManager(io.servicecomb.common.rest.locator.ServicePathManager) Test(org.junit.Test)

Aggregations

SwaggerGenerator (io.servicecomb.swagger.generator.core.SwaggerGenerator)8 Swagger (io.swagger.models.Swagger)3 CompositeSwaggerGeneratorContext (io.servicecomb.swagger.generator.core.CompositeSwaggerGeneratorContext)2 SwaggerGeneratorContext (io.servicecomb.swagger.generator.core.SwaggerGeneratorContext)2 Method (java.lang.reflect.Method)2 Test (org.junit.Test)2 JavaType (com.fasterxml.jackson.databind.JavaType)1 ClassConfig (io.servicecomb.common.javassist.ClassConfig)1 ServicePathManager (io.servicecomb.common.rest.locator.ServicePathManager)1 MicroserviceMeta (io.servicecomb.core.definition.MicroserviceMeta)1 OperationMeta (io.servicecomb.core.definition.OperationMeta)1 SchemaMeta (io.servicecomb.core.definition.SchemaMeta)1 ConsumerOperationMeta (io.servicecomb.core.provider.consumer.ConsumerOperationMeta)1 OperationGenerator (io.servicecomb.swagger.generator.core.OperationGenerator)1 ConsumerArgumentsMapper (io.servicecomb.swagger.invocation.arguments.consumer.ConsumerArgumentsMapper)1 Operation (io.swagger.models.Operation)1 BodyParameter (io.swagger.models.parameters.BodyParameter)1 Parameter (io.swagger.models.parameters.Parameter)1 ArrayList (java.util.ArrayList)1 ApplicationContext (org.springframework.context.ApplicationContext)1