schema

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2022 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FormatBinary          = "binary"
	FormatByte            = "byte" // Alias to "binary"
	FormatDefault         = ""
	FormatDate            = "date"
	FormatDateTime        = "date-time"
	FormatDurationRFC3339 = "duration"
	FormatDurationGo      = "duration-go"
	FormatEmail           = "email"
	FormatHostname        = "hostname"
	FormatIDNEmail        = "idn-email"
	FormatIDNHostname     = "idn-hostname"
	FormatIP              = "ip"
	FormatIPCIDR          = "ip-cidr"
	FormatIPv4            = "ipv4"
	FormatIPv4CIDR        = "ipv4-cidr"
	FormatIPv6            = "ipv6"
	FormatIPv6CIDR        = "ipv6-cidr"
	FormatIRI             = "iri"
	FormatIRIReference    = "iri-reference"
	FormatRegex           = "regex"
	FormatTime            = "time"
	FormatURI             = "uri"
	FormatURIReference    = "uri-reference"
	FormatUUID            = "uuid"
)
View Source
const Epsilon = 0.000000001

Epsilon is used as a float64 comparison tolerance

View Source
const (
	FormatConflowID = "conflow.ID"
)
View Source
const NameRegExpPattern = "[a-z][a-z0-9]*(?:_[a-z0-9]+)*"

NameRegExpPattern is the regular expression for a valid identifier

Variables

View Source
var ErrMetadataReadOnly = errors.New("metadata is read-only")
View Source
var FieldNameRegexp = regexp.MustCompile("^[_a-zA-Z][_a-zA-Z0-9]*$")
View Source
var NameRegExp = regexp.MustCompile("^" + NameRegExpPattern + "$")

NameRegExp is a compiled regular expression object for a valid identifier

Functions

func NumberEquals

func NumberEquals(a, b float64) bool

func NumberGreaterThan

func NumberGreaterThan(v1, v2 float64) bool

func NumberGreaterThanOrEqualsTo

func NumberGreaterThanOrEqualsTo(v1, v2 float64) bool

func NumberLessThan

func NumberLessThan(v1, v2 float64) bool

func NumberLessThanOrEqualsTo

func NumberLessThanOrEqualsTo(v1, v2 float64) bool

func NumberMultipleOf

func NumberMultipleOf(v1, v2 float64) bool

func Pointer

func Pointer[V any](v V) *V

func Register

func Register(s Schema)

func RegisterFormat

func RegisterFormat(name string, format Format)

func RegisterResolver

func RegisterResolver(uri string, res Resolver)

func UnregisterFormat

func UnregisterFormat(name string)

func UpdateMetadata

func UpdateMetadata(s Schema, f func(meta MetadataAccessor) error) error

func ValueOf

func ValueOf[V any](v *V) (r V)

Types

type AllOf

type AllOf struct {
	// @name "schema"
	// @required
	// @min_items 1
	Schemas []Schema `json:"allOf"`
	// @ignore
	Schema `json:"-"`
}

func (*AllOf) AssignValue

func (a *AllOf) AssignValue(imports map[string]string, valueName, resultName string) string

func (*AllOf) CompareValues

func (a *AllOf) CompareValues(v1, v2 interface{}) int

func (*AllOf) Copy

func (a *AllOf) Copy() Schema

func (*AllOf) DefaultValue

func (a *AllOf) DefaultValue() interface{}

func (*AllOf) GoString

func (a *AllOf) GoString(imports map[string]string) string

func (*AllOf) GoType

func (a *AllOf) GoType(imports map[string]string) string

func (*AllOf) StringValue

func (a *AllOf) StringValue(value interface{}) string

func (*AllOf) Type

func (a *AllOf) Type() Type

func (*AllOf) TypeString

func (a *AllOf) TypeString() string

func (*AllOf) UnmarshalJSON

func (a *AllOf) UnmarshalJSON(j []byte) error

func (*AllOf) ValidateSchema

