Documentation
¶
Overview ¶
Package validator implements a STAC resource validation.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct { // Limit to the number of resources to fetch and validate concurrently. Concurrency int // Type of recursion to use when crawling linked resources. Use crawler.None to visit // a single resource. Use crawler.Children to only visit linked item/child resources. // Use crawler.All to visit parent and child resources. Recursion crawler.RecursionType // A lookup of substitute schema locations. The key is the original schema location // and the value is the substitute location. SchemaMap map[string]string // Logger to use for logging. Logger *logr.Logger }
Options for the Validator.
type ValidationError ¶
type ValidationError struct { *jsonschema.ValidationError // Location is the file path or URL to the resource that failed validation. Location string // The resource being crawled. Resource crawler.Resource }
ValidationError holds details about a validation error.
func (*ValidationError) GoString ¶
func (err *ValidationError) GoString() string
GoString provides additional detail about the validation error.
Called when the # flag is used with the %v verb as in fmt.Printf("%#v", err).
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator allows validation of STAC resources.
func (*Validator) Validate ¶
Validate validates a STAC resource.
The resource can be a path to a local file or a URL. Validation will stop with the first invalid resource and the resulting ValidationError will be returned. Context cancellation will also stop validation and the context error will be returned.
Example (Children) ¶
package main import ( "context" "fmt" "github.com/planetlabs/go-stac/crawler" "github.com/planetlabs/go-stac/validator" ) func main() { v := validator.New(&validator.Options{ Recursion: crawler.Children, }) err := v.Validate(context.Background(), "testdata/cases/v1.0.0/catalog-with-item-missing-id.json") fmt.Printf("%#v\n", err) }
Output: invalid item: testdata/cases/v1.0.0/item-missing-id.json [I#] [S#] doesn't validate with https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json# [I#] [S#/allOf/0] allOf failed [I#] [S#/allOf/0/$ref] doesn't validate with '/definitions/core' [I#] [S#/definitions/core/allOf/2] allOf failed [I#] [S#/definitions/core/allOf/2/required] missing properties: 'id'
Example (Single) ¶
package main import ( "context" "fmt" "github.com/planetlabs/go-stac/crawler" "github.com/planetlabs/go-stac/validator" ) func main() { v := validator.New(&validator.Options{ Recursion: crawler.None, }) err := v.Validate(context.Background(), "testdata/cases/v1.0.0/item-missing-id.json") fmt.Printf("%#v\n", err) }
Output: invalid item: testdata/cases/v1.0.0/item-missing-id.json [I#] [S#] doesn't validate with https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json# [I#] [S#/allOf/0] allOf failed [I#] [S#/allOf/0/$ref] doesn't validate with '/definitions/core' [I#] [S#/definitions/core/allOf/2] allOf failed [I#] [S#/definitions/core/allOf/2/required] missing properties: 'id'
Click to show internal directories.
Click to hide internal directories.