jsonschema

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2022 License: Apache-2.0 Imports: 10 Imported by: 14 modules, 8 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdditionalProperties

type AdditionalProperties struct {
	Bool   *bool
	Schema RawSchema
}

AdditionalProperties is JSON Schema additionalProperties validator description.

func (AdditionalProperties) MarshalJSON

func (p AdditionalProperties) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*AdditionalProperties) UnmarshalJSON

func (p *AdditionalProperties) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type Discriminator

type Discriminator struct {
	PropertyName string            `json:"propertyName"`
	Mapping      map[string]string `json:"mapping,omitempty"`
}

Discriminator is JSON Schema discriminator description.

type Num added in v0.16.0

type Num jx.Num

Num represents JSON number.

func (Num) MarshalJSON added in v0.17.1

func (n Num) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Num) UnmarshalJSON added in v0.16.0

func (n *Num) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type Parser

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

Parser parses JSON schemas.

func NewParser

func NewParser(s Settings) *Parser

NewParser creates new Parser.

func (*Parser) Parse

func (p *Parser) Parse(schema *RawSchema) (*Schema, error)

Parse parses given RawSchema and returns parsed Schema.

func (*Parser) Resolve added in v0.27.0

func (p *Parser) Resolve(ref string) (*Schema, error)

Resolve resolves Schema by given ref.

type PatternProperty added in v0.23.0

type PatternProperty struct {
	Pattern *regexp.Regexp
	Schema  *Schema
}

PatternProperty is a property pattern.

type Property

type Property struct {
	Name        string  // Property name.
	Description string  // Property description.
	Schema      *Schema // Property schema.
	Required    bool    // Whether the field is required or not.
}

Property is a JSON Schema Object property.

type RawPatternProperties added in v0.23.0

type RawPatternProperties []RawPatternProperty

RawPatternProperties is unparsed JSON Schema patternProperties validator description.

func (RawPatternProperties) MarshalJSON added in v0.23.0

func (r RawPatternProperties) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*RawPatternProperties) UnmarshalJSON added in v0.23.0

func (r *RawPatternProperties) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type RawPatternProperty added in v0.23.0

type RawPatternProperty struct {
	Pattern string
	Schema  *RawSchema
}

RawPatternProperty is item of RawPatternProperties.

type RawProperties

type RawProperties []RawProperty

RawProperties is unparsed JSON Schema properties validator description.

func (RawProperties) MarshalJSON

func (p RawProperties) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*RawProperties) UnmarshalJSON

func (p *RawProperties) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type RawProperty

type RawProperty struct {
	Name   string
	Schema *RawSchema
}

RawProperty is item of RawProperties.

type RawSchema

type RawSchema struct {
	Ref                  string                `json:"$ref,omitempty"`
	Description          string                `json:"description,omitempty"`
	Type                 string                `json:"type,omitempty"`
	Format               string                `json:"format,omitempty"`
	Properties           RawProperties         `json:"properties,omitempty"`
	AdditionalProperties *AdditionalProperties `json:"additionalProperties,omitempty"`
	PatternProperties    RawPatternProperties  `json:"patternProperties,omitempty"`
	Required             []string              `json:"required,omitempty"`
	Items                *RawSchema            `json:"items,omitempty"`
	Nullable             bool                  `json:"nullable,omitempty"`
	AllOf                []*RawSchema          `json:"allOf,omitempty"`
	OneOf                []*RawSchema          `json:"oneOf,omitempty"`
	AnyOf                []*RawSchema          `json:"anyOf,omitempty"`
	Discriminator        *Discriminator        `json:"discriminator,omitempty"`
	Enum                 []json.RawMessage     `json:"enum,omitempty"`
	MultipleOf           Num                   `json:"multipleOf,omitempty"`
	Maximum              Num                   `json:"maximum,omitempty"`
	ExclusiveMaximum     bool                  `json:"exclusiveMaximum,omitempty"`
	Minimum              Num                   `json:"minimum,omitempty"`
	ExclusiveMinimum     bool                  `json:"exclusiveMinimum,omitempty"`
	MaxLength            *uint64               `json:"maxLength,omitempty"`
	MinLength            *uint64               `json:"minLength,omitempty"`
	Pattern              string                `json:"pattern,omitempty"`
	MaxItems             *uint64               `json:"maxItems,omitempty"`
	MinItems             *uint64               `json:"minItems,omitempty"`
	UniqueItems          bool                  `json:"uniqueItems,omitempty"`
	MaxProperties        *uint64               `json:"maxProperties,omitempty"`
	MinProperties        *uint64               `json:"minProperties,omitempty"`
	Default              json.RawMessage       `json:"default,omitempty"`
	Example              json.RawMessage       `json:"example,omitempty"`
	Deprecated           bool                  `json:"deprecated,omitempty"`
	XAnnotations         map[string]jx.Raw     `json:"-"`
}

