jsonschema

package
v0.19.2 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2022 License: Apache-2.0 Imports: 5 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)

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

type ReferenceResolver

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

ReferenceResolver resolves JSON schema references.

type Schema

type Schema struct {
	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.
	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"
)

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