jsonschema

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2022 License: Apache-2.0 Imports: 10 Imported by: 4

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
}

func (AdditionalProperties) MarshalJSON

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

func (*AdditionalProperties) UnmarshalJSON

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

type Discriminator

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

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(bytes []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

func (*Parser) Parse

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

func (*Parser) Resolve added in v0.27.0

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

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

func (RawPatternProperties) MarshalJSON added in v0.23.0

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

func (*RawPatternProperties) UnmarshalJSON added in v0.23.0

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

type RawPatternProperty added in v0.23.0

type RawPatternProperty struct {
	Pattern string
	Schema  *RawSchema
}

type RawProperties

type RawProperties []RawProperty

func (RawProperties) MarshalJSON

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

func (*RawProperties) UnmarshalJSON

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

type RawProperty

type RawProperty struct {
	Name   string
	Schema *RawSchema
}

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:"-"`
}

func (*RawSchema) UnmarshalJSON added in v0.25.0

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

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)

type SchemaType

type SchemaType string

SchemaType is a JSON Schema type.

const (
	Empty   SchemaType = "" // OneOf, AnyOf, AllOf.
	Object  SchemaType = "object"
	Array   SchemaType = "array"
	Integer SchemaType = "integer"
	Number  SchemaType = "number"
	String  SchemaType = "string"
	Boolean SchemaType = "boolean"
	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
}

Jump to

Keyboard shortcuts

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