Search in sources :

Example 1 with DateProperty

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

the class JodaLocalDateConverterTest method testJodaLocalDate.

@Test
public void testJodaLocalDate() {
    final Map<String, Model> models = ModelConverters.getInstance().read(ModelWithJodaLocalDate.class);
    assertEquals(models.size(), 1);
    final Model model = models.get("ModelWithJodaLocalDate");
    final Property dateTimeProperty = model.getProperties().get("createdAt");
    assertTrue(dateTimeProperty instanceof DateProperty);
    assertEquals((int) dateTimeProperty.getPosition(), 1);
    assertTrue(dateTimeProperty.getRequired());
    assertEquals(dateTimeProperty.getDescription(), "creation localDate");
    final Property nameProperty = model.getProperties().get("name");
    assertTrue(nameProperty instanceof StringProperty);
    assertEquals((int) nameProperty.getPosition(), 2);
    assertEquals(nameProperty.getDescription(), "name of the model");
}
Also used : DateProperty(io.swagger.models.properties.DateProperty) Model(io.swagger.models.Model) StringProperty(io.swagger.models.properties.StringProperty) DateProperty(io.swagger.models.properties.DateProperty) StringProperty(io.swagger.models.properties.StringProperty) ApiModelProperty(io.swagger.annotations.ApiModelProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 2 with DateProperty

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

the class ModelSerializerTest method convertModel.

@Test(description = "it should convert a model")
public void convertModel() throws JsonProcessingException {
    final ModelImpl pet = new ModelImpl();
    final HashMap<String, Property> props = new HashMap<String, Property>();
    props.put("intValue", new IntegerProperty());
    props.put("longValue", new LongProperty());
    props.put("dateValue", new DateProperty());
    props.put("dateTimeValue", new DateTimeProperty());
    pet.setProperties(props);
    pet.setRequired(Arrays.asList("intValue", "name"));
    final String json = "{\n" + "   \"required\":[\n" + "      \"intValue\"\n" + "   ],\n" + "   \"properties\":{\n" + "      \"dateValue\":{\n" + "         \"type\":\"string\",\n" + "         \"format\":\"date\"\n" + "      },\n" + "      \"longValue\":{\n" + "         \"type\":\"integer\",\n" + "         \"format\":\"int64\"\n" + "      },\n" + "      \"dateTimeValue\":{\n" + "         \"type\":\"string\",\n" + "         \"format\":\"date-time\"\n" + "      },\n" + "      \"intValue\":{\n" + "         \"type\":\"integer\",\n" + "         \"format\":\"int32\"\n" + "      }\n" + "   }\n" + "}";
    SerializationMatchers.assertEqualsToJson(pet, json);
}
Also used : IntegerProperty(io.swagger.models.properties.IntegerProperty) HashMap(java.util.HashMap) DateProperty(io.swagger.models.properties.DateProperty) LongProperty(io.swagger.models.properties.LongProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) ModelImpl(io.swagger.models.ModelImpl) StringProperty(io.swagger.models.properties.StringProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) DateProperty(io.swagger.models.properties.DateProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) Test(org.testng.annotations.Test)

Example 3 with DateProperty

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

the class PropertySerializationTest method serializeDateProperty.

@Test(description = "it should serialize a DateProperty")
public void serializeDateProperty() throws IOException {
    final DateProperty p = new DateProperty();
    final String json = "{\"type\":\"string\",\"format\":\"date\"}";
    assertEquals(m.writeValueAsString(p), json);
}
Also used : DateProperty(io.swagger.models.properties.DateProperty) Test(org.testng.annotations.Test)

Example 4 with DateProperty

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

the class PropertySerializationTest method deserializeDateProperty.

@Test(description = "it should deserialize a DateProperty")
public void deserializeDateProperty() throws IOException {
    final String json = "{\"type\":\"string\",\"format\":\"date\"}";
    final Property p = m.readValue(json, Property.class);
    assertEquals(p.getType(), "string");
    assertEquals(p.getFormat(), "date");
    assertEquals(p.getClass(), DateProperty.class);
    assertEquals(m.writeValueAsString(p), json);
}
Also used : 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)

Aggregations

DateProperty (io.swagger.models.properties.DateProperty)4 Test (org.testng.annotations.Test)4 Property (io.swagger.models.properties.Property)3 StringProperty (io.swagger.models.properties.StringProperty)3 DateTimeProperty (io.swagger.models.properties.DateTimeProperty)2 IntegerProperty (io.swagger.models.properties.IntegerProperty)2 LongProperty (io.swagger.models.properties.LongProperty)2 RefProperty (io.swagger.models.properties.RefProperty)2 ApiModelProperty (io.swagger.annotations.ApiModelProperty)1 Model (io.swagger.models.Model)1 ModelImpl (io.swagger.models.ModelImpl)1 ArrayProperty (io.swagger.models.properties.ArrayProperty)1 BooleanProperty (io.swagger.models.properties.BooleanProperty)1 DoubleProperty (io.swagger.models.properties.DoubleProperty)1 FileProperty (io.swagger.models.properties.FileProperty)1 FloatProperty (io.swagger.models.properties.FloatProperty)1 MapProperty (io.swagger.models.properties.MapProperty)1 ObjectProperty (io.swagger.models.properties.ObjectProperty)1 HashMap (java.util.HashMap)1