func (a *AllOf) ValidateSchema(s Schema, compare bool) error

func (*AllOf) ValidateValue

func (a *AllOf) ValidateValue(value interface{}) (interface{}, error)

type Array

type Array struct {
	Metadata

	Const   []interface{}   `json:"const,omitempty"`
	Default []interface{}   `json:"default,omitempty"`
	Enum    [][]interface{} `json:"enum,omitempty"`
	// @required
	Items       Schema `json:"items,omitempty"`
	MinItems    int64  `json:"minItems,omitempty"`
	MaxItems    *int64 `json:"maxItems,omitempty"`
	UniqueItems bool   `json:"uniqueItems,omitempty"`
}

func (*Array) AssignValue

func (a *Array) AssignValue(imports map[string]string, valueName, resultName string) string

func (*Array) CompareValues

func (a *Array) CompareValues(v1, v2 interface{}) int

func (*Array) Copy

func (a *Array) Copy() Schema

func (*Array) DefaultValue

func (a *Array) DefaultValue() interface{}

func (*Array) GetItems

func (a *Array) GetItems() Schema

func (*Array) GoString

func (a *Array) GoString(imports map[string]string) string

func (*Array) GoType

func (a *Array) GoType(imports map[string]string) string

func (*Array) MarshalJSON

func (a *Array) MarshalJSON() ([]byte, error)

func (*Array) StringValue

func (a *Array) StringValue(value interface{}) string

func (*Array) Type

func (a *Array) Type() Type

func (*Array) TypeString

func (a *Array) TypeString() string

func (*Array) UnmarshalJSON

func (a *Array) UnmarshalJSON(j []byte) error

func (*Array) ValidateSchema

func (a *Array) ValidateSchema(s Schema, compare bool) error

func (*Array) ValidateValue

func (a *Array) ValidateValue(value interface{}) (interface{}, error)

type Boolean

type Boolean struct {
	Metadata

	Const    *bool  `json:"const,omitempty"`
	Default  *bool  `json:"default,omitempty"`
	Enum     []bool `json:"enum,omitempty"`
	Nullable bool   `json:"nullable,omitempty"`
}

func (*Boolean) AssignValue

func (b *Boolean) AssignValue(imports map[string]string, valueName, resultName string) string

func (*Boolean) CompareValues

func (b *Boolean) CompareValues(v1, v2 interface{}) int

func (*Boolean) Copy

func (b *Boolean) Copy() Schema

func (*Boolean) DefaultValue

func (b *Boolean) DefaultValue() interface{}

func (*Boolean) GetNullable

func (b *Boolean) GetNullable() bool

func (*Boolean) GoString

func (b *Boolean) GoString(imports map[string]string) string

func (*Boolean) GoType

func (b *Boolean) GoType(_ map[string]string) string

func (*Boolean) MarshalJSON

func (b *Boolean) MarshalJSON() ([]byte, error)

func (*Boolean) SetNullable

func (b *Boolean) SetNullable(nullable bool)

func (*Boolean) StringValue

func (b *Boolean) StringValue(value interface{}) string

func (*Boolean) Type

func (b *Boolean) Type() Type

func (*Boolean) TypeString

func (b *Boolean) TypeString() string

func (*Boolean) UnmarshalJSON

func (b *Boolean) UnmarshalJSON(input []byte) error

func (*Boolean) ValidateSchema

func (b *Boolean) ValidateSchema(b2 Schema, _ bool) error

func (*Boolean) ValidateValue

func (b *Boolean) ValidateValue(value interface{}) (interface{}, error)

type ByteStream

type ByteStream struct {
	Metadata
}

func (*ByteStream) AssignValue

func (b *ByteStream) AssignValue(imports map[string]string, valueName, resultName string) string

func (*ByteStream) CompareValues

func (b *ByteStream) CompareValues(v1, v2 interface{}) int

func (*ByteStream) Copy

func (b *ByteStream) Copy() Schema

func (*ByteStream) DefaultValue

