echoes-xyz / mongoose-geojson-schema

Schema definitions for GeoJSON types for use with Mongoose JS
MIT License
79 stars 25 forks source link

wish: define specific fields on a GeoJSON Feature #1

Open markstos opened 10 years ago

markstos commented 10 years ago

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 commented 8 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.

joshkopecek commented 8 years ago

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!