Search in sources :

Example 1 with DateTimeProperty

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

the class JodaDateTimeConverterTest method testJodaDateTime.

@Test
public void testJodaDateTime() {
    final Map<String, Model> models = ModelConverters.getInstance().read(ModelWithJodaDateTime.class);
    // don't create a Joda DateTime object
    assertEquals(models.size(), 1);
    final Model model = models.get("ModelWithJodaDateTime");
    final Property dateTimeProperty = model.getProperties().get("createdAt");
    assertTrue(dateTimeProperty instanceof DateTimeProperty);
    assertEquals((int) dateTimeProperty.getPosition(), 1);
    assertTrue(dateTimeProperty.getRequired());
    assertEquals(dateTimeProperty.getDescription(), "creation timestamp");
    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 : DateTimeProperty(io.swagger.models.properties.DateTimeProperty) Model(io.swagger.models.Model) StringProperty(io.swagger.models.properties.StringProperty) StringProperty(io.swagger.models.properties.StringProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) ApiModelProperty(io.swagger.annotations.ApiModelProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 2 with DateTimeProperty

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

the class XMLGregorianCalendarTest method testXMLGregorianCalendar.

@Test(description = "it should read a model with XMLGregorianCalendar")
public void testXMLGregorianCalendar() {
    final Map<String, Model> models = ModelConverters.getInstance().readAll(ModelWithCalendar.class);
    // don't create a Joda DateTime object
    assertEquals(models.size(), 1);
    final Map<String, Property> properties = models.get("ModelWithCalendar").getProperties();
    final Property nameProperty = properties.get("name");
    assertTrue(nameProperty instanceof StringProperty);
    assertEquals((int) nameProperty.getPosition(), 2);
    assertEquals(nameProperty.getDescription(), "name of the model");
    final Property dateTimeProperty = properties.get("createdAt");
    assertTrue(dateTimeProperty instanceof DateTimeProperty);
    assertEquals((int) dateTimeProperty.getPosition(), 1);
    assertTrue(dateTimeProperty.getRequired());
    assertEquals(dateTimeProperty.getDescription(), "creation timestamp");
}
Also used : DateTimeProperty(io.swagger.models.properties.DateTimeProperty) Model(io.swagger.models.Model) StringProperty(io.swagger.models.properties.StringProperty) StringProperty(io.swagger.models.properties.StringProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) ApiModelProperty(io.swagger.annotations.ApiModelProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 3 with DateTimeProperty

use of io.swagger.models.properties.DateTimeProperty 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 4 with DateTimeProperty

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

the class PropertySerializationTest method deserializeDateTimeProperty.

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

Example 5 with DateTimeProperty

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

the class PropertySerializationTest method serializeDateTimeProperty.

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

Aggregations

DateTimeProperty (io.swagger.models.properties.DateTimeProperty)5 Test (org.testng.annotations.Test)5 Property (io.swagger.models.properties.Property)4 StringProperty (io.swagger.models.properties.StringProperty)4 ApiModelProperty (io.swagger.annotations.ApiModelProperty)2 Model (io.swagger.models.Model)2 DateProperty (io.swagger.models.properties.DateProperty)2 IntegerProperty (io.swagger.models.properties.IntegerProperty)2 LongProperty (io.swagger.models.properties.LongProperty)2 RefProperty (io.swagger.models.properties.RefProperty)2 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