func (b *ByteStream) DefaultValue() interface{}

func (*ByteStream) GoString

func (b *ByteStream) GoString(imports map[string]string) string

func (*ByteStream) GoType

func (b *ByteStream) GoType(imports map[string]string) string

func (*ByteStream) MarshalJSON

func (b *ByteStream) MarshalJSON() ([]byte, error)

func (*ByteStream) StringValue

func (b *ByteStream) StringValue(value interface{}) string

func (*ByteStream) Type

func (b *ByteStream) Type() Type

func (*ByteStream) TypeString

func (b *ByteStream) TypeString() string

func (*ByteStream) ValidateSchema

func (b *ByteStream) ValidateSchema(s2 Schema, compare bool) error

func (*ByteStream) ValidateValue

func (b *ByteStream) ValidateValue(value interface{}) (interface{}, error)

type Directive

type Directive interface {
	ApplyToSchema(Schema) error
}

type FieldError

type FieldError struct {
	Field string `json:"field"`
	Err   error  `json:"error"`
}

func NewFieldError

func NewFieldError(field string, err error) FieldError

func NewFieldErrorf

func NewFieldErrorf(field, format string, a ...interface{}) FieldError

func (FieldError) Error

func (f FieldError) Error() string

type Format

type Format interface {
	Type() (reflect.Type, bool)
	StringValue(input interface{}) (string, bool)
	ValidateValue(input string) (interface{}, error)
}

func GetFormat

func GetFormat(name string) (Format, bool)

func GetFormatForType

func GetFormatForType(path string) (string, Format, bool)

type Function

type Function struct {
	Metadata

	AdditionalParameters *NamedSchema `json:"additionalParameters,omitempty"`
	Parameters           Parameters   `json:"parameters,omitempty"`
	Result               Schema       `json:"result,omitempty"`
	ResultTypeFrom       string       `json:"resultTypeFrom,omitempty"`
}

func (*Function) AssignValue

func (f *Function) AssignValue(_ map[string]string, _, _ string) string

func (*Function) CompareValues

func (f *Function) CompareValues(_, _ interface{}) int

func (*Function) Copy

func (f *Function) Copy() Schema

func (*Function) DefaultValue

func (f *Function) DefaultValue() interface{}

func (*Function) GetAdditionalParameters

func (f *Function) GetAdditionalParameters() *NamedSchema

func (*Function) GetParameters

func (f *Function) GetParameters() Parameters

func (*Function) GetResult

func (f *Function) GetResult() Schema

func (*Function) GetResultTypeFrom

func (f *Function) GetResultTypeFrom() string

func (*Function) GoString

func (f *Function) GoString(imports map[string]string) string

func (*Function) GoType

func (f *Function) GoType(imports map[string]string) string

func (*Function) MarshalJSON

func (f *Function) MarshalJSON() ([]byte, error)

func (*Function) StringValue

func (f *Function) StringValue(interface{}) string

func (*Function) Type

func (f *Function) Type() Type

func (*Function) TypeString

func (f *Function) TypeString() string

func (*Function) UnmarshalJSON

func (f *Function) UnmarshalJSON(j []byte) error

func (*Function) ValidateSchema

func (f *Function) ValidateSchema(s Schema, compare bool) error

func (*Function) ValidateValue

func (f *Function) ValidateValue(value interface{}) (interface{}, error)

type Integer

type Integer struct {
	Metadata

	Const            *int64  `json:"const,omitempty"`
	Default          *int64  `json:"default,omitempty"`
	Enum             []int64 `json:"enum,omitempty"`
	ExclusiveMinimum *int64  `json:"exclusiveMinimum,omitempty"`
	ExclusiveMaximum *int64  `json:"exclusiveMaximum,omitempty"`
	// @enum ["int32", "int64"]
	Format     string `json:"format,omitempty"`
	Maximum    *int64 `json:"maximum,omitempty"`
	Minimum    *int64 `json:"minimum,omitempty"`
	Nullable   bool   `json:"nullable,omitempty"`
	MultipleOf *int64 `json:"multipleOf,omitempty"`
}

