You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using PySTAC it would be convenient to be able to validate STAC objects. This is true for incoming STAC objects - for example, you might want to run validation against the JSON of a STAC object against an older version before reading in with PySTAC (and thereby migrating it to the latest STAC version). This is also true of STAC you construct with PySTAC - though the structure of PySTAC tends towards making valid STAC objects, a user can set a property that breaks the specification (e.g. setting a string instead of an array of strings) and it would be convenient to be able to check validity on-demand to avoid this.
I believe that validation should not happen by default in the core package. For one, this would add a dependency to the library, which aims to minimize dependencies. Also, validation takes time - and when dealing with many STAC objects, it should be up to the user if they want to pay the cost of that validation time or avoid it altogether.
An approach to solving this is as follows:
Validate STACObjects
Create a new package, pystac_validator. This will expand on the SchemaValidator already used in the unit tests, and be based off of jsonschema validation. It will also implement an abstract class so that other validators can easily be utilized by extending this class.
Allow the registering of a validator in the core library. This allows flexibility for users to implement their own validation logic.
In the core library, create a .validate method on STACObject. This method will:
Check if there is a validator registered with PySTAC. If so, use that to validate the STACObject.
If no validator is registered, check to see if the pystac_validator library is importable. If so, use that validator.
If no validator is registered and pystac_validator cannot be imported, throw an exception.
This way validation can happen on-demand for any STACObject by calling its validate method.
This can be done in a way that lets catalogs be validated completely in a single call.
Validate JSON
In addition to validating STACObjects, users may want to validate incoming JSON before they are read in as PySTAC objects. This could be done by a pystac.validate(d) method that will validate a dict based on the type and extensions identified in pystac.serialization.identify.
The text was updated successfully, but these errors were encountered:
When using PySTAC it would be convenient to be able to validate STAC objects. This is true for incoming STAC objects - for example, you might want to run validation against the JSON of a STAC object against an older version before reading in with PySTAC (and thereby migrating it to the latest STAC version). This is also true of STAC you construct with PySTAC - though the structure of PySTAC tends towards making valid STAC objects, a user can set a property that breaks the specification (e.g. setting a string instead of an array of strings) and it would be convenient to be able to check validity on-demand to avoid this.
I believe that validation should not happen by default in the core package. For one, this would add a dependency to the library, which aims to minimize dependencies. Also, validation takes time - and when dealing with many STAC objects, it should be up to the user if they want to pay the cost of that validation time or avoid it altogether.
An approach to solving this is as follows:
Validate STACObjects
pystac_validator
. This will expand on the SchemaValidator already used in the unit tests, and be based off ofjsonschema
validation. It will also implement an abstract class so that other validators can easily be utilized by extending this class..validate
method onSTACObject
. This method will:pystac_validator
library is importable. If so, use that validator.pystac_validator
cannot be imported, throw an exception.This way validation can happen on-demand for any
STACObject
by calling itsvalidate
method.This can be done in a way that lets catalogs be validated completely in a single call.
Validate JSON
In addition to validating
STACObject
s, users may want to validate incoming JSON before they are read in as PySTAC objects. This could be done by apystac.validate(d)
method that will validate a dict based on the type and extensions identified inpystac.serialization.identify
.The text was updated successfully, but these errors were encountered: