Search in sources :

Example 1 with DateTimeSchema

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

the class JodaLocalDateConverterTest method testJavaTimeInstant.

@Test
public void testJavaTimeInstant() {
    final Map<String, Schema> models = ModelConverters.getInstance().read(ModelWithJavaTimeInstant.class);
    assertEquals(models.size(), 1);
    final Schema model = models.get("ModelWithJavaTimeInstant");
    final Schema dateTimeProperty = (Schema) model.getProperties().get("createdAt");
    assertTrue(dateTimeProperty instanceof DateTimeSchema);
}
Also used : DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) 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) Test(org.testng.annotations.Test)

Example 2 with DateTimeSchema

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

the class SamplePropertyExtendedConverter method resolve.

@Override
public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> chain) {
    if (type.isSchemaProperty()) {
        JavaType _type = Json.mapper().constructType(type.getType());
        if (_type != null) {
            Class<?> cls = _type.getRawClass();
            if (MyCustomClass.class.isAssignableFrom(cls)) {
                Schema schema = new DateTimeSchema();
                super.resolveSchemaMembers(schema, type);
                return schema;
            }
        }
    }
    if (chain.hasNext()) {
        return chain.next().resolve(type, context, chain);
    } else {
        return null;
    }
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) Schema(io.swagger.v3.oas.models.media.Schema)

Example 3 with DateTimeSchema

use of io.swagger.v3.oas.models.media.DateTimeSchema 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, Schema> models = ModelConverters.getInstance().readAll(ModelWithCalendar.class);
    // don't create a Joda DateTime object
    assertEquals(models.size(), 1);
    Schema model = models.get("ModelWithCalendar");
    final Map<String, Schema> properties = model.getProperties();
    final Schema nameProperty = properties.get("name");
    assertTrue(nameProperty instanceof StringSchema);
    assertEquals(nameProperty.getDescription(), "name of the model");
    final Schema dateTimeSchema = properties.get("createdAt");
    assertTrue(dateTimeSchema instanceof DateTimeSchema);
    assertTrue(model.getRequired().contains("createdAt"));
    assertEquals(dateTimeSchema.getDescription(), "creation timestamp");
}
Also used : DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) Schema(io.swagger.v3.oas.models.media.Schema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Test(org.testng.annotations.Test)

Example 4 with DateTimeSchema

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

the class JodaDateTimeConverterTest method testJodaDateTime.

@Test
public void testJodaDateTime() {
    final Map<String, Schema> models = ModelConverters.getInstance().read(ModelWithJodaDateTime.class);
    // don't create a Joda DateTime object
    assertEquals(models.size(), 1);
    final Schema model = models.get("ModelWithJodaDateTime");
    final Schema dateTimeProperty = (Schema) model.getProperties().get("createdAt");
    assertTrue(dateTimeProperty instanceof DateTimeSchema);
    assertTrue(model.getRequired().contains("createdAt"));
    assertEquals(dateTimeProperty.getDescription(), "creation timestamp");
    final Schema nameProperty = (Schema) model.getProperties().get("name");
    assertTrue(nameProperty instanceof StringSchema);
    assertEquals(nameProperty.getDescription(), "name of the model");
}
Also used : DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) Schema(io.swagger.v3.oas.models.media.Schema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Test(org.testng.annotations.Test)

Example 5 with DateTimeSchema

use of io.swagger.v3.oas.models.media.DateTimeSchema 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

DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)6 Schema (io.swagger.v3.oas.models.media.Schema)5 Test (org.testng.annotations.Test)5 StringSchema (io.swagger.v3.oas.models.media.StringSchema)4 DateSchema (io.swagger.v3.oas.models.media.DateSchema)2 JavaType (com.fasterxml.jackson.databind.JavaType)1 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)1 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)1 LinkedHashMap (java.util.LinkedHashMap)1