definition

package
v0.25.6 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContentEncoding

func NewContentEncoding() jsonschema.Keyword

NewContentEncoding allocates a new ContentEncoding validator

func NewRootSchema

func NewRootSchema() *jsonschema.Schema

NewRootSchema returns a jsonschema.RootSchema with any needed custom jsonschema.Validators pre-registered

Types

type ContentEncoding

type ContentEncoding string

ContentEncoding represents a "custom" Schema property

func (ContentEncoding) Register

func (c ContentEncoding) Register(uri string, registry *jsonschema.SchemaRegistry)

func (ContentEncoding) Resolve

func (c ContentEncoding) Resolve(pointer jsonpointer.Pointer, uri string) *jsonschema.Schema

func (ContentEncoding) Validate

func (c ContentEncoding) Validate(propPath string, data interface{}, errs *[]jsonschema.KeyError)

func (ContentEncoding) ValidateKeyword

func (c ContentEncoding) ValidateKeyword(ctx context.Context, currentState *jsonschema.ValidationState, data interface{})

type Definitions

type Definitions map[string]*Schema

type Schema

type Schema struct {
	Schema               string                 `json:"$schema,omitempty" yaml:"$schema,omitempty"`
	Comment              string                 `json:"$comment,omitempty" yaml:"$comment,omitempty"`
	ID                   string                 `json:"$id,omitempty" yaml:"$id,omitempty"`
	Ref                  string                 `json:"$ref,omitempty" yaml:"$ref,omitempty"`
	AdditionalItems      interface{}            `json:"additionalItems,omitempty" yaml:"additionalItems,omitempty"`
	AdditionalProperties interface{}            `json:"additionalProperties,omitempty" yaml:"additionalProperties,omitempty"`
	AllOf                []*Schema              `json:"allOf,omitempty" yaml:"allOf,omitempty"`
	Const                interface{}            `json:"const,omitempty" yaml:"const,omitempty"`
	Contains             *Schema                `json:"contains,omitempty" yaml:"contains,omitempty"`
	ContentEncoding      string                 `json:"contentEncoding,omitempty" yaml:"contentEncoding,omitempty"`
	ContentMediaType     string                 `json:"contentMediaType,omitempty" yaml:"contentMediaType,omitempty"`
	Default              interface{}            `json:"default,omitempty" yaml:"default,omitempty"`
	Definitions          Definitions            `json:"definitions,omitempty" yaml:"definitions,omitempty"`
	Dependencies         map[string]interface{} `json:"dependencies,omitempty" yaml:"dependencies,omitempty"`
	Description          string                 `json:"description,omitempty" yaml:"description,omitempty"`
	Else                 *Schema                `json:"else,omitempty" yaml:"else,omitempty"`
	Enum                 []interface{}          `json:"enum,omitempty" yaml:"enum,omitempty"`
	Examples             []interface{}          `json:"examples,omitempty" yaml:"examples,omitempty"`
	ExclusiveMaximum     *float64               `json:"exclusiveMaximum,omitempty" yaml:"exclusiveMaximum,omitempty"`
	ExclusiveMinimum     *float64               `json:"exclusiveMinimum,omitempty" yaml:"exclusiveMinimum,omitempty"`
	Format               string                 `json:"format,omitempty" yaml:"format,omitempty"`
	If                   *Schema                `json:"if,omitempty" yaml:"if,omitempty"`
	//Items can be a Schema or an Array of Schema :(
	Items         interface{} `json:"items,omitempty" yaml:"items,omitempty"`
	Maximum       *float64    `json:"maximum,omitempty" yaml:"maximum,omitempty"`
	MaxLength     *int        `json:"maxLength,omitempty" yaml:"maxLength,omitempty"`
	MinItems      *int        `json:"minItems,omitempty" yaml:"minItems,omitempty"`
	MinLength     *int        `json:"minLength,omitempty" yaml:"minLength,omitempty"`
	MinProperties *int        `json:"minProperties,omitempty" yaml:"minProperties,omitempty"`
	Minimum       *float64    `json:"minimum,omitempty" yaml:"minimum,omitempty"`
	MultipleOf    *float64    `json:"multipleOf,omitempty" yaml:"multipleOf,omitempty"`
	Not           *Schema     `json:"not,omitempty" yaml:"not,omitempty"`
	OneOf         *Schema     `json:"oneOf,omitempty" yaml:"oneOf,omitempty"`

	PatternProperties map[string]*Schema `json:"patternProperties,omitempty" yaml:"patternProperties,omitempty"`

	Properties    map[string]*Schema `json:"properties,omitempty" yaml:"properties,omitempty"`
	PropertyNames *Schema            `json:"propertyNames,omitempty" yaml:"propertyNames,omitempty"`
	ReadOnly      *bool              `json:"readOnly,omitempty" yaml:"readOnly,omitempty"`
	Required      []string           `json:"required,omitempty" yaml:"required,omitempty"`
	Then          *Schema            `json:"then,omitempty" yaml:"then,omitempty"`
	Title         string             `json:"title,omitempty" yaml:"title,omitempty"`
	Type          interface{}        `json:"type,omitempty" yaml:"type,omitempty"`
	UniqueItems   *bool              `json:"uniqueItems,omitempty" yaml:"uniqueItems,omitempty"`
	WriteOnly     *bool              `json:"writeOnly,omitempty" yaml:"writeOnly,omitempty"`
}

Schema represents a JSON Schema compatible CNAB Definition

func (*Schema) CoerceValue

func (s *Schema) CoerceValue(value interface{}) interface{}

CoerceValue can be used to turn float and other numeric types into integers. When unmarshaled, often integer values are not represented as an integer. This is a convenience method.

func (*Schema) ConvertValue

func (s *Schema) ConvertValue(val string) (interface{}, error)

ConvertValue attempts to convert the given string value to the type from the definition. Note: this is only applicable to string, number, integer and boolean types

func (*Schema) GetType

func (s *Schema) GetType() (string, bool, error)

GetType will return the singular type for a given schema and a success boolean. If the schema does not have a single type, it will return the false boolean and an error.

func (*Schema) GetTypes

func (s *Schema) GetTypes() ([]string, bool, error)

GetTypes will return the types (as a slice) for a given schema and a success boolean. If the schema has a single type, it will return the false boolean and an error.

func (*Schema) UnmarshalJSON

func (s *Schema) UnmarshalJSON(data []byte) error

UnmarshalJSON provides an implementation of a JSON unmarshaler that uses the github.com/qri-io/jsonschema to load and validate a given schema. If it is valid, then the json is unmarshaled.

func (*Schema) Validate

func (s *Schema) Validate(data interface{}) ([]ValidationError, error)

Validate applies JSON Schema validation to the data passed as a parameter. If validation errors occur, they will be returned in as a slice of ValidationError structs. If any other error occurs, it will be returned as a separate error

func (*Schema) ValidateSchema

func (s *Schema) ValidateSchema() (*jsonschema.Schema, error)

ValidateSchema validates that the Schema is valid JSON Schema. If no errors occur, the validated jsonschema.Schema is returned.

type ValidationError

type ValidationError struct {
	Path  string
	Error string
}

ValidationError error represents a validation error against the JSON Schema. The type includes the path in the given object and the error message

Jump to

Keyboard shortcuts

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