Open markstos opened 10 years ago
@joshkopecek What do you think about this "wish" request? It addresses the wish to mark some GeoJSON schema elements as required, add extra validation, or fill in default values for particular fields in the Schema.
So I think there are two separate issues here:
required: true
could be done through
myPolygon: {
type: mongoose.SchemaTypes.Polygon,
required: true
}
The default values for properties are another issue. The only place the GeoJSON schema provides an room for flexibility is in the properties, so I can see this being one way to do it:
myPolygon: {
type: mongoose.SchemaTypes.Polygon,
required: true,
properties: {
a: { type: String, validator: myValidator },
b: { type: Number, validator: numberValdator }
}
}
and the other use case would be specifying your own validator for the CSR stuff, but I really don't know how much usage there would be for that!
A benefit of using Mongoose over raw Mongo is that field names are explicitly defined and validated.
It would be nice if GeoJSON.Feature could allow defining specific 'properties' as well as continuing to provide the boilerplate schema that it already does.
Some potential syntax options:
Option 2 is the more flexible way to go. I don't think either is backcompat, though. You would to start doing this:
But, perhaps that's a good direction to go anyway, as it allows you to add extra validation to any GeoJSON schema element: