Search in sources :

Example 16 with ArrayModel

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

the class TestApiOperation method testList.

private void testList(Path path) {
    Operation operation = path.getPost();
    Model result200 = operation.getResponses().get("200").getResponseSchema();
    Assert.assertEquals(ArrayModel.class, result200.getClass());
    Assert.assertEquals(null, ((ArrayModel) result200).getUniqueItems());
}
Also used : Model(io.swagger.models.Model) ArrayModel(io.swagger.models.ArrayModel) ApiOperation(io.swagger.annotations.ApiOperation) Operation(io.swagger.models.Operation)

Example 17 with ArrayModel

use of io.swagger.models.ArrayModel in project swagger-core by swagger-api.

the class ModelSerializerTest method serializeArrayModel.

@Test(description = "it should serialize an array model")
public void serializeArrayModel() throws IOException {
    final ArrayModel model = new ArrayModel();
    model.setItems(new RefProperty("Pet"));
    assertEquals(m.writeValueAsString(model), "{\"type\":\"array\",\"items\":{\"$ref\":\"#/definitions/Pet\"}}");
}
Also used : ArrayModel(io.swagger.models.ArrayModel) RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

Example 18 with ArrayModel

use of io.swagger.models.ArrayModel in project swagger-core by swagger-api.

the class SimpleReaderTest method checkResponseModelsProcessing.

@Test(description = "check response models processing")
public void checkResponseModelsProcessing() {
    Swagger swagger = getSwagger(ResourceWithTypedResponses.class);
    assertEquals(swagger.getDefinitions().keySet(), Arrays.asList("Tag"));
    for (Map.Entry<String, Path> entry : swagger.getPaths().entrySet()) {
        String name = entry.getKey().substring(entry.getKey().lastIndexOf("/") + 1);
        if ("testPrimitiveResponses".equals(name)) {
            Map<String, String[]> expected = ImmutableMap.of("400", new String[] { "string", "uri" }, "401", new String[] { "string", "url" }, "402", new String[] { "string", "uuid" }, "403", new String[] { "integer", "int64" }, "404", new String[] { "string", null });
            assertEquals(entry.getValue().getGet().getResponses().size(), expected.size());
            for (Map.Entry<String, Response> responseEntry : entry.getValue().getGet().getResponses().entrySet()) {
                String[] expectedProp = expected.get(responseEntry.getKey());
                Property property = responseEntry.getValue().getSchema();
                assertEquals(property.getType(), expectedProp[0]);
                assertEquals(property.getFormat(), expectedProp[1]);
            }
        } else {
            Operation op = entry.getValue().getGet();
            Property response = op.getResponses().get("200").getSchema();
            Model model = ((BodyParameter) op.getParameters().get(0)).getSchema();
            assertEquals(op.getParameters().size(), 1);
            if ("testObjectResponse".equals(name)) {
                assertEquals(((RefProperty) response).getSimpleRef(), "Tag");
                assertEquals(((RefModel) model).getSimpleRef(), "Tag");
            } else if ("testObjectsResponse".equals(name)) {
                assertEquals(((RefProperty) ((ArrayProperty) response).getItems()).getSimpleRef(), "Tag");
                assertEquals(((RefProperty) ((ArrayModel) model).getItems()).getSimpleRef(), "Tag");
            } else if ("testStringResponse".equals(name)) {
                assertEquals(response.getClass(), StringProperty.class);
                assertEquals(((ModelImpl) model).getType(), "string");
            } else if ("testStringsResponse".equals(name)) {
                assertEquals(((ArrayProperty) response).getItems().getClass(), StringProperty.class);
                assertEquals(((ArrayModel) model).getItems().getClass(), StringProperty.class);
            } else if ("testMapResponse".equals(name)) {
                assertEquals(((RefProperty) ((MapProperty) response).getAdditionalProperties()).getSimpleRef(), "Tag");
                assertNull(model.getProperties());
                assertEquals(((RefProperty) ((ModelImpl) model).getAdditionalProperties()).getSimpleRef(), "Tag");
            } else {
                fail(String.format("Unexpected property: %s", name));
            }
        }
    }
}
Also used : Path(io.swagger.models.Path) MapProperty(io.swagger.models.properties.MapProperty) StringProperty(io.swagger.models.properties.StringProperty) Operation(io.swagger.models.Operation) NicknamedOperation(io.swagger.resources.NicknamedOperation) BodyParameter(io.swagger.models.parameters.BodyParameter) RefProperty(io.swagger.models.properties.RefProperty) ResourceWithResponse(io.swagger.resources.ResourceWithResponse) Response(io.swagger.models.Response) Swagger(io.swagger.models.Swagger) Model(io.swagger.models.Model) ResourceWithEmptyModel(io.swagger.resources.ResourceWithEmptyModel) RefModel(io.swagger.models.RefModel) ArrayModel(io.swagger.models.ArrayModel) ModelImpl(io.swagger.models.ModelImpl) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) MapProperty(io.swagger.models.properties.MapProperty) RefProperty(io.swagger.models.properties.RefProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) Test(org.testng.annotations.Test)

