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);
}
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;
}
}
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");
}
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");
}
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);
}
Aggregations