func (*Integer) AssignValue

func (i *Integer) AssignValue(imports map[string]string, valueName, resultName string) string

func (*Integer) CompareValues

func (i *Integer) CompareValues(v1, v2 interface{}) int

func (*Integer) Copy

func (i *Integer) Copy() Schema

func (*Integer) DefaultValue

func (i *Integer) DefaultValue() interface{}

func (*Integer) GetNullable

func (i *Integer) GetNullable() bool

func (*Integer) GoString

func (i *Integer) GoString(imports map[string]string) string

func (*Integer) GoType

func (i *Integer) GoType(_ map[string]string) string

func (*Integer) MarshalJSON

func (i *Integer) MarshalJSON() ([]byte, error)

func (*Integer) SetNullable

func (i *Integer) SetNullable(nullable bool)

func (*Integer) StringValue

func (i *Integer) StringValue(value interface{}) string

func (*Integer) Type

func (i *Integer) Type() Type

func (*Integer) TypeString

func (i *Integer) TypeString() string

func (*Integer) UnmarshalJSON

func (i *Integer) UnmarshalJSON(input []byte) error

func (*Integer) ValidateSchema

func (i *Integer) ValidateSchema(i2 Schema, compare bool) error

func (*Integer) ValidateValue

func (i *Integer) ValidateValue(value interface{}) (interface{}, error)

type Map

type Map struct {
	Metadata

	// @required
	AdditionalProperties Schema                   `json:"additionalProperties,omitempty"`
	Const                map[string]interface{}   `json:"const,omitempty"`
	Default              map[string]interface{}   `json:"default,omitempty"`
	Enum                 []map[string]interface{} `json:"enum,omitempty"`
	MinProperties        int64                    `json:"minProperties,omitempty"`
	MaxProperties        *int64                   `json:"maxProperties,omitempty"`
}

func (*Map) AssignValue

func (m *Map) AssignValue(imports map[string]string, valueName, resultName string) string

func (*Map) CompareValues

func (m *Map) CompareValues(v1, v2 interface{}) int

func (*Map) Copy

func (m *Map) Copy() Schema

func (*Map) DefaultValue

func (m *Map) DefaultValue() interface{}

func (*Map) GetAdditionalProperties

func (m *Map) GetAdditionalProperties() Schema

func (*Map) GoString

func (m *Map) GoString(imports map[string]string) string

func (*Map) GoType

func (m *Map) GoType(imports map[string]string) string

func (*Map) MarshalJSON

func (m *Map) MarshalJSON() ([]byte, error)

func (*Map) StringValue

func (m *Map) StringValue(value interface{}) string

func (*Map) Type

func (m *Map) Type() Type

func (*Map) TypeString

func (m *Map) TypeString() string

func (*Map) UnmarshalJSON

func (m *Map) UnmarshalJSON(j []byte) error

func (*Map) ValidateSchema

func (m *Map) ValidateSchema(s Schema, compare bool) error

func (*Map) ValidateValue

func (m *Map) ValidateValue(value interface{}) (interface{}, error)

type Metadata

type Metadata struct {
	Annotations map[string]string `json:"annotations,omitempty"`
	Deprecated  bool              `json:"deprecated,omitempty"`
	Description string            `json:"description,omitempty"`
	Examples    []interface{}     `json:"examples,omitempty"`
	ID          string            `json:"$id,omitempty"`
	ReadOnly    bool              `json:"readOnly,omitempty"`
	Title       string            `json:"title,omitempty"`
	WriteOnly   bool              `json:"writeOnly,omitempty"`
}

Metadata contains common metadata for schemas

func (*Metadata) GetAnnotation

func (m *Metadata) GetAnnotation(name string) string

func (*Metadata) GetDeprecated

func (m *Metadata) GetDeprecated() bool

func (*Metadata) GetDescription

func (m *Metadata) GetDescription() string

