Search in sources :

Example 1 with SwaggerGeneratorForTest

use of io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest in project java-chassis by ServiceComb.

the class TestSwaggerDefinition method testFillDefault.

@Test
public void testFillDefault() {
    SwaggerGenerator swaggerGenerator = new SwaggerGeneratorForTest(context, SwaggerNoAnnotation.class);
    swaggerGenerator.generate();
    swaggerGenerator.correctSwagger();
    Swagger swagger = swaggerGenerator.getSwagger();
    Assert.assertEquals("2.0", swagger.getSwagger());
    Assert.assertEquals("/SwaggerNoAnnotation", swagger.getBasePath());
    Assert.assertEquals("swagger definition for " + SwaggerNoAnnotation.class.getName(), swagger.getInfo().getTitle());
}
Also used : Swagger(io.swagger.models.Swagger) SwaggerGeneratorForTest(io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest) Test(org.junit.Test) SwaggerGeneratorForTest(io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest)

Example 2 with SwaggerGeneratorForTest

use of io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest in project java-chassis by ServiceComb.

the class TestSwaggerDefinition method testSwaggerDefinition.

@SuppressWarnings("unchecked")
@Test
public void testSwaggerDefinition() {
    SwaggerGenerator swaggerGenerator = new SwaggerGeneratorForTest(context, SwaggerAnnotation.class);
    swaggerGenerator.generate();
    Swagger swagger = swaggerGenerator.getSwagger();
    Assert.assertEquals(SwaggerAnnotation.class.getName(), swagger.getInfo().getVendorExtensions().get(SwaggerConst.EXT_JAVA_INTF));
    Assert.assertEquals("2.0", swagger.getSwagger());
    Assert.assertEquals("/base", swagger.getBasePath());
    Assert.assertEquals("host", swagger.getHost());
    Assert.assertEquals(Arrays.asList("json", "xml"), swagger.getConsumes());
    Assert.assertEquals(Arrays.asList("abc", "123"), swagger.getProduces());
    Assert.assertEquals(1, swagger.getTags().size());
    io.swagger.models.Tag tagA = swagger.getTags().get(0);
    Assert.assertEquals("tagA", tagA.getName());
    Assert.assertEquals("desc of tagA", tagA.getDescription());
    Assert.assertEquals("tagA ext docs", tagA.getExternalDocs().getDescription());
    Assert.assertEquals("url of tagA ext docs", tagA.getExternalDocs().getUrl());
    Assert.assertEquals(1, tagA.getVendorExtensions().size());
    Map<String, Object> tagValue = (Map<String, Object>) tagA.getVendorExtensions().get("x-tagA");
    Assert.assertEquals("value of tagAExt", tagValue.get("x-tagAExt"));
    io.swagger.models.Info info = swagger.getInfo();
    Assert.assertEquals("title of SwaggerAnnotation", info.getTitle());
    Assert.assertEquals("0.1", info.getVersion());
    Assert.assertEquals("termsOfService", info.getTermsOfService());
    Assert.assertEquals("description of info for SwaggerAnnotation", info.getDescription());
    Assert.assertEquals("contact", info.getContact().getName());
    Assert.assertEquals("contact@email.com", info.getContact().getEmail());
    Assert.assertEquals("http://contact", info.getContact().getUrl());
    Assert.assertEquals("license ", info.getLicense().getName());
    Assert.assertEquals("http://license", info.getLicense().getUrl());
    Assert.assertEquals(2, info.getVendorExtensions().size());
    Map<String, Object> infoValue = (Map<String, Object>) info.getVendorExtensions().get("x-info");
    Assert.assertEquals("value of infoExt", infoValue.get("x-infoExt"));
    Assert.assertEquals("SwaggerAnnotation ext docs", swagger.getExternalDocs().getDescription());
    Assert.assertEquals("url of SwaggerAnnotation ext docs", swagger.getExternalDocs().getUrl());
}
Also used : Swagger(io.swagger.models.Swagger) Map(java.util.Map) SwaggerGeneratorForTest(io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest) Test(org.junit.Test) SwaggerGeneratorForTest(io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest)

