Search in sources :

Example 76 with Swagger

use of io.swagger.models.Swagger 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 77 with Swagger

use of io.swagger.models.Swagger 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 78 with Swagger

use of io.swagger.models.Swagger 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 79 with Swagger

use of io.swagger.models.Swagger 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 80 with Swagger

use of io.swagger.models.Swagger in project java-chassis by ServiceComb.

the class TestApiResponse method checkApiResponseHeader.

private void checkApiResponseHeader(SwaggerGenerator generator) {
    Swagger swagger = generator.getSwagger();
    Path path = swagger.getPaths().get("/testApiResponseHeader");
    Operation operation = path.getOperations().get(0);
    Assert.assertEquals("testApiResponseHeader", operation.getOperationId());
    Response response = operation.getResponses().get("200");
    Property property = response.getHeaders().get("k1");
    Assert.assertEquals(Integer.class, ConverterMgr.findJavaType(generator, property).getRawClass());
    property = response.getHeaders().get("k2");
    Assert.assertEquals(String.class, ConverterMgr.findJavaType(generator, property).getRawClass());
}
Also used : Path(io.swagger.models.Path) Response(io.swagger.models.Response) ApiResponse(io.swagger.annotations.ApiResponse) Swagger(io.swagger.models.Swagger) Operation(io.swagger.models.Operation) Property(io.swagger.models.properties.Property)

Aggregations

Swagger (io.swagger.models.Swagger)184 Test (org.testng.annotations.Test)115 Operation (io.swagger.models.Operation)45 Parameter (io.swagger.models.parameters.Parameter)33 QueryParameter (io.swagger.models.parameters.QueryParameter)33 BodyParameter (io.swagger.models.parameters.BodyParameter)29 Path (io.swagger.models.Path)26 PathParameter (io.swagger.models.parameters.PathParameter)25 Reader (io.swagger.jaxrs.Reader)23 SpecFilter (io.swagger.core.filter.SpecFilter)21 Test (org.junit.Test)19 SwaggerParser (io.swagger.parser.SwaggerParser)16 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)16 Response (io.swagger.models.Response)14 SerializableParameter (io.swagger.models.parameters.SerializableParameter)14 HashMap (java.util.HashMap)14 Info (io.swagger.models.Info)12 Map (java.util.Map)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 Model (io.swagger.models.Model)10