func (Metadata) GetExamples

func (m Metadata) GetExamples() []interface{}

func (Metadata) GetID

func (m Metadata) GetID() string

func (*Metadata) GetReadOnly

func (m *Metadata) GetReadOnly() bool

func (*Metadata) GetTitle

func (m *Metadata) GetTitle() string

func (*Metadata) GetWriteOnly

func (m *Metadata) GetWriteOnly() bool

func (*Metadata) GoString

func (m *Metadata) GoString(imports map[string]string) string

func (*Metadata) Merge

func (m *Metadata) Merge(m2 Metadata)

func (*Metadata) SetAnnotation

func (m *Metadata) SetAnnotation(name, value string)

func (*Metadata) SetDeprecated

func (m *Metadata) SetDeprecated(deprecated bool)

func (*Metadata) SetDescription

func (m *Metadata) SetDescription(description string)

func (*Metadata) SetExamples

func (m *Metadata) SetExamples(examples []interface{})

func (*Metadata) SetID

func (m *Metadata) SetID(id string)

func (*Metadata) SetReadOnly

func (m *Metadata) SetReadOnly(readOnly bool)

func (*Metadata) SetTitle

func (m *Metadata) SetTitle(title string)

func (*Metadata) SetWriteOnly

func (m *Metadata) SetWriteOnly(writeOnly bool)

type MetadataAccessor

type MetadataAccessor interface {
	Merge(Metadata)
	SetAnnotation(string, string)
	SetDeprecated(bool)
	SetDescription(string)
	SetExamples([]interface{})
	SetID(string)
	SetReadOnly(bool)
	SetTitle(string)
	SetWriteOnly(bool)
}

type NamedSchema

type NamedSchema struct {
	Name string
	Schema
}

func (NamedSchema) GoString

func (n NamedSchema) GoString(imports map[string]string) string

type NonEmptyString

type NonEmptyString = string

@min_length 1

type Null

type Null struct {
	Metadata
}

func (*Null) AssignValue

func (n *Null) AssignValue(_ map[string]string, _, resultName string) string

func (*Null) CompareValues

func (n *Null) CompareValues(v1, v2 interface{}) int

func (*Null) Copy

func (n *Null) Copy() Schema

func (*Null) DefaultValue

func (n *Null) DefaultValue() interface{}

func (*Null) GoString

func (n *Null) GoString(imports map[string]string) string

func (*Null) GoType

func (n *Null) GoType(_ map[string]string) string

func (*Null) MarshalJSON

func (n *Null) MarshalJSON() ([]byte, error)

func (*Null) StringValue

func (n *Null) StringValue(interface{}) string

func (*Null) Type

func (n *Null) Type() Type

func (*Null) TypeString

func (n *Null) TypeString() string

func (*Null) ValidateSchema

func (n *Null) ValidateSchema(n2 Schema, _ bool) error

func (*Null) ValidateValue

func (n *Null) ValidateValue(v interface{}) (interface{}, error)

type Nullable

type Nullable interface {
	GetNullable() bool
	SetNullable(bool)
}

type Number

type Number struct {
	Metadata

	Const            *float64  `json:"const,omitempty"`
	Default          *float64  `json:"default,omitempty"`
	Enum             []float64 `json:"enum,omitempty"`
	ExclusiveMinimum *float64  `json:"exclusiveMinimum,omitempty"`
	ExclusiveMaximum *float64  `json:"exclusiveMaximum,omitempty"`
	Maximum          *float64  `json:"maximum,omitempty"`
	Minimum          *float64  `json:"minimum,omitempty"`
	MultipleOf       *float64  `json:"multipleOf,omitempty"`
	Nullable         bool      `json:"nullable,omitempty"`
}

func (*Number) AssignValue

func (n *Number) AssignValue(imports map[string]string, valueName, resultName string) string

func (*Number) CompareValues

func (n *Number) CompareValues(v1, v2 interface{}) int

func (*Number) Copy