Example 19 with ArrayModel

use of io.swagger.models.ArrayModel in project swagger-core by swagger-api.

the class GenericsTest method checkCollectionsOfStringsAsBodyParameter.

@Test(description = "check collection of strings as body parameter")
public void checkCollectionsOfStringsAsBodyParameter() {
    Operation op = getOperation("testStringsInBody");
    assertEquals(op.getParameters().size(), 1);
    BodyParameter p = getBodyParameter(op, 0);
    ArrayModel strArray = (ArrayModel) p.getSchema();
    assertEquals(strArray.getItems().getType(), "string");
}
Also used : Operation(io.swagger.models.Operation) BodyParameter(io.swagger.models.parameters.BodyParameter) ArrayModel(io.swagger.models.ArrayModel) Test(org.testng.annotations.Test)

Example 20 with ArrayModel

use of io.swagger.models.ArrayModel in project swagger-core by swagger-api.

the class GenericsTest method checkCollectionsOfEnumerationsAsBodyParameter.

@Test(description = "check collection of enumerations as body parameter")
public void checkCollectionsOfEnumerationsAsBodyParameter() {
    Operation op = getOperation("testEnumsInBody");
    assertEquals(op.getParameters().size(), 1);
    BodyParameter p = getBodyParameter(op, 0);
    ArrayModel enumArray = (ArrayModel) p.getSchema();
    assertEquals(((StringProperty) enumArray.getItems()).getEnum(), enumValues);
}
Also used : Operation(io.swagger.models.Operation) BodyParameter(io.swagger.models.parameters.BodyParameter) ArrayModel(io.swagger.models.ArrayModel) Test(org.testng.annotations.Test)

Aggregations

ArrayModel (io.swagger.models.ArrayModel)27 Test (org.testng.annotations.Test)21 Model (io.swagger.models.Model)17 BodyParameter (io.swagger.models.parameters.BodyParameter)17 Operation (io.swagger.models.Operation)15 RefProperty (io.swagger.models.properties.RefProperty)14 Property (io.swagger.models.properties.Property)10 Path (io.swagger.models.Path)9 RefModel (io.swagger.models.RefModel)9 StringProperty (io.swagger.models.properties.StringProperty)9 Swagger (io.swagger.models.Swagger)7 ArrayProperty (io.swagger.models.properties.ArrayProperty)6 ComposedModel (io.swagger.models.ComposedModel)4 ModelImpl (io.swagger.models.ModelImpl)4 SwaggerDeserializationResult (io.swagger.parser.util.SwaggerDeserializationResult)4 Response (io.swagger.models.Response)3 ApiOperation (io.swagger.annotations.ApiOperation)2 FormParameter (io.swagger.models.parameters.FormParameter)2 HeaderParameter (io.swagger.models.parameters.HeaderParameter)2 Parameter (io.swagger.models.parameters.Parameter)2