Search in sources :

Example 81 with Response

use of io.swagger.models.Response in project syndesis by syndesisio.

the class UnifiedXmlDataShapeGenerator method createResponseBodySchema.

private static Element createResponseBodySchema(final Swagger swagger, final Operation operation, final Map<String, SchemaPrefixAndElement> moreSchemas) {
    final Optional<Response> maybeResponse = findResponse(operation);
    if (!maybeResponse.isPresent()) {
        return null;
    }
    final Response body = maybeResponse.get();
    final Property bodySchema = body.getSchema();
    if (bodySchema instanceof RefProperty) {
        return defineComplexElement((RefProperty) bodySchema, null, swagger, moreSchemas);
    } else if (bodySchema instanceof ArrayProperty) {
        final ArrayProperty array = (ArrayProperty) bodySchema;
        final String targetNamespace = xmlTargetNamespaceOrNull(array);
        final Element schema = newXmlSchema(targetNamespace);
        defineElementProperty(ofNullable(array.getName()).orElse("array"), array, schema, swagger, moreSchemas);
        return schema;
    } else {
        throw new IllegalArgumentException("Unsupported response schema type: " + bodySchema);
    }
}
Also used : Response(io.swagger.models.Response) ArrayProperty(io.swagger.models.properties.ArrayProperty) XmlSchemaHelper.isElement(io.syndesis.server.connector.generator.swagger.util.XmlSchemaHelper.isElement) XmlSchemaHelper.addElement(io.syndesis.server.connector.generator.swagger.util.XmlSchemaHelper.addElement) Element(org.dom4j.Element) ArrayProperty(io.swagger.models.properties.ArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) RefProperty(io.swagger.models.properties.RefProperty)

Example 82 with Response

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

the class TestApiResponse method checkSingle.

@Test
public void checkSingle() {
    SwaggerOperation swaggerOperation = swaggerOperations.findOperation("testSingle");
    Assert.assertEquals("/testSingle", swaggerOperation.getPath());
    Response response = swaggerOperation.getOperation().getResponses().get("200");
    Assert.assertEquals("integer", ((ModelImpl) response.getResponseSchema()).getType());
    Assert.assertEquals("int32", ((ModelImpl) response.getResponseSchema()).getFormat());
}
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 83 with Response

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

the class TestApiResponse method checkMulti.

@Test
public void checkMulti() {
    SwaggerOperation swaggerOperation = swaggerOperations.findOperation("testMulti");
    Assert.assertEquals("/testMulti", swaggerOperation.getPath());
    Response response = swaggerOperation.getOperation().getResponses().get("200");
    Assert.assertEquals("integer", ((ModelImpl) response.getResponseSchema()).getType());
    Assert.assertEquals("int32", ((ModelImpl) response.getResponseSchema()).getFormat());
    response = swaggerOperation.getOperation().getResponses().get("301");
    Assert.assertEquals("string", ((ModelImpl) response.getResponseSchema()).getType());
    Assert.assertNull(((ModelImpl) response.getResponseSchema()).getFormat());
}
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 84 with Response

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

the class TestApiResponse method checkApiResponseHeader.

@Test
public void checkApiResponseHeader() {
    SwaggerOperation swaggerOperation = swaggerOperations.findOperation("testApiResponseHeader");
    Assert.assertEquals("/testApiResponseHeader", 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());
    property = response.getHeaders().get("k2");
    Assert.assertEquals("string", property.getType());
    Assert.assertNull(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)

Example 85 with Response

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

the class TestOperationGenerator method responseThenApiOperation.

@Test
public void responseThenApiOperation() {
    SwaggerOperation swaggerOperation = swaggerOperations.findOperation("responseThenApiOperation");
    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.assertNotNull(response.getHeaders().get("x-user-domain"));
    Assert.assertNull(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)

Aggregations

Response (io.swagger.models.Response)93 Operation (io.swagger.models.Operation)51 Property (io.swagger.models.properties.Property)30 Path (io.swagger.models.Path)29 Swagger (io.swagger.models.Swagger)29 ApiResponse (io.swagger.annotations.ApiResponse)24 Test (org.testng.annotations.Test)23 RefProperty (io.swagger.models.properties.RefProperty)21 ArrayProperty (io.swagger.models.properties.ArrayProperty)20 Test (org.junit.Test)17 MapProperty (io.swagger.models.properties.MapProperty)14 Parameter (io.swagger.models.parameters.Parameter)13 Model (io.swagger.models.Model)12 BodyParameter (io.swagger.models.parameters.BodyParameter)12 StringProperty (io.swagger.models.properties.StringProperty)12 HashMap (java.util.HashMap)12 RefModel (io.swagger.models.RefModel)10 PathParameter (io.swagger.models.parameters.PathParameter)10 IntegerProperty (io.swagger.models.properties.IntegerProperty)10 QueryParameter (io.swagger.models.parameters.QueryParameter)9