Example 3 with SwaggerGeneratorForTest

use of io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest in project java-chassis by ServiceComb.

the class TestSwaggerUtils method testConverter.

@Test
public void testConverter() {
    SwaggerGenerator generator = new SwaggerGeneratorForTest(context, null);
    Swagger swagger = generator.getSwagger();
    ParamUtils.addDefinitions(swagger, User.class);
    Model model = swagger.getDefinitions().get("User");
    model.getVendorExtensions().clear();
    JavaType javaType = ConverterMgr.findJavaType(generator, model);
    checkJavaType(swagger, javaType);
    RefModel refModel = new RefModel();
    refModel.setReference("User");
    javaType = ConverterMgr.findJavaType(generator, refModel);
    checkJavaType(swagger, javaType);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) RefModel(io.swagger.models.RefModel) Swagger(io.swagger.models.Swagger) RefModel(io.swagger.models.RefModel) Model(io.swagger.models.Model) SwaggerGeneratorForTest(io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest) Test(org.junit.Test) SwaggerGeneratorForTest(io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest)

Example 4 with SwaggerGeneratorForTest

use of io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest in project java-chassis by ServiceComb.

the class TestApiOperation method testApiOperation.

@Test
public void testApiOperation() {
    SwaggerGenerator swaggerGenerator = new SwaggerGeneratorForTest(context, ApiOperationAnnotation.class);
    swaggerGenerator.generate();
    Swagger swagger = swaggerGenerator.getSwagger();
    testBase(swagger.getPath("/test"));
    testPrimitive(swagger.getPath("/testPrimitive"));
    testMap(swagger.getPath("/testMap"));
    testList(swagger.getPath("/testList"));
    testSet(swagger.getPath("/testSet"));
}
Also used : Swagger(io.swagger.models.Swagger) SwaggerGeneratorForTest(io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest) Test(org.junit.Test) SwaggerGeneratorForTest(io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest)

Example 5 with SwaggerGeneratorForTest

use of io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest in project java-chassis by ServiceComb.

the class TestApiImplicitParams method testBody.

@Test
public void testBody() {
    SwaggerGenerator swaggerGenerator = new SwaggerGeneratorForTest(context, ApiImplicitParamsAnnotation.class);
    swaggerGenerator.generate();
    Swagger swagger = swaggerGenerator.getSwagger();
    Path path = swagger.getPaths().get("/testBody");
    Operation operation = path.getOperations().get(0);
    Parameter parameter = operation.getParameters().get(0);
    JavaType javaType = ConverterMgr.findJavaType(swaggerGenerator, parameter);
    Assert.assertEquals(User.class, javaType.getRawClass());
}
Also used : Path(io.swagger.models.Path) JavaType(com.fasterxml.jackson.databind.JavaType) Swagger(io.swagger.models.Swagger) Parameter(io.swagger.models.parameters.Parameter) Operation(io.swagger.models.Operation) SwaggerGeneratorForTest(io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest) SwaggerGeneratorForTest(io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest) Test(org.junit.Test)

Aggregations

SwaggerGeneratorForTest (io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest)6 Test (org.junit.Test)6 Swagger (io.swagger.models.Swagger)5 JavaType (com.fasterxml.jackson.databind.JavaType)3 StringPropertyConverter (io.servicecomb.swagger.converter.property.StringPropertyConverter)1 Model (io.swagger.models.Model)1 Operation (io.swagger.models.Operation)1 Path (io.swagger.models.Path)1 RefModel (io.swagger.models.RefModel)1 Parameter (io.swagger.models.parameters.Parameter)1 StringProperty (io.swagger.models.properties.StringProperty)1 Map (java.util.Map)1