Search in sources :

Example 31 with SwaggerOperation

use of org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation in project java-chassis by ServiceComb.

the class ApiProcessorTest method process.

@Test
public void process() {
    SwaggerOperations swaggerOperations = SwaggerOperations.generate(SwaggerTestTarget.class);
    SwaggerOperation swaggerOperation = swaggerOperations.findOperation("op");
    assertThat(swaggerOperation.getOperation().getTags(), contains("tag1", "tag2"));
    assertThat(swaggerOperation.getSwagger().getConsumes(), Matchers.contains(MediaType.APPLICATION_JSON));
    assertThat(swaggerOperation.getSwagger().getProduces(), Matchers.contains(MediaType.APPLICATION_JSON));
}
Also used : SwaggerOperations(org.apache.servicecomb.swagger.generator.core.model.SwaggerOperations) SwaggerOperation(org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation) Test(org.junit.Test)

Example 32 with SwaggerOperation

use of org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation in project incubator-servicecomb-java-chassis by apache.

the class TestOperationGenerator method apiOperationThenResponse.

@Test
public void apiOperationThenResponse() throws NoSuchMethodException {
    SwaggerOperation swaggerOperation = swaggerOperations.findOperation("apiOperationThenResponse");
    List<String> tags = swaggerOperation.getOperation().getTags();
    assertThat(tags, contains("tag1", "tag2"));
    Response response = swaggerOperation.getOperation().getResponses().get("200");
    assertEquals("200 is ok............", response.getDescription());
    Assert.assertNull(response.getHeaders().get("x-user-domain"));
    Assert.assertNotNull(response.getHeaders().get("x-user-name"));
    Assert.assertNotNull(swaggerOperation.getOperation().getVendorExtensions().get("x-class-name"));
}
Also used : Response(io.swagger.models.Response) ApiResponse(io.swagger.annotations.ApiResponse) SwaggerOperation(org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation) Test(org.junit.Test)

Example 33 with SwaggerOperation

use of org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation in project incubator-servicecomb-java-chassis by apache.

the class TestOperationGenerator method apiOperationNoTag.

@Test
public void apiOperationNoTag() {
    SwaggerOperation operation = swaggerOperations.findOperation("apiOperationNoTag");
    List<String> tags = operation.getOperation().getTags();
    assertThat(tags, contains("default0", "default1"));
    assertEquals("value2", operation.getOperation().getSummary());
}
Also used : SwaggerOperation(org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation) Test(org.junit.Test)

Example 34 with SwaggerOperation

use of org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation in project incubator-servicecomb-java-chassis by apache.

the class TestArrayType method test.

@Test
public void test() {
    SwaggerOperations swaggerOperations = SwaggerOperations.generate(ArrayType.class);
    SwaggerOperation swaggerOperation = swaggerOperations.findOperation("testBytes");
    BodyParameter bodyParameter = (BodyParameter) swaggerOperation.getOperation().getParameters().get(0);
    ModelImpl model = SwaggerUtils.getModelImpl(swaggerOperations.getSwagger(), bodyParameter);
    Assert.assertEquals(ModelImpl.OBJECT, model.getType());
    Assert.assertEquals(1, model.getProperties().size());
    ByteArrayProperty byteArrayProperty = (ByteArrayProperty) model.getProperties().get("value");
    Assert.assertEquals("string", byteArrayProperty.getType());
    Assert.assertEquals("byte", byteArrayProperty.getFormat());
}
Also used : ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) SwaggerOperations(org.apache.servicecomb.swagger.generator.core.model.SwaggerOperations) SwaggerOperation(org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation) BodyParameter(io.swagger.models.parameters.BodyParameter) ModelImpl(io.swagger.models.ModelImpl) Test(org.junit.Test)

Example 35 with SwaggerOperation

use of org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation in project incubator-servicecomb-java-chassis by apache.

the class ApiProcessorTest method processOnNoTag.

@Test
public void processOnNoTag() {
    SwaggerOperations swaggerOperations = SwaggerOperations.generate(SwaggerTestTargetWithNoTag.class);
    SwaggerOperation swaggerOperation = swaggerOperations.findOperation("op");
    assertNull(swaggerOperation.getOperation().getTags());
    assertThat(swaggerOperation.getSwagger().getConsumes(), Matchers.contains(MediaType.APPLICATION_JSON));
    assertThat(swaggerOperation.getSwagger().getProduces(), Matchers.contains(MediaType.APPLICATION_JSON));
}
Also used : SwaggerOperations(org.apache.servicecomb.swagger.generator.core.model.SwaggerOperations) SwaggerOperation(org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation) Test(org.junit.Test)

Aggregations

SwaggerOperation (org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation)36 Test (org.junit.Test)32 ApiResponse (io.swagger.annotations.ApiResponse)14 Response (io.swagger.models.Response)14 SwaggerOperations (org.apache.servicecomb.swagger.generator.core.model.SwaggerOperations)10 Property (io.swagger.models.properties.Property)6 Method (java.lang.reflect.Method)4 ContextArgumentMapperFactory (org.apache.servicecomb.swagger.invocation.arguments.ContextArgumentMapperFactory)4 ConsumerContextArgumentMapperFactory (org.apache.servicecomb.swagger.invocation.arguments.consumer.ConsumerContextArgumentMapperFactory)4 ProducerArgumentsMapper (org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapper)4 ProducerContextArgumentMapperFactory (org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerContextArgumentMapperFactory)4 ResponseMapperFactorys (org.apache.servicecomb.swagger.invocation.response.ResponseMapperFactorys)4 ModelImpl (io.swagger.models.ModelImpl)2 BodyParameter (io.swagger.models.parameters.BodyParameter)2 ByteArrayProperty (io.swagger.models.properties.ByteArrayProperty)2 ArgumentsMapper (org.apache.servicecomb.swagger.invocation.arguments.ArgumentsMapper)2 ConsumerArgumentsMapperCreator (org.apache.servicecomb.swagger.invocation.arguments.consumer.ConsumerArgumentsMapperCreator)2 ProducerArgumentsMapperCreator (org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapperCreator)2 ConsumerResponseMapper (org.apache.servicecomb.swagger.invocation.response.consumer.ConsumerResponseMapper)2 ProducerResponseMapper (org.apache.servicecomb.swagger.invocation.response.producer.ProducerResponseMapper)2