use of com.github.sebastianfrey.joa.models.schema.type.ObjectType in project joa by sebastianfrey.
the class JSONSchemaBuilderTest method should_serialize_full_object_type.
@Test
public void should_serialize_full_object_type() throws Exception {
ObjectType objectType = objectType().title("title").property("string", stringType().title("string")).property("number", numberType().title("number")).patternProperty("^_S", stringType()).required(List.of("string")).additionalProperties().unevaluatedProperties().minProperties(1).maxProperties(2).propertyNames("^[A-Za-z_][A-Za-z0-9_]*$");
final String expected = MAPPER.writeValueAsString(MAPPER.readValue(fixture("fixtures/schemas/type/objectFull.json"), ObjectType.class));
assertThat(MAPPER.writeValueAsString(objectType)).isEqualTo(expected);
}
use of com.github.sebastianfrey.joa.models.schema.type.ObjectType in project joa by sebastianfrey.
the class JSONSchemaBuilderTest method should_serialize_object_type.
@Test
public void should_serialize_object_type() throws Exception {
ObjectType objectType = objectType();
final String expected = MAPPER.writeValueAsString(MAPPER.readValue(fixture("fixtures/schemas/type/object.json"), ObjectType.class));
assertThat(MAPPER.writeValueAsString(objectType)).isEqualTo(expected);
}
use of com.github.sebastianfrey.joa.models.schema.type.ObjectType in project joa by sebastianfrey.
the class GeoPackageService method getQueryables.
@Override
public Queryables getQueryables(String serviceId, String collectionId) {
try (GeoPackage gpkg = loadService(serviceId)) {
ObjectType schema = JSONSchemaBuilder.objectType().title(collectionId).schema(Schemas.DRAFT_2019_09);
FeatureDao featureDao = loadCollection(gpkg, collectionId);
String geometryColumn = featureDao.getGeometryColumnName();
featureDao.getColumns().stream().forEach((column) -> {
if (column.isGeometry()) {
return;
}
Long max = column.getMax();
Object defaultValue = column.getDefaultValue();
GenericType<?> type = null;
switch(column.getDataType()) {
case BOOLEAN:
type = JSONSchemaBuilder.booleanType();
break;
case BLOB:
case TINYINT:
case TEXT:
type = JSONSchemaBuilder.stringType().maxLength(max);
break;
case DATE:
type = JSONSchemaBuilder.stringType().maxLength(max).format("date");
break;
case DATETIME:
type = JSONSchemaBuilder.stringType().maxLength(max).format("date-time");
break;
case DOUBLE:
case FLOAT:
case REAL:
type = JSONSchemaBuilder.numberType();
break;
case INT:
case INTEGER:
case MEDIUMINT:
case SMALLINT:
type = JSONSchemaBuilder.integerType().maximum(max);
break;
default:
break;
}
if (type == null) {
return;
}
String columnName = column.getName();
type.title(columnName);
if (defaultValue != null) {
type.defaultValue(defaultValue.toString());
}
schema.property(columnName, type);
});
GeometryType geometryType = featureDao.getGeometryType();
JSONSchema geometrySchema = null;
switch(geometryType) {
case GEOMETRY:
geometrySchema = Schemas.GeoJSON.geometry();
break;
case POINT:
geometrySchema = Schemas.GeoJSON.point();
break;
case LINESTRING:
geometrySchema = Schemas.GeoJSON.lineString();
break;
case POLYGON:
geometrySchema = Schemas.GeoJSON.polygon();
break;
case MULTIPOINT:
geometrySchema = Schemas.GeoJSON.multiPoint();
break;
case MULTILINESTRING:
geometrySchema = Schemas.GeoJSON.multiLineString();
break;
case MULTIPOLYGON:
geometrySchema = Schemas.GeoJSON.multiPolygon();
break;
default:
break;
}
if (geometrySchema != null) {
schema.property(geometryColumn, geometrySchema);
}
return new Queryables().serviceId(serviceId).collectionId(collectionId).schema(schema);
}
}
Aggregations