Documentation ¶
Index ¶
- Constants
- func Index(token string, maxLengths ...int) (int, bool)
- func SetElement(object any, element Element, path list.List, value any) error
- func UseFormat(name string, fn format.Generator)
- type Any
- func (element Any) Clean(value any) error
- func (element Any) DefaultValue() any
- func (element Any) GetElement(name string) (Element, bool)
- func (element Any) Inherit(parent Element)
- func (element Any) IsRequired() bool
- func (element Any) MarshalMap() map[string]any
- func (element *Any) UnmarshalMap(data map[string]any) error
- func (element Any) Validate(value any) error
- type Array
- func (element Array) Clean(value any) error
- func (element Array) DefaultValue() any
- func (element Array) GetElement(name string) (Element, bool)
- func (element Array) GetProperty(name string) (Element, error)
- func (element Array) Inherit(parent Element)
- func (element Array) IsRequired() bool
- func (element Array) MarshalMap() map[string]any
- func (element *Array) UnmarshalMap(data map[string]any) error
- func (element Array) Validate(object any) error
- type BoolGetter
- type BoolSetter
- type Boolean
- func (element Boolean) Clean(value any) error
- func (element Boolean) DefaultValue() any
- func (element Boolean) GetElement(name string) (Element, bool)
- func (element Boolean) Inherit(parent Element)
- func (element Boolean) IsRequired() bool
- func (element Boolean) MarshalJSON() ([]byte, error)
- func (element Boolean) MarshalMap() map[string]any
- func (element *Boolean) UnmarshalMap(data map[string]any) error
- func (element Boolean) Validate(object any) error
- type Element
- type ElementMap
- type Enumerator
- type FloatGetter
- type FloatSetter
- type Int64Getter
- type Int64Setter
- type IntGetter
- type IntSetter
- type Integer
- func (element Integer) Clean(value any) error
- func (element Integer) DefaultValue() any
- func (element Integer) Enumerate() []string
- func (element Integer) GetElement(name string) (Element, bool)
- func (element Integer) Inherit(parent Element)
- func (element Integer) IsRequired() bool
- func (element Integer) MarshalMap() map[string]any
- func (element *Integer) UnmarshalMap(data map[string]any) error
- func (element Integer) Validate(value any) error
- type LengthGetter
- type Nullable
- type Number
- func (element Number) Clean(value any) error
- func (element Number) DefaultValue() any
- func (element Number) Enumerate() []string
- func (element Number) GetElement(name string) (Element, bool)
- func (element Number) Inherit(parent Element)
- func (element Number) IsRequired() bool
- func (element Number) MarshalMap() map[string]any
- func (element *Number) UnmarshalMap(data map[string]any) error
- func (element Number) Validate(value any) error
- type Object
- func (element Object) Clean(value any) error
- func (element Object) DefaultValue() any
- func (element Object) GetElement(name string) (Element, bool)
- func (element Object) Inherit(parent Element)
- func (element Object) IsRequired() bool
- func (element Object) MarshalMap() map[string]any
- func (element *Object) UnmarshalMap(data map[string]any) error
- func (element Object) Validate(object any) error
- type ObjectGetter
- type ObjectSetter
- type Remover
- type Schema
- func (schema Schema) Clean(value any) error
- func (schema Schema) Get(object any, path string) (any, error)
- func (schema Schema) GetElement(path string) (Element, bool)
- func (schema *Schema) Inherit(parent Schema)
- func (schema Schema) MarshalJSON() ([]byte, error)
- func (schema Schema) MarshalMap() map[string]any
- func (schema Schema) Remove(object any, path string) bool
- func (schema Schema) Set(object any, path string, value any) error
- func (schema Schema) SetAll(object any, values map[string]any) error
- func (schema *Schema) UnmarshalJSON(data []byte) error
- func (schema *Schema) UnmarshalMap(data map[string]any) error
- func (schema Schema) Validate(value any) error
- type String
- func (element String) Clean(value any) error
- func (element String) DefaultValue() any
- func (element String) Enumerate() []string
- func (element String) GetElement(name string) (Element, bool)
- func (element String) Inherit(parent Element)
- func (element String) IsRequired() bool
- func (element String) MarshalMap() map[string]any
- func (element *String) UnmarshalMap(data map[string]any) error
- func (element String) Validate(value any) error
- type StringGetter
- type StringSetter
- type Type
- type ValueSetter
- type WritableElement
Constants ¶
const TypeAny = Type("any")
TypeAny is the token used by JSON-Schema to designate that any kind of data
const TypeArray = Type("array")
TypeArray is the token used by JSON-Schema to designate that a schema describes an array.
const TypeBoolean = Type("boolean")
TypeBoolean is the token used by JSON-Schema to designate that a schema describes an boolean.
const TypeInteger = Type("integer")
TypeInteger is the token used by JSON-Schema to designate that a schema describes an integer.
const TypeNumber = Type("number")
TypeNumber is the token used by JSON-Schema to designate that a schema describes an number.
const TypeObject = Type("object")
TypeObject is the token used by JSON-Schema to designate that a schema describes an object.
const TypeString = Type("string")
TypeString is the token used by JSON-Schema to designate that a schema describes an string.
Variables ¶
This section is empty.
Functions ¶
func Index ¶ added in v0.10.0
Index converts a string into an array index that is bounded by zero and the maximum value provided. It returns the final index and a boolean that is TRUE if the index was converted successfully, and FALSE if it was truncated.
func SetElement ¶ added in v0.10.0
Types ¶
type Any ¶
type Any struct {
Required bool
}
func (Any) Clean ¶ added in v0.10.0
Clean updates a value to match the schema. The value must be a pointer.
func (Any) DefaultValue ¶ added in v0.10.0
Default returns the default value for this element
func (Any) IsRequired ¶
IsRequired returns true if this a value is required for this element
func (Any) MarshalMap ¶
MarshalMap populates the object data into a map[string]any
func (*Any) UnmarshalMap ¶
UnmarshalMap tries to populate this object using data from a map[string]any
type Array ¶
Array represents an array data type within a JSON-Schema.
func (Array) DefaultValue ¶ added in v0.6.0
func (Array) GetElement ¶ added in v0.6.0
func (Array) GetProperty ¶ added in v0.10.0
func (Array) IsRequired ¶
IsRequired returns TRUE if this element is a required field
func (Array) MarshalMap ¶
MarshalMap populates object data into a map[string]any
func (*Array) UnmarshalMap ¶
UnmarshalMap tries to populate this object using data from a map[string]any
type BoolGetter ¶ added in v0.7.0
type BoolSetter ¶ added in v0.7.0
type Boolean ¶
Boolean represents a boolean data type within a JSON-Schema.
func (Boolean) DefaultValue ¶ added in v0.6.0
func (Boolean) GetElement ¶ added in v0.6.0
func (Boolean) IsRequired ¶
IsRequired returns TRUE if this element is a required field
func (Boolean) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface
func (Boolean) MarshalMap ¶
MarshalMap populates object data into a map[string]any
func (*Boolean) UnmarshalMap ¶
UnmarshalMap tries to populate this object using data from a map[string]any
type Element ¶
type Element interface { // Default returns the default value for this element DefaultValue() any // IsRequired returns true if this a value is required for this element IsRequired() bool // Validate validates the provided value Validate(value any) error // Clean updates a value to match the schema. The value must be a pointer. Clean(value any) error // MarshalMap populates the object data into a map[string]any MarshalMap() map[string]any // getElement returns a named sub-element of this element, if it exists. GetElement(string) (Element, bool) Inherit(Element) }
Element interface wraps all of the methods required for schema elements.
func UnmarshalJSON ¶
UnmarshalJSON tries to parse a []byte into a schema.Element
func UnmarshalMap ¶
UnmarshalMap tries to parse a map[string]any into a schema.Element
type ElementMap ¶
type Enumerator ¶
type Enumerator interface {
Enumerate() []string
}
type FloatGetter ¶ added in v0.7.0
type FloatSetter ¶ added in v0.7.0
type Int64Getter ¶ added in v0.7.0
type Int64Setter ¶ added in v0.7.0
type Integer ¶
type Integer struct { Default null.Int64 `json:"default"` Minimum null.Int64 `json:"minimum"` Maximum null.Int64 `json:"maximum"` MultipleOf null.Int64 `json:"multipleOf"` BitSize int `json:"bitSize"` Enum []int `json:"emum"` Required bool }
Integer represents an integer data type within a JSON-Schema.
func (Integer) DefaultValue ¶ added in v0.6.0
DefaultValue returns the default value for this element type
func (Integer) GetElement ¶ added in v0.6.0
func (Integer) IsRequired ¶
IsRequired returns TRUE if this element is a required field
func (Integer) MarshalMap ¶
MarshalMap populates object data into a map[string]any
func (*Integer) UnmarshalMap ¶
UnmarshalMap tries to populate this object using data from a map[string]any
type LengthGetter ¶ added in v0.10.0
type LengthGetter interface {
Length() int
}
LengthGetter allows arrays to report their total length
type Nullable ¶
type Nullable interface {
IsNull() bool
}
Nullable interface wraps the IsNull method, that helps an object to identify if it contains a null value or not. This mirrors the null.Nullable interface here, for convenience.
type Number ¶
type Number struct { Default null.Float `json:"default"` Minimum null.Float `json:"minimum"` Maximum null.Float `json:"maximum"` MultipleOf null.Float `json:"multipleOf"` BitSize int `json:"bitSize"` Enum []float64 `json:"enum"` Required bool }
Number represents a number data type within a JSON-Schema.
func (Number) DefaultValue ¶ added in v0.6.0
DefaultValue returns the default value for this element type
func (Number) GetElement ¶ added in v0.6.0
func (Number) IsRequired ¶
IsRequired returns TRUE if this element is a required field
func (Number) MarshalMap ¶
MarshalMap populates object data into a map[string]any
func (*Number) UnmarshalMap ¶
UnmarshalMap tries to populate this object using data from a map[string]any
type Object ¶
type Object struct { Properties ElementMap Wildcard Element RequiredProps []string Required bool }
Object represents an object data type within a JSON-Schema.
func (Object) DefaultValue ¶ added in v0.6.0
DefaultValue returns the default value for this element type. In a special case for objects, which can be represented as both Go structs and maps, this returns a map[string]any that has been populated with any known default keys.
func (Object) GetElement ¶ added in v0.6.0
func (Object) IsRequired ¶
IsRequired returns TRUE if this element is a required field
func (Object) MarshalMap ¶
MarshalMap populates object data into a map[string]any
func (*Object) UnmarshalMap ¶
UnmarshalMap tries to populate this object using data from a map[string]any
type ObjectGetter ¶ added in v0.10.0
type ObjectSetter ¶ added in v0.10.0
type Remover ¶ added in v0.10.0
*****************************************
- Remover Interface *****************************************
type Schema ¶
Schema defines a (simplified) JSON-Schema object, that can be Marshalled/Unmarshalled to JSON.
func (Schema) Clean ¶ added in v0.7.0
Clean tries to force a particular value to fit this schema by updating it (or all of its properties) to match. If values cannot be coerced to fit the schema, then an error is returned
func (Schema) Get ¶
Get retrieves a generic value from the object. If the object is nil, Get still tries to return a default value if provided by the schema
func (Schema) GetElement ¶ added in v0.6.0
func (Schema) MarshalJSON ¶
MarshalJSON converts a schema into JSON.
func (Schema) MarshalMap ¶
MarshalMap converts a schema into a map[string]any
func (Schema) SetAll ¶
SetAll iterates over Set to apply all of the values to the object one at a time, stopping at the first error it encounters. If all values are addedd successfully, then SetAll also uses Validate() to confirm that the object is still correct.
func (*Schema) UnmarshalJSON ¶
UnmarshalJSON creates a new Schema object using a JSON-serialized byte array.
func (*Schema) UnmarshalMap ¶
UnmarshalMap updates a Schema using a map[string]any
type String ¶
type String struct { Default string MinLength int MaxLength int Enum []string Pattern string Format string Required bool }
String represents a string data type within a JSON-Schema.
func (String) DefaultValue ¶ added in v0.6.0
DefaultValue returns the default value for this element type
func (String) GetElement ¶ added in v0.6.0
func (String) IsRequired ¶
IsRequired returns TRUE if this element is a required field
func (String) MarshalMap ¶
MarshalMap populates object data into a map[string]any
func (*String) UnmarshalMap ¶
UnmarshalMap tries to populate this object using data from a map[string]any