func (n *Number) Copy() Schema

func (*Number) DefaultValue

func (n *Number) DefaultValue() interface{}

func (*Number) GetNullable

func (n *Number) GetNullable() bool

func (*Number) GoString

func (n *Number) GoString(imports map[string]string) string

func (*Number) GoType

func (n *Number) GoType(_ map[string]string) string

func (*Number) MarshalJSON

func (n *Number) MarshalJSON() ([]byte, error)

func (*Number) SetNullable

func (n *Number) SetNullable(nullable bool)

func (*Number) StringValue

func (n *Number) StringValue(value interface{}) string

func (*Number) Type

func (n *Number) Type() Type

func (*Number) TypeString

func (n *Number) TypeString() string

func (*Number) UnmarshalJSON

func (n *Number) UnmarshalJSON(input []byte) error

func (*Number) ValidateSchema

func (n *Number) ValidateSchema(n2 Schema, _ bool) error

func (*Number) ValidateValue

func (n *Number) ValidateValue(value interface{}) (interface{}, error)

type Object

type Object struct {
	Metadata

	Const             map[string]interface{}   `json:"const,omitempty"`
	Default           map[string]interface{}   `json:"default,omitempty"`
	DependentRequired map[string][]string      `json:"dependentRequired,omitempty"`
	Enum              []map[string]interface{} `json:"enum,omitempty"`
	// FieldNames will contain the json property name -> field name mapping, if they are different
	// @ignore
	FieldNames map[string]string `json:"fieldNames,omitempty"`
	// ParameterNames will contain the json property name -> parameter name mapping, if they are different
	// @ignore
	ParameterNames map[string]string `json:"parameterNames,omitempty"`
	// JSONPropertyNames will contain the parameter name -> json property name mapping, if they are different
	// @ignore
	JSONPropertyNames map[string]string `json:"-"`
	MinProperties     int64             `json:"minProperties,omitempty"`
	MaxProperties     *int64            `json:"maxProperties,omitempty"`
	// @name "property"
	Properties map[string]Schema `json:"properties,omitempty"`
	// Required will contain the required parameter names
	Required []string `json:"required,omitempty"`
}

func (*Object) AssignValue

func (o *Object) AssignValue(_ map[string]string, _, _ string) string

func (*Object) CompareValues

func (o *Object) CompareValues(v1, v2 interface{}) int

func (*Object) Copy

func (o *Object) Copy() Schema

func (*Object) DefaultValue

func (o *Object) DefaultValue() interface{}

func (*Object) FieldName

func (o *Object) FieldName(parameterName string) string

FieldName returns the field name for the given parameter name

func (*Object) GoString

func (o *Object) GoString(imports map[string]string) string

func (*Object) GoType

func (o *Object) GoType(imports map[string]string) string

func (*Object) IsPropertyRequired

func (o *Object) IsPropertyRequired(jsonPropertyName string) bool

func (*Object) JSONPropertyName

func (o *Object) JSONPropertyName(parameterName string) string

JSONPropertyName returns the JSON property name for the given parameter name

func (*Object) MarshalJSON

func (o *Object) MarshalJSON() ([]byte, error)

func (*Object) ParameterName

func (o *Object) ParameterName(jsonPropertyName string) string

ParameterName returns the parameter name for the given JSON property name

func (*Object) PropertyByParameterName

func (o *Object) PropertyByParameterName(parameterName string) (Schema, bool)

func (*Object) StringValue

func (o *Object) StringValue(value interface{}) string

func (*Object) Type

func (o *Object) Type() Type

func (*Object) TypeString

func (o *Object) TypeString() string

func (*Object) UnmarshalJSON

func (o *Object) UnmarshalJSON(j []byte) error

func (*Object) ValidateSchema

func (o *Object) ValidateSchema(s Schema, compare bool) error

func (*Object) ValidateValue

func (o *Object) ValidateValue(value interface{}) (interface{}, error)

type Parameters

type Parameters []NamedSchema