RawSchema is unparsed JSON Schema.

func (*RawSchema) UnmarshalJSON added in v0.25.0

func (r *RawSchema) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type ReferenceResolver

type ReferenceResolver interface {
	ResolveReference(ref string) (*RawSchema, error)
}

ReferenceResolver resolves JSON schema references.

type RootResolver added in v0.22.0

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

RootResolver is ReferenceResolver implementation.

func NewRootResolver added in v0.22.0

func NewRootResolver(root []byte) *RootResolver

NewRootResolver creates new RootResolver.

func (RootResolver) ResolveReference added in v0.22.0

func (r RootResolver) ResolveReference(ref string) (rawSchema *RawSchema, err error)

ResolveReference implements ReferenceResolver.

type Schema

type Schema struct {
	XOgenName string // Annotation to set type name.

	Type        SchemaType
	Format      string // Schema format, optional.
	Description string // Schema description, optional.
	Ref         string // Whether schema is referenced.

	Item                 *Schema           // Only for Array and Object with additional properties.
	AdditionalProperties *bool             // Whether Object has additional properties.
	PatternProperties    []PatternProperty // Only for Object.
	Enum                 []interface{}     // Only for Enum.
	Properties           []Property        // Only for Object.

	Nullable bool // Whether schema is nullable or not. Any types.

	OneOf         []*Schema
	AnyOf         []*Schema
	AllOf         []*Schema
	Discriminator *Discriminator

	// Numeric validation (Integer, Number).
	Maximum          Num
	ExclusiveMaximum bool
	Minimum          Num
	ExclusiveMinimum bool
	MultipleOf       Num

	// String validation.
	MaxLength *uint64
	MinLength *uint64
	Pattern   string

	// Array validation.
	MaxItems    *uint64
	MinItems    *uint64
	UniqueItems bool

	// Object validation.
	MaxProperties *uint64
	MinProperties *uint64

	Examples []json.RawMessage
	// Default schema value.
	Default    interface{}
	DefaultSet bool
}

Schema is a JSON Schema.

func (*Schema) AddExample

func (s *Schema) AddExample(r json.RawMessage)

AddExample adds example for this Schema.

type SchemaType

type SchemaType string

SchemaType is a JSON Schema type.

const (
	// Empty is empty (unset) schema type.
	Empty SchemaType = "" // OneOf, AnyOf, AllOf.
	// Object is "object" schema type.
	Object SchemaType = "object"
	// Array is "array" schema type.
	Array SchemaType = "array"
	// Integer is "integer" schema type.
	Integer SchemaType = "integer"
	// Number is "number" schema type.
	Number SchemaType = "number"
	// String is "string" schema type.
	String SchemaType = "string"
	// Boolean is "boolean" schema type.
	Boolean SchemaType = "boolean"
	// Null is "null" schema type.
	Null SchemaType = "null"
)

type Settings

type Settings struct {
	Resolver ReferenceResolver

	// Enables type inference.
	//
	// For example:
	//
	//	{
	//		"items": {
	//			"type": "string"
	//		}
	//	}
	//
	// In that case schemaParser will handle that schema as "array" schema, because it has "items" field.
	InferTypes bool
}

Settings is parser settings.

Jump to

Keyboard shortcuts

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