Documentation ¶
Index ¶
- type Definitions
- type Schema
- func (s *Schema) CoerceValue(value interface{}) interface{}
- func (s *Schema) ConvertValue(val string) (interface{}, error)
- func (s *Schema) GetType() (string, bool, error)
- func (s *Schema) GetTypes() ([]string, bool, error)
- func (s *Schema) UnmarshalJSON(data []byte) error
- func (s *Schema) Validate(data interface{}) ([]ValidationError, error)
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Definitions ¶
type Schema ¶
type Schema struct { Comment string `json:"$comment,omitempty" mapstructure:"$comment,omitempty"` ID string `json:"$id,omitempty" mapstructure:"$ref,omitempty"` Ref string `json:"$ref,omitempty" mapstructure:"$ref,omitempty"` AdditionalItems interface{} `json:"additionalItems,omitempty" mapstructure:"additionalProperties,omitempty"` AdditionalProperties interface{} `json:"additionalProperties,omitempty" mapstructure:"additionalProperties,omitempty"` AllOf []*Schema `json:"allOf,omitempty" mapstructure:"allOf,omitempty"` Const interface{} `json:"const,omitempty" mapstructure:"const,omitempty"` Contains *Schema `json:"contains,omitempty" mapstructure:"contains,omitempty"` ContentEncoding string `json:"contentEncoding,omitempty" mapstructure:"contentEncoding,omitempty"` ContentMediaType string `json:"contentMediaType,omitempty" mapstructure:"contentMediaType,omitempty"` Default interface{} `json:"default,omitempty" mapstructure:"default,omitempty"` Definitions Definitions `json:"definitions,omitempty" mapstructure:"definitions,omitempty"` Dependencies map[string]interface{} `json:"dependencies,omitempty" mapstructure:"dependencies,omitempty"` Description string `json:"description,omitempty" mapstructure:"description,omitempty"` Else *Schema `json:"else,omitempty" mapstructure:"else,omitempty"` Enum []interface{} `json:"enum,omitempty" mapstructure:"enum,omitempty"` Examples []interface{} `json:"examples,omitempty" mapstructure:"examples,omitempty"` ExclusiveMaximum *float64 `json:"exclusiveMaximum,omitempty" mapstructure:"exclusiveMaximum,omitempty"` ExclusiveMinimum *float64 `json:"exclusiveMinimum,omitempty" mapstructure:"exclusiveMinimum,omitempty"` Format string `json:"format,omitempty" mapstructure:"format,omitempty"` If *Schema `json:"if,omitempty" mapstructure:"if,omitempty"` //Items can be a Schema or an Array of Schema :( Items interface{} `json:"items,omitempty" mapstructure:"items,omitempty"` Maximum *float64 `json:"maximum,omitempty" mapstructure:"maximum,omitempty"` MaxLength *float64 `json:"maxLength,omitempty" mapstructure:"maxLength,omitempty"` MinItems *float64 `json:"minItems,omitempty" mapstructure:"minItems,omitempty"` MinLength *float64 `json:"minLength,omitempty" mapstructure:"minLength,omitempty"` MinProperties *float64 `json:"minProperties,omitempty" mapstructure:"minProperties,omitempty"` Minimum *float64 `json:"minimum,omitempty" mapstructure:"minimum,omitempty"` MultipleOf *float64 `json:"multipleOf,omitempty" mapstructure:"multipleOf,omitempty"` Not *Schema `json:"not,omitempty" mapstructure:"not,omitempty"` OneOf *Schema `json:"oneOf,omitempty" mapstructure:"oneOf,omitempty"` PatternProperties map[string]*Schema `json:"patternProperties,omitempty" mapstructure:"patternProperties,omitempty"` Properties map[string]*Schema `json:"properties,omitempty" mapstructure:"properties,omitempty"` PropertyNames *Schema `json:"propertyNames,omitempty" mapstructure:"propertyNames,omitempty"` ReadOnly *bool `json:"readOnly,omitempty" mapstructure:"readOnly,omitempty"` Required []string `json:"required,omitempty" mapstructure:"required,omitempty"` Then *Schema `json:"then,omitempty" mapstructure:"then,omitempty"` Title string `json:"title,omitempty" mapstructure:"title,omitempty"` Type interface{} `json:"type,omitempty" mapstructure:"type,omitempty"` UniqueItems *bool `json:"uniqueItems,omitempty" mapstructure:"uniqueItems,omitempty"` WriteOnly *bool `json:"writeOnly,omitempty" mapstructure:"writeOnly,omitempty"` }
Schema represents a JSON Schema compatible CNAB Definition
func (*Schema) CoerceValue ¶
func (s *Schema) CoerceValue(value interface{}) interface{}
CoerceValue can be used to turn float and other numeric types into integers. When unmarshaled, often integer values are not represented as an integer. This is a convenience method.
func (*Schema) ConvertValue ¶
ConvertValue attempts to convert the given string value to the type from the definition. Note: this is only applicable to string, number, integer and boolean types
func (*Schema) GetType ¶
GetType will return the singular type for a given schema and a success boolean. If the schema does not have a single type, it will return the false boolean and an error.
func (*Schema) GetTypes ¶
GetTypes will return the types (as a slice) for a given schema and a success boolean. If the schema has a single type, it will return the false boolean and an error.
func (*Schema) UnmarshalJSON ¶
UnmarshalJSON provides an implementation of a JSON unmarshaler that uses the github.com/qri-io/jsonschema to load and validate a given schema. If it is valid, then the json is unmarshaled.
func (*Schema) Validate ¶
func (s *Schema) Validate(data interface{}) ([]ValidationError, error)
Validate applies JSON Schema validation to the data passed as a parameter. If validation errors occur, they will be returned in as a slice of ValidationError structs. If any other error occurs, it will be returned as a separate error
type ValidationError ¶
ValidationError error represents a validation error against the JSON Schema. The type includes the path in the given object and the error message