Search in sources :

Example 46 with Property

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

the class JsonDeserializationTest method shouldDeserializeArrayPropertyMinItems.

@Test
public void shouldDeserializeArrayPropertyMinItems() throws Exception {
    String path = "json-schema-validation/array.json";
    ArrayProperty property = (ArrayProperty) TestUtils.deserializeJsonFileFromClasspath(path, Property.class);
    assertNotNull(property.getMinItems());
    assertEquals(property.getMinItems().intValue(), 1);
}
Also used : ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) MapProperty(io.swagger.models.properties.MapProperty) StringProperty(io.swagger.models.properties.StringProperty) ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 47 with Property

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

the class GenericsTest method checkParametersOfGenericTypes.

@Test(description = "check parameters of generic types")
public void checkParametersOfGenericTypes() {
    Set<String> genericTypes = new HashSet(Arrays.asList("GenericTypeString", "GenericTypeUUID", "GenericTypeGenericTypeString", "RenamedGenericTypeString", "RenamedGenericTypeRenamedGenericTypeString"));
    assertTrue(swagger.getDefinitions().keySet().containsAll(genericTypes));
    Operation opString = getOperation("testGenericType");
    testGenericType(opString, "GenericTypeString");
    Property strValue = getProperty("GenericTypeString", "value");
    assertNotEquals(strValue, null);
    assertEquals(strValue.getClass().getName(), StringProperty.class.getName());
    Operation opUUID = getOperation("testStringBasedGenericType");
    testGenericType(opUUID, "GenericTypeUUID");
    Property uuidValue = getProperty("GenericTypeUUID", "value");
    assertNotEquals(uuidValue, null);
    assertEquals(uuidValue.getClass().getName(), UUIDProperty.class.getName());
    Operation opComplex = getOperation("testComplexGenericType");
    testGenericType(opComplex, "GenericTypeGenericTypeString");
    Property complexValue = getProperty("GenericTypeGenericTypeString", "value");
    assertNotEquals(complexValue, null);
    assertEquals(complexValue.getClass().getName(), RefProperty.class.getName());
    assertEquals(((RefProperty) complexValue).getSimpleRef(), "GenericTypeString");
    Operation opRenamed = getOperation("testRenamedGenericType");
    testGenericType(opRenamed, "RenamedGenericTypeRenamedGenericTypeString");
    Property renamedComplexValue = getProperty("RenamedGenericTypeRenamedGenericTypeString", "value");
    assertNotEquals(renamedComplexValue, null);
    assertTrue(renamedComplexValue instanceof RefProperty);
    assertEquals(((RefProperty) renamedComplexValue).getSimpleRef(), "RenamedGenericTypeString");
}
Also used : UUIDProperty(io.swagger.models.properties.UUIDProperty) StringProperty(io.swagger.models.properties.StringProperty) Operation(io.swagger.models.Operation) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) UUIDProperty(io.swagger.models.properties.UUIDProperty) HashSet(java.util.HashSet) RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

Example 48 with Property

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

the class GenericsTest method checkGenericResult.

@Test(description = "check generic result")
public void checkGenericResult() {
    Operation op = swagger.getPath("/generics/testGenericResult").getGet();
    Property schema = op.getResponses().get("200").getSchema();
    assertEquals(schema.getClass().getName(), RefProperty.class.getName());
    assertEquals(((RefProperty) schema).getSimpleRef(), "GenericListWrapperTag");
    Property entries = getProperty("GenericListWrapperTag", "entries");
    assertNotEquals(entries, null);
    assertEquals(entries.getClass().getName(), ArrayProperty.class.getName());
    Property items = ((ArrayProperty) entries).getItems();
    assertEquals(items.getClass().getName(), RefProperty.class.getName());
    assertEquals(((RefProperty) items).getSimpleRef(), "Tag");
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) Operation(io.swagger.models.Operation) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) UUIDProperty(io.swagger.models.properties.UUIDProperty) RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

Example 49 with Property

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

the class MapPropertyDeserializerTest method testMapDeserialization.

@Test(description = "it should deserialize a response per #1349")
public void testMapDeserialization() throws Exception {
    Operation operation = Json.mapper().readValue(json, Operation.class);
    Response response = operation.getResponses().get("200");
    assertNotNull(response);
    Property responseSchema = response.getSchema();
    assertNotNull(responseSchema);
    assertTrue(responseSchema instanceof MapProperty);
    MapProperty mp = (MapProperty) responseSchema;
    assertTrue(mp.getAdditionalProperties() instanceof IntegerProperty);
}
Also used : Response(io.swagger.models.Response) IntegerProperty(io.swagger.models.properties.IntegerProperty) MapProperty(io.swagger.models.properties.MapProperty) Operation(io.swagger.models.Operation) IntegerProperty(io.swagger.models.properties.IntegerProperty) MapProperty(io.swagger.models.properties.MapProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 50 with Property

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

the class MapPropertyDeserializerTest method testIssue1261InlineSchemaExample.

@Test(description = "it should read an example within an inlined schema")
public void testIssue1261InlineSchemaExample() throws Exception {
    Operation operation = Yaml.mapper().readValue("      produces:\n" + "        - application/json\n" + "      responses:\n" + "        200:\n" + "          description: OK\n" + "          schema:\n" + "            type: object\n" + "            properties:\n" + "              id:\n" + "                type: integer\n" + "                format: int32\n" + "              name:\n" + "                type: string\n" + "            required: [id, name]\n" + "            example:\n" + "              id: 42\n" + "              name: Arthur Dent\n", Operation.class);
    Response response = operation.getResponses().get("200");
    assertNotNull(response);
    Property schema = response.getSchema();
    Object example = schema.getExample();
    assertNotNull(example);
    assertTrue(example instanceof ObjectNode);
    ObjectNode objectNode = (ObjectNode) example;
    assertEquals(objectNode.get("id").intValue(), 42);
    assertEquals(objectNode.get("name").textValue(), "Arthur Dent");
}
Also used : Response(io.swagger.models.Response) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Operation(io.swagger.models.Operation) IntegerProperty(io.swagger.models.properties.IntegerProperty) MapProperty(io.swagger.models.properties.MapProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Aggregations

Property (io.swagger.models.properties.Property)145 Test (org.testng.annotations.Test)96 ArrayProperty (io.swagger.models.properties.ArrayProperty)86 StringProperty (io.swagger.models.properties.StringProperty)75 RefProperty (io.swagger.models.properties.RefProperty)65 MapProperty (io.swagger.models.properties.MapProperty)59 Model (io.swagger.models.Model)52 IntegerProperty (io.swagger.models.properties.IntegerProperty)48 LongProperty (io.swagger.models.properties.LongProperty)35 DoubleProperty (io.swagger.models.properties.DoubleProperty)32 FloatProperty (io.swagger.models.properties.FloatProperty)27 BooleanProperty (io.swagger.models.properties.BooleanProperty)25 ObjectProperty (io.swagger.models.properties.ObjectProperty)25 Operation (io.swagger.models.Operation)24 DateTimeProperty (io.swagger.models.properties.DateTimeProperty)23 DateProperty (io.swagger.models.properties.DateProperty)22 ApiModelProperty (io.swagger.annotations.ApiModelProperty)20 FileProperty (io.swagger.models.properties.FileProperty)18 ModelImpl (io.swagger.models.ModelImpl)17 Response (io.swagger.models.Response)16