Search in sources :

Example 1 with SwaggerOperation

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

the class ApiOperationProcessorTest method testBodyParam.

@Test
public void testBodyParam() {
    SwaggerOperation swaggerOperation = swaggerOperations.findOperation("testBodyParam");
    Map<String, Property> properties = swaggerOperation.getSwagger().getDefinitions().get("TestBodyBean").getProperties();
    assertTrue("Support NotBlank annotation", properties.get("age").getRequired());
    assertTrue("Support NotEmpty annotation", properties.get("sexes").getRequired());
    assertTrue("Original support NotNull annotation", properties.get("name").getRequired());
}
Also used : SwaggerOperation(org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation) Property(io.swagger.models.properties.Property) Test(org.junit.Test)

Example 2 with SwaggerOperation

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

the class ApiOperationProcessorTest method testConvertTagsOnMethodWithNoTag.

@Test
public void testConvertTagsOnMethodWithNoTag() {
    SwaggerOperation swaggerOperation = swaggerOperations.findOperation("functionWithNoTag");
    assertNull(swaggerOperation.getOperation().getTags());
}
Also used : SwaggerOperation(org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation) Test(org.junit.Test)

Example 3 with SwaggerOperation

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

the class ApiOperationProcessorTest method testConvertTags.

@Test
public void testConvertTags() {
    SwaggerOperation swaggerOperation = swaggerOperations.findOperation("function");
    assertThat(swaggerOperation.getOperation().getTags(), containsInAnyOrder("tag1", "tag2"));
}
Also used : SwaggerOperation(org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation) Test(org.junit.Test)

Example 4 with SwaggerOperation

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

the class ApiOperationProcessorTest method testMediaType.

@Test
public void testMediaType() {
    SwaggerOperation swaggerOperation = swaggerOperations.findOperation("testSingleMediaType");
    assertThat(swaggerOperation.getOperation().getConsumes(), Matchers.contains(MediaType.TEXT_PLAIN));
    assertThat(swaggerOperation.getOperation().getProduces(), Matchers.contains(MediaType.APPLICATION_XML));
    swaggerOperation = swaggerOperations.findOperation("testMultiMediaType");
    assertThat(swaggerOperation.getOperation().getConsumes(), Matchers.contains(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN));
    assertThat(swaggerOperation.getOperation().getProduces(), Matchers.contains(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML));
    swaggerOperation = swaggerOperations.findOperation("testBlankMediaType");
    assertNull(swaggerOperation.getOperation().getConsumes());
    assertNull(swaggerOperation.getOperation().getProduces());
    swaggerOperation.getOperation().addConsumes(MediaType.TEXT_HTML);
    swaggerOperation.getOperation().addProduces(MediaType.TEXT_HTML);
    assertThat(swaggerOperation.getOperation().getConsumes(), Matchers.contains(MediaType.TEXT_HTML));
    assertThat(swaggerOperation.getOperation().getProduces(), Matchers.contains(MediaType.TEXT_HTML));
}
Also used : SwaggerOperation(org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation) Test(org.junit.Test)

Example 5 with SwaggerOperation

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

the class TestApiResponse method checkResponseHeader.

@Test
public void checkResponseHeader() {
    SwaggerOperation swaggerOperation = swaggerOperations.findOperation("testResponseHeader");
    Assert.assertEquals("/testResponseHeader", swaggerOperation.getPath());
    Response response = swaggerOperation.getOperation().getResponses().get("200");
    Property property = response.getHeaders().get("k1");
    Assert.assertEquals("integer", property.getType());
    Assert.assertEquals("int32", property.getFormat());
}
Also used : Response(io.swagger.models.Response) ApiResponse(io.swagger.annotations.ApiResponse) SwaggerOperation(org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation) Property(io.swagger.models.properties.Property) Test(org.junit.Test)

Aggregations

SwaggerOperation (org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation)18 Test (org.junit.Test)16 ApiResponse (io.swagger.annotations.ApiResponse)7 Response (io.swagger.models.Response)7 SwaggerOperations (org.apache.servicecomb.swagger.generator.core.model.SwaggerOperations)5 Property (io.swagger.models.properties.Property)3 Method (java.lang.reflect.Method)2 ContextArgumentMapperFactory (org.apache.servicecomb.swagger.invocation.arguments.ContextArgumentMapperFactory)2 ConsumerContextArgumentMapperFactory (org.apache.servicecomb.swagger.invocation.arguments.consumer.ConsumerContextArgumentMapperFactory)2 ProducerArgumentsMapper (org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapper)2 ProducerContextArgumentMapperFactory (org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerContextArgumentMapperFactory)2 ResponseMapperFactorys (org.apache.servicecomb.swagger.invocation.response.ResponseMapperFactorys)2 ModelImpl (io.swagger.models.ModelImpl)1 BodyParameter (io.swagger.models.parameters.BodyParameter)1 ByteArrayProperty (io.swagger.models.properties.ByteArrayProperty)1 ArgumentsMapper (org.apache.servicecomb.swagger.invocation.arguments.ArgumentsMapper)1 ConsumerArgumentsMapperCreator (org.apache.servicecomb.swagger.invocation.arguments.consumer.ConsumerArgumentsMapperCreator)1 ProducerArgumentsMapperCreator (org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapperCreator)1 ConsumerResponseMapper (org.apache.servicecomb.swagger.invocation.response.consumer.ConsumerResponseMapper)1 ProducerResponseMapper (org.apache.servicecomb.swagger.invocation.response.producer.ProducerResponseMapper)1