jsonschema

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Templates embed.FS

Functions

func Load

func Load(location string) (io.ReadCloser, error)

Load loads the content from location using the appropriate Loader.

func RegisterLoader

func RegisterLoader(loader Loader, schemes ...string)

RegisterLoader registers a loader for the given schemes.

func UnregisterLoader

func UnregisterLoader(scheme string)

UnregisterLoader unregisters the loader for the given scheme.

func WordSequence

func WordSequence(words []string, separator string) string

Types

type Any

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

func (Any) IsSet added in v0.6.0

func (a Any) IsSet() bool

func (Any) JSONString added in v0.5.0

func (a Any) JSONString() string

func (Any) MarshalJSON

func (a Any) MarshalJSON() ([]byte, error)

func (Any) String

func (a Any) String() string

func (*Any) UnmarshalJSON

func (a *Any) UnmarshalJSON(data []byte) error

func (Any) YAMLString added in v0.5.0

func (a Any) YAMLString() string

type CachedLoader

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

CachedLoader caches the results of another Loader in-memory.

func NewCachedLoader

func NewCachedLoader(loader Loader) *CachedLoader

NewCachedLoader wraps the given loader with one that caches results in-memory.

func (*CachedLoader) Load

func (l *CachedLoader) Load(uri *url.URL) (io.ReadCloser, error)

Load delegates to the wrapped loader and caches the result.

type Context

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

func NewContext

func NewContext() *Context

func (*Context) Get

func (c *Context) Get(ref string) (*Schema, error)

type FileLoader

type FileLoader struct {
}

FileLoader loads files from the filesystem.

func NewFileLoader

func NewFileLoader() *FileLoader

NewFileLoader returns a new FileLoader.

func (*FileLoader) Load

func (l *FileLoader) Load(uri *url.URL) (io.ReadCloser, error)

Load opens the given URI.

type HTTPLoader

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

HTTPLoader loads files via net/http.

func NewHTTPLoader

func NewHTTPLoader(client *http.Client) *HTTPLoader

NewHTTPLoader returns a new HTTPLoader.

func (*HTTPLoader) Load

func (l *HTTPLoader) Load(uri *url.URL) (io.ReadCloser, error)

Load requests the given URI via HTTP GET.

type Loader

type Loader interface {
	// Load returns an [io.ReadCloser] for the content at the given URI.
	Load(uri *url.URL) (io.ReadCloser, error)
}

Loader is a type that can load schemas from a URI.

func RegisteredLoader

func RegisteredLoader(scheme string) Loader

RegisteredLoader returns the loader registered for a scheme.

type Schema

type Schema struct {
	AdditionalItems       *Schema            `json:"additionalItems,omitempty"`
	AdditionalProperties  any                `json:"additionalProperties,omitempty"`
	AllOf                 []*Schema          `json:"allOf,omitempty"`
	AnyOf                 []*Schema          `json:"anyOf,omitempty"`
	Comment               string             `json:"$comment,omitempty"`
	Const                 Any                `json:"const,omitempty"`
	Contains              *Schema            `json:"contains,omitempty"`
	ContentEncoding       string             `json:"contentEncoding,omitempty"`
	ContentMediaType      string             `json:"contentMediaType,omitempty"`
	Default               Any                `json:"default,omitempty"`
	Definitions           map[string]*Schema `json:"definitions,omitempty"`
	Deprecated            bool               `json:"deprecated,omitempty"`
	Description           string             `json:"description,omitempty"`
	Else                  *Schema            `json:"else,omitempty"`
	Enum                  []Any              `json:"enum,omitempty"`
	EnumDescriptions      []string           `json:"enumDescriptions,omitempty"`
	Examples              []Any              `json:"examples,omitempty"`
	ExclusiveMaximum      float64            `json:"exclusiveMaximum,omitempty"`
	ExclusiveMinimum      float64            `json:"exclusiveMinimum,omitempty"`
	Format                string             `json:"format,omitempty"`
	ID                    string             `json:"$id,omitempty"`
	If                    *Schema            `json:"if,omitempty"`
	Items                 *Schema            `json:"items,omitempty"`
	MarkdownDescription   string             `json:"markdownDescription,omitempty"`
	MaxContains           int                `json:"maxContains,omitempty"`
	Maximum               float64            `json:"maximum,omitempty"`
	MaxItems              int                `json:"maxItems,omitempty"`
	MaxLength             int                `json:"maxLength,omitempty"`
	MaxProperties         int                `json:"maxProperties,omitempty"`
	MinContains           int                `json:"minContains,omitempty"`
	Minimum               float64            `json:"minimum,omitempty"`
	MinItems              int                `json:"minItems,omitempty"`
	MinLength             int                `json:"minLength,omitempty"`
	MinProperties         int                `json:"minProperties,omitempty"`
	MultipleOf            float64            `json:"multipleOf,omitempty"`
	Not                   []*Schema          `json:"not,omitempty"`
	OneOf                 []*Schema          `json:"oneOf,omitempty"`
	Pattern               string             `json:"pattern,omitempty"`
	PatternProperties     map[string]*Schema `json:"patternProperties,omitempty"`
	PrefixItems           []*Schema          `json:"prefixItems,omitempty"`
	Properties            map[string]*Schema `json:"properties,omitempty"`
	PropertyNames         *Schema            `json:"propertyNames,omitempty"`
	ReadOnly              bool               `json:"readOnly,omitempty"`
	Ref                   string             `json:"$ref,omitempty"`
	Required              []string           `json:"required,omitempty"`
	Schema                string             `json:"$schema,omitempty"`
	Then                  *Schema            `json:"then,omitempty"`
	Title                 string             `json:"title,omitempty"`
	Types                 Types              `json:"type,omitempty"`
	UnevaluatedProperties bool               `json:"unevaluatedProperties,omitempty"`
	UniqueItems           bool               `json:"uniqueItems,omitempty"`
	WriteOnly             bool               `json:"writeOnly,omitempty"`

	Context      *Context        `json:"-"`
	Document     any             `json:"-"`
	GenPathTpl   render.Template `json:"-"`
	Key          string          `json:"key,omitempty"`
	Parent       *Schema         `json:"-"`
	Resolved     bool            `json:"resolved,omitempty"`
	RetrievalURI string          `json:"retrievalURI,omitempty"`
}