func (Parameters) GoString

func (p Parameters) GoString(imports map[string]string) string

func (Parameters) MarshalJSON

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

func (*Parameters) UnmarshalJSON

func (p *Parameters) UnmarshalJSON(j []byte) error

type Reference

type Reference struct {
	Metadata

	Nullable bool `json:"nullable,omitempty"`
	// @value
	// @required
	Ref string `json:"$ref"`
	// contains filtered or unexported fields
}

func (*Reference) AssignValue

func (r *Reference) AssignValue(imports map[string]string, valueName, resultName string) string

func (*Reference) CompareValues

func (r *Reference) CompareValues(a, b interface{}) int

func (*Reference) Copy

func (r *Reference) Copy() Schema

func (*Reference) DefaultValue

func (r *Reference) DefaultValue() interface{}

func (*Reference) GetNullable

func (r *Reference) GetNullable() bool

func (*Reference) GoString

func (r *Reference) GoString(imports map[string]string) string

func (*Reference) GoType

func (r *Reference) GoType(imports map[string]string) string

func (*Reference) SetNullable

func (r *Reference) SetNullable(nullable bool)

func (*Reference) StringValue

func (r *Reference) StringValue(value interface{}) string

func (*Reference) Type

func (r *Reference) Type() Type

func (*Reference) TypeString

func (r *Reference) TypeString() string

func (*Reference) ValidateSchema

func (r *Reference) ValidateSchema(s Schema, compare bool) error

func (*Reference) ValidateValue

func (r *Reference) ValidateValue(value interface{}) (interface{}, error)

type Registry

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

func (*Registry) GetSchema

func (r *Registry) GetSchema(uri string) (Schema, error)

func (*Registry) RegisterResolver

func (r *Registry) RegisterResolver(uri string, res Resolver)

func (*Registry) RegisterSchema

func (r *Registry) RegisterSchema(s Schema)

type Resolver

type Resolver interface {
	ResolveSchema(uri string) (Schema, error)
}

type ResolverFunc

type ResolverFunc func(uri string) (Schema, error)

func (ResolverFunc) ResolveSchema

func (f ResolverFunc) ResolveSchema(uri string) (Schema, error)

type Schema

type Schema interface {
	AssignValue(imports map[string]string, valueName, resultName string) string
	CompareValues(a, b interface{}) int
	Copy() Schema
	DefaultValue() interface{}
	GetAnnotation(string) string
	GetDeprecated() bool
	GetDescription() string
	GetExamples() []interface{}
	GetID() string
	GetReadOnly() bool
	GetTitle() string
	GetWriteOnly() bool
	GoString(imports map[string]string) string
	GoType(imports map[string]string) string
	StringValue(interface{}) string
	Type() Type
	TypeString() string
	ValidateValue(interface{}) (interface{}, error)
	ValidateSchema(s Schema, compare bool) error
}

func BooleanValue

func BooleanValue() Schema

func ByteStreamValue

func ByteStreamValue() Schema

func False

func False() Schema

func Get

func Get(uri string) (Schema, error)

func GetCommonSchema

func GetCommonSchema(s1, s2 Schema) (Schema, error)

func GetSchemaForValue

func GetSchemaForValue(value interface{}) (Schema, error)

func GetSchemaForValues

func GetSchemaForValues(cnt int, s func(i int) (Schema, error)) (Schema, error)

func IntegerValue

func IntegerValue() Schema

func NullValue

func NullValue() Schema

func NumberValue

func NumberValue() Schema

func ResolveFromFile

func ResolveFromFile(uri string) (Schema, error)

func StringValue

func StringValue() Schema

func UnmarshalJSON

func UnmarshalJSON(b []byte) (Schema, error)

func UntypedValue

func UntypedValue() Schema

type SchemaUnmarshaler

type SchemaUnmarshaler struct {
	Schema Schema
}

func (*SchemaUnmarshaler) UnmarshalJSON

func (s *SchemaUnmarshaler) UnmarshalJSON(j []byte) error

