validator

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

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
}

Options for the Validator.

type ValidationError added in v0.3.0

type ValidationError struct {
	*jsonschema.ValidationError

	// Resource is the file path or URL to the resource that failed validation.
	Resource string
}

ValidationError holds details about a validation error.

func (*ValidationError) GoString added in v0.3.0

func (err *ValidationError) GoString() string

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator allows validation of STAC resources.

func New

func New(options *Options) *Validator

New creates a new Validator.

func (*Validator) Validate

func (v *Validator) Validate(ctx context.Context, resource string) error

Validate validates a STAC resource.

The resource can be a path to a local file or a URL.

Example (Children)
package main

import (
	"context"
	"fmt"

	"github.com/planetlabs/go-stac/pkg/crawler"
	"github.com/planetlabs/go-stac/pkg/validator"
)

func main() {
	v := validator.New(&validator.Options{
		Concurrency: 1,
		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 resource: 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/pkg/crawler"
	"github.com/planetlabs/go-stac/pkg/validator"
)

func main() {
	v := validator.New(&validator.Options{
		Concurrency: 1,
		Recursion:   crawler.None,
	})

	err := v.Validate(context.Background(), "testdata/cases/v1.0.0/item-missing-id.json")
	fmt.Printf("%#v\n", err)
}
Output:

invalid resource: 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'

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL