Search in sources :

Example 1 with DateSchema

use of io.swagger.v3.oas.models.media.DateSchema in project swagger-core by swagger-api.

the class JodaLocalDateConverterTest method testJodaLocalDate.

@Test
public void testJodaLocalDate() {
    final Map<String, Schema> models = ModelConverters.getInstance().read(ModelWithJodaLocalDate.class);
    assertEquals(models.size(), 1);
    final Schema model = models.get("ModelWithJodaLocalDate");
    final Schema dateTimeProperty = (Schema) model.getProperties().get("createdAt");
    assertTrue(dateTimeProperty instanceof DateSchema);
    assertTrue(model.getRequired().contains("createdAt"));
    assertEquals(dateTimeProperty.getDescription(), "creation localDate");
    final Schema nameProperty = (Schema) model.getProperties().get("name");
    assertTrue(nameProperty instanceof StringSchema);
    assertEquals(nameProperty.getDescription(), "name of the model");
}
Also used : StringSchema(io.swagger.v3.oas.models.media.StringSchema) DateSchema(io.swagger.v3.oas.models.media.DateSchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) Schema(io.swagger.v3.oas.models.media.Schema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) DateSchema(io.swagger.v3.oas.models.media.DateSchema) Test(org.testng.annotations.Test)

Example 2 with DateSchema

use of io.swagger.v3.oas.models.media.DateSchema 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 DateSchema p = new DateSchema();
    final String json = "{\"type\":\"string\",\"format\":\"date\"}";
    assertEquals(m.writeValueAsString(p), json);
}
Also used : DateSchema(io.swagger.v3.oas.models.media.DateSchema) Test(org.testng.annotations.Test)

Example 3 with DateSchema

use of io.swagger.v3.oas.models.media.DateSchema 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 Schema pet = new Schema();
    final Map<String, Schema> props = new LinkedHashMap<String, Schema>();
    props.put("intValue", new IntegerSchema());
    props.put("longValue", new IntegerSchema().format("int64"));
    props.put("dateValue", new DateSchema());
    props.put("dateTimeValue", new DateTimeSchema());
    pet.setProperties(props);
    pet.setRequired(Arrays.asList("intValue", "name"));
    final String json = "{\n" + "   \"required\":[\n" + "      \"intValue\"\n" + "   ],\n" + "   \"properties\":{\n" + "      \"intValue\":{\n" + "         \"type\":\"integer\",\n" + "         \"format\":\"int32\"\n" + "      },\n" + "      \"longValue\":{\n" + "         \"type\":\"integer\",\n" + "         \"format\":\"int64\"\n" + "      },\n" + "      \"dateValue\":{\n" + "         \"type\":\"string\",\n" + "         \"format\":\"date\"\n" + "      },\n" + "      \"dateTimeValue\":{\n" + "         \"type\":\"string\",\n" + "         \"format\":\"date-time\"\n" + "      }\n" + "   }\n" + "}";
    SerializationMatchers.assertEqualsToJson(pet, json);
}
Also used : DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) DateSchema(io.swagger.v3.oas.models.media.DateSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) DateSchema(io.swagger.v3.oas.models.media.DateSchema) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Aggregations

DateSchema (io.swagger.v3.oas.models.media.DateSchema)3 Test (org.testng.annotations.Test)3 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)2 Schema (io.swagger.v3.oas.models.media.Schema)2 StringSchema (io.swagger.v3.oas.models.media.StringSchema)2 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)1 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)1 LinkedHashMap (java.util.LinkedHashMap)1