mongoose-geojson-schema icon indicating copy to clipboard operation
mongoose-geojson-schema copied to clipboard

wish: define specific fields on a GeoJSON Feature

Open markstos opened this issue 10 years ago • 2 comments

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 1:
// Allow defining just properties:
geoFeature: GeoJSON.Feature({
  a: 1,
  b: 2,
);


//Option 2:
// Allow defining anything or everything. 
// Internally, add any missing bits from the boilerplate
geoFeature: GeoJSON.Feature({
    properties: {
      a: 1,
      b: 2,
    },
});

Option 2 is the more flexible way to go. I don't think either is backcompat, though. You would to start doing this:

geoFeature: GeoJSON.Feature();

But, perhaps that's a good direction to go anyway, as it allows you to add extra validation to any GeoJSON schema element:

myPolyGon : geoJSON.Polygon({ required: true, validator: myValidator });

markstos avatar Mar 31 '14 16:03 markstos

@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.

markstos avatar May 04 '16 15:05 markstos

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!

joshkopecek avatar May 04 '16 16:05 joshkopecek