Schema represents a JSON schema document.

func (*Schema) BaseURI

func (s *Schema) BaseURI() *url.URL

BaseURI returns the resolved base URI for the schema. The base URI is the schema $id attribute resolved against the retrieval URI.

func (*Schema) Clone

func (s *Schema) Clone() (*Schema, error)

Clone returns a deep-copied clone of the receiver.

func (*Schema) DescriptionMarkdown added in v0.4.0

func (s *Schema) DescriptionMarkdown() string

DescriptionMarkdown returns the schema description formatted as Markdown, Will prioritize the non-standard `markdownDescription` attribute if present, otherwise uses `description`.

func (*Schema) EnsureDocument

func (s *Schema) EnsureDocument()
func (s *Schema) EntityLink() string

func (*Schema) EntityName

func (s *Schema) EntityName() string

func (*Schema) EnumMarkdownItems added in v0.6.0

func (s *Schema) EnumMarkdownItems() []string

EnumMarkdownItems returns the .Enum items formatted as Markdown. If .Const is present, will treat that as a virtual enum of one.

func (*Schema) GenPath

func (s *Schema) GenPath() string

func (*Schema) Merge

func (s *Schema) Merge(other *Schema)

Merge merges fields from other into the receiver.

func (*Schema) RefURI

func (s *Schema) RefURI(ref string) *url.URL

RefURI resolves the given ref against the base URI.

func (*Schema) RequiredKey

func (s *Schema) RequiredKey(key string) bool

RequiredKey returns true when key is a required property.

func (*Schema) Root

func (s *Schema) Root() *Schema

Root returns the root schema.

func (*Schema) TypeInfo

func (s *Schema) TypeInfo() []TypeInfo

func (*Schema) TypeInfoMarkdown

func (s *Schema) TypeInfoMarkdown() string

func (*Schema) YAMLExamples added in v0.6.0

func (s *Schema) YAMLExamples() []string

YAMLExamples returns the examples formatted as YAML.

type Type

type Type string
const (
	TypeArray   Type = "array"
	TypeBoolean Type = "boolean"
	TypeInteger Type = "integer"
	TypeNull    Type = "null"
	TypeNumber  Type = "number"
	TypeObject  Type = "object"
	TypeString  Type = "string"
)

type TypeInfo

type TypeInfo struct {
	Type   Type
	Schema *Schema
}

func (TypeInfo) Markdown

func (ti TypeInfo) Markdown() string

type Types

type Types []Type

func (*Types) Contains

func (ts *Types) Contains(val Type) bool

Contains returns true if the receiver contains val.

func (*Types) UnmarshalJSON

func (ts *Types) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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