type String

type String struct {
	Metadata

	Const     *string        `json:"const,omitempty"`
	Default   *string        `json:"default,omitempty"`
	Enum      []string       `json:"enum,omitempty"`
	Format    string         `json:"format,omitempty"`
	MinLength int64          `json:"minLength,omitempty"`
	MaxLength *int64         `json:"maxLength,omitempty"`
	Nullable  bool           `json:"nullable,omitempty"`
	Pattern   *regexp.Regexp `json:"pattern,omitempty"`
}

func (*String) AssignValue

func (s *String) AssignValue(imports map[string]string, valueName, resultName string) string

func (*String) CompareValues

func (s *String) CompareValues(v1, v2 interface{}) int

func (*String) Copy

func (s *String) Copy() Schema

func (*String) DefaultValue

func (s *String) DefaultValue() interface{}

func (*String) GetNullable

func (s *String) GetNullable() bool

func (*String) GoString

func (s *String) GoString(imports map[string]string) string

func (*String) GoType

func (s *String) GoType(imports map[string]string) string

func (*String) MarshalJSON

func (s *String) MarshalJSON() ([]byte, error)

func (*String) SetNullable

func (s *String) SetNullable(nullable bool)

func (*String) StringValue

func (s *String) StringValue(value interface{}) string

func (*String) Type

func (s *String) Type() Type

func (*String) TypeString

func (s *String) TypeString() string

func (*String) UnmarshalJSON

func (s *String) UnmarshalJSON(input []byte) error

func (*String) ValidateSchema

func (s *String) ValidateSchema(s2 Schema, _ bool) error

func (*String) ValidateValue

func (s *String) ValidateValue(value interface{}) (interface{}, error)

type Type

type Type string
const (
	TypeUntyped    Type = ""
	TypeArray      Type = "array"
	TypeByteStream Type = "byte_stream"
	TypeBoolean    Type = "boolean"
	TypeFalse      Type = "false"
	TypeFunction   Type = "function"
	TypeInteger    Type = "integer"
	TypeMap        Type = "map"
	TypeNull       Type = "null"
	TypeNumber     Type = "number"
	TypeObject     Type = "object"
	TypeReference  Type = "reference"
	TypeString     Type = "string"
)

type UniqueNonEmptyStringList

type UniqueNonEmptyStringList = []NonEmptyString

@min_items 1 @unique_items

type Untyped

type Untyped struct {
	Metadata
	Types []string `json:"type,omitempty"`
}

func (*Untyped) AssignValue

func (u *Untyped) AssignValue(_ map[string]string, valueName, resultName string) string

func (*Untyped) CompareValues

func (u *Untyped) CompareValues(v1, v2 interface{}) int

func (*Untyped) Copy

func (u *Untyped) Copy() Schema

func (*Untyped) DefaultValue

func (u *Untyped) DefaultValue() interface{}

func (*Untyped) GoString

func (u *Untyped) GoString(imports map[string]string) string

func (*Untyped) GoType

func (u *Untyped) GoType(_ map[string]string) string

func (*Untyped) StringValue

func (u *Untyped) StringValue(value interface{}) string

func (*Untyped) Type

func (u *Untyped) Type() Type

func (*Untyped) TypeString

func (u *Untyped) TypeString() string

func (*Untyped) ValidateSchema

func (u *Untyped) ValidateSchema(s Schema, compare bool) error

func (*Untyped) ValidateValue

func (u *Untyped) ValidateValue(v interface{}) (interface{}, error)

type ValidationError

type ValidationError struct {
	Errors []error `json:"errors"`
}

func (*ValidationError) AddError

func (v *ValidationError) AddError(field string, err error)

func (*ValidationError) AddErrorf

func (v *ValidationError) AddErrorf(field, format string, a ...interface{})

func (ValidationError) ErrOrNil

func (v ValidationError) ErrOrNil() error

func (ValidationError) Error

func (v ValidationError) Error() string

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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