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

Implement validation #139

Merged
merged 12 commits into from
Aug 14, 2020
Merged

Implement validation #139

merged 12 commits into from
Aug 14, 2020

Conversation

lossyrob
Copy link
Member

This PR implements validation in PySTAC.

Catalog, Collection and Item have a validate() method that will validate their serialized versions against STAC schema json hosted at https://schemas.stacspec.org/. There's also a pystac.validation.validate_json method that can validate STAC from earlier versions, back to 0.6.0.

The design of this feature allows for users to write their own implementations of STACValidator and register it with PySTAC via the pystac.validation.set_validator method. Users can also override the DefaultSchemaUriMap to provide custom mappings between STAC object types and extensions to schema URIs.

This feature requires jsonschema to be installed if using the default validator. This can be accomplished by specifying the 'validation' extras on install:

> pip install pystac[validation]

Also included in this PR is moving the urllib capability for reading http and https URIs from the unit tests to the default implementations in STAC_IO, and so allowing http and https STAC to be read by default without a custom read implementation.

Fixes #118

Reading http and https can be accomplished via the stdlib; enable it
in the STAC_IO.default_read_text_method and remove the override from
the unittests.
Also import it into the top level package, so users can use as `pystac.STACObjectType`.
This makes it easier to pass information along to methods that need to
work on serialized versions of the object. This was implemented in
preperation of the `validate` method on STACObject
@simonkassel simonkassel self-requested a review August 13, 2020 16:13
Copy link
Collaborator

@simonkassel simonkassel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this in person. I think just one change to validate moethods and some minor bug fixes, otherwise looks good.

pystac/validation/__init__.py Outdated Show resolved Hide resolved
Also remove the test version of SchemaValidator and move to the core
PySTAC implementation in all unit tests.
This makes installing jsonschema along with PySTAC optional, keeping
PySTAC lightweight for users that don't need validation.
Also fix up some API docs for pystac.serialization
@lossyrob lossyrob force-pushed the feature/rde/validation branch from 984ade9 to 2167a47 Compare August 14, 2020 02:33
Copy link
Collaborator

@simonkassel simonkassel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lossyrob lossyrob merged commit 7d50977 into develop Aug 14, 2020
@lossyrob lossyrob deleted the feature/rde/validation branch August 14, 2020 17:11
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

Successfully merging this pull request may close these issues.

Add validation capabilities to PySTAC
2 participants