Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature.properties should be mandatory #41

Open
OlivierMartineau opened this issue Jul 16, 2021 · 2 comments
Open

Feature.properties should be mandatory #41

OlivierMartineau opened this issue Jul 16, 2021 · 2 comments

Comments

@OlivierMartineau
Copy link

https://datatracker.ietf.org/doc/html/rfc7946#section-3.2

A Feature object has a member with the name "properties". The value of the properties member is an object (any JSON object or a JSON null value).

I found that you could remove a Feature "properties" property and still have the format validated.
Such property can be null or any object, possibly empty, but should always be there.

Delete line 609 to 611 in test/GeoJSON.integration.js: all tests are still successful.

@OlivierMartineau OlivierMartineau changed the title Feature.property should be mandatory Feature.properties should be mandatory Jul 16, 2021
@OlivierMartineau
Copy link
Author

OlivierMartineau commented Jul 16, 2021

I suggest to change index.js line 496 to the following:

Feature.schemaName = 'Feature'

function validateFeature(feature) {
  if (!feature.type) {
    throw new mongoose.Error('Feature must have a type')
  }
  // type must be Feature
  if (feature.type !== 'Feature') {
    throw new mongoose.Error(feature.type + ' is not a valid GeoJSON type')
  }
  if (!feature.geometry) {
    throw new mongoose.Error('Feature must have a geometry')
  }
  // check for crs
  if (feature.crs) {
    crs = feature.crs
    validateCrs(crs)
  }
  validateGeometry(feature.geometry)
  validateFeatureProperties(feature.properties)
}

function validateFeatureProperties(properties) {
  if (properties === null) return
  if (!properties) {
    throw new mongoose.Error('Feature must have a "properties" member')
  }
  if (typeof properties !== 'object') {
    throw new mongoose.Error('Feature properties must be a JSON object or a null value.')
  }
}

@joshkopecek
Copy link
Contributor

Hi @OlivierMartineau. Great suggestion. Feel free to make a PR for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants