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
schemas: add geojson support #21
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall, good job 🔥
Some discussions to be made regarding which parts of GeoJSON to be included and how to integrate extra metadata fields better.
optional third element. | ||
""" | ||
if not data: | ||
raise ValidationError({"geojson": "coordinates must be present."}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that handled by the required=True
above on the coordinates
field?
Also I think passing a dict
to the ValidationError
hides the real field that has the error (unless we want to establish a convention for exposing GeoJSON error under a specific key)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that handled by the required=True above on the coordinates field?
Correct, it was legacy code. First I tried to have a single "validates_schema" on the GeoJSONSchema
, and a simple attr geojson_cls
. Because as you can see the validation function is the same except for the geojson object they invoke for validation. In this case, this check was needed. However, I did not manage to make it work, for some reason the validation decorator was not triggered (even though OneOfSchema
inherits from Schema
...). Some issues are open also about post_load
and company not being triggered.
Proposal: Open an issue, and address this (refactor validation) when we add more fields/schemas. (Already removed the unnecessary check).
Also I think passing a dict to the ValidationError hides the real field that has the error (unless we want to establish a convention for exposing GeoJSON error under a specific key)
My idea was to actually expose GeoJSON since we are validating with it... would be nice to tell the user that in a meaningful way.
tests/schemas/test_geojson.py
Outdated
"type": "point", | ||
"coordinates": [-32.94682] | ||
} | ||
pytest.raises(ValidationError, GeoJSONSchema().load, invalid_input) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also test in general for the shape/kind of data the ValidationError
s have
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do that once we agreed on the above point. Was also thinking if we should capture/re-raise exceptions to enable translation on strings... (would make this module dependent on babel and company). Maybe it's better to do it on rdm-records level?
|
[ci skip]Skipped tests until reviewed cuz Travis...As discussed with @slint this PR adds support for
Point
,MultiPoint
andPolygon
. Since DataCite supportsgeoLocationPoint
,geoLocationBox
,geoLocationPolygon
.These schemas have been implemented using python geojson library. In order to provide support for multiple schemas (i.e. the
coordinates
is different depending on the object type) marshmallow-oneofschema is used. marshmallow-polyschema was evaluated.Enables the start of inveniosoftware/invenio-rdm-records#231 in Invenio-RDM-Records