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 {
Schema string `json:"$schema,omitempty" yaml:"$schema,omitempty"`
Comment string `json:"$comment,omitempty" yaml:"$comment,omitempty"`
ID string `json:"$id,omitempty" yaml:"$id,omitempty"`
Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
AdditionalItems interface{} `json:"additionalItems,omitempty" yaml:"additionalItems,omitempty"`
AdditionalProperties interface{} `json:"additionalProperties,omitempty" yaml:"additionalProperties,omitempty"`
AllOf []*Schema `json:"allOf,omitempty" yaml:"allOf,omitempty"`
Const interface{} `json:"const,omitempty" yaml:"const,omitempty"`
Contains *Schema `json:"contains,omitempty" yaml:"contains,omitempty"`
ContentEncoding string `json:"contentEncoding,omitempty" yaml:"contentEncoding,omitempty"`
ContentMediaType string `json:"contentMediaType,omitempty" yaml:"contentMediaType,omitempty"`
Default interface{} `json:"default,omitempty" yaml:"default,omitempty"`
Definitions Definitions `json:"definitions,omitempty" yaml:"definitions,omitempty"`
Dependencies map[string]interface{} `json:"dependencies,omitempty" yaml:"dependencies,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Else *Schema `json:"else,omitempty" yaml:"else,omitempty"`
Enum []interface{} `json:"enum,omitempty" yaml:"enum,omitempty"`
Examples []interface{} `json:"examples,omitempty" yaml:"examples,omitempty"`
ExclusiveMaximum *float64 `json:"exclusiveMaximum,omitempty" yaml:"exclusiveMaximum,omitempty"`
ExclusiveMinimum *float64 `json:"exclusiveMinimum,omitempty" yaml:"exclusiveMinimum,omitempty"`
Format string `json:"format,omitempty" yaml:"format,omitempty"`
If *Schema `json:"if,omitempty" yaml:"if,omitempty"`
//Items can be a Schema or an Array of Schema :(
Items interface{} `json:"items,omitempty" yaml:"items,omitempty"`
Maximum *float64 `json:"maximum,omitempty" yaml:"maximum,omitempty"`
MaxLength *float64 `json:"maxLength,omitempty" yaml:"maxLength,omitempty"`
MinItems *float64 `json:"minItems,omitempty" yaml:"minItems,omitempty"`
MinLength *float64 `json:"minLength,omitempty" yaml:"minLength,omitempty"`
MinProperties *float64 `json:"minProperties,omitempty" yaml:"minProperties,omitempty"`
Minimum *float64 `json:"minimum,omitempty" yaml:"minimum,omitempty"`
MultipleOf *float64 `json:"multipleOf,omitempty" yaml:"multipleOf,omitempty"`
Not *Schema `json:"not,omitempty" yaml:"not,omitempty"`
OneOf *Schema `json:"oneOf,omitempty" yaml:"oneOf,omitempty"`
PatternProperties map[string]*Schema `json:"patternProperties,omitempty" yaml:"patternProperties,omitempty"`
Properties map[string]*Schema `json:"properties,omitempty" yaml:"properties,omitempty"`
PropertyNames *Schema `json:"propertyNames,omitempty" yaml:"propertyNames,omitempty"`
ReadOnly *bool `json:"readOnly,omitempty" yaml:"readOnly,omitempty"`
Required []string `json:"required,omitempty" yaml:"required,omitempty"`
Then *Schema `json:"then,omitempty" yaml:"then,omitempty"`
Title string `json:"title,omitempty" yaml:"title,omitempty"`
Type interface{} `json:"type,omitempty" yaml:"type,omitempty"`
UniqueItems *bool `json:"uniqueItems,omitempty" yaml:"uniqueItems,omitempty"`
WriteOnly *bool `json:"writeOnly,omitempty" yaml:"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