Search in sources :

Example 21 with Property

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

the class PropertySerializationTest method serializeReadOnlyStringProperty.

@Test(description = "it should serialize a string property with readOnly set")
public void serializeReadOnlyStringProperty() throws IOException {
    final Property p = new StringProperty().readOnly();
    final String json = "{\"type\":\"string\",\"readOnly\":true}";
    assertEquals(m.writeValueAsString(p), json);
}
Also used : StringProperty(io.swagger.models.properties.StringProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty) MapProperty(io.swagger.models.properties.MapProperty) FloatProperty(io.swagger.models.properties.FloatProperty) DateProperty(io.swagger.models.properties.DateProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) FileProperty(io.swagger.models.properties.FileProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 22 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 23 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 24 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 25 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)

Aggregations

Property (io.swagger.models.properties.Property)143 Test (org.testng.annotations.Test)96 ArrayProperty (io.swagger.models.properties.ArrayProperty)85 StringProperty (io.swagger.models.properties.StringProperty)73 RefProperty (io.swagger.models.properties.RefProperty)64 MapProperty (io.swagger.models.properties.MapProperty)59 Model (io.swagger.models.Model)51 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)16 Response (io.swagger.models.Response)16