Documentation ¶
Index ¶
- func NewStringPtr(b []byte) *string
- func Validate(jsonDoc []byte) (bool, error)
- type Dependencies
- type Dependency
- type Enum
- type Items
- type NamedProperty
- type NamedValue
- type Properties
- type Ref
- type Schema
- func (s *Schema) AddSchema(schema *Schema) error
- func (s *Schema) AddSchemaString(schemaString string) error
- func (s *Schema) DeRef() error
- func (s *Schema) ExpandURI(uri string) (*url.URL, error)
- func (s Schema) GetID() string
- func (s *Schema) GetUnknown(name string) (*Value, error)
- func (s Schema) IsDraft4() bool
- func (s Schema) IsDraft6() bool
- func (s Schema) IsDraft7() bool
- func (s Schema) IsEmpty() bool
- func (s Schema) MarshalJSON() ([]byte, error)
- func (s *Schema) Parse(jsonSchema []byte) (*Schema, error)
- func (s Schema) Pretty() string
- func (s *Schema) ResolveRef(ref *Ref) (*Schema, error)
- func (s *Schema) SetCircularRefThresHold(threshold int)
- func (s *Schema) SetID(id string)
- func (s *Schema) SetUnknown(name string, val *Value) error
- func (s Schema) String() string
- func (s *Schema) UnmarshalJSON(schema []byte) error
- func (s *Schema) Validate(jsonDoc []byte) (bool, error)
- type SchemaProp
- type Schemas
- type Strings
- type Type
- type Value
- type ValueType
- type Values
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewStringPtr ¶
Types ¶
type Dependencies ¶
type Dependencies map[string]*Dependency
func NewDependencies ¶
func NewDependencies(jsonVal []byte, vt jsonparser.ValueType, parentSchema *Schema) (*Dependencies, error)
func (Dependencies) MarshalJSON ¶
func (d Dependencies) MarshalJSON() ([]byte, error)
type Dependency ¶
func NewDependency ¶
func NewDependency(jsonVal []byte, vt jsonparser.ValueType, parentSchema *Schema) (*Dependency, error)
func (Dependency) MarshalJSON ¶
func (i Dependency) MarshalJSON() ([]byte, error)
type NamedProperty ¶
Properties are build like this, instead of map[string]*Schema, to make it possible to Marshal with original sort order of fields
type NamedValue ¶ added in v0.1.2
type Properties ¶
type Properties []*NamedProperty
func NewProperties ¶
func NewProperties(jsonVal []byte, vt jsonparser.ValueType, parentSchema *Schema) (*Properties, error)
func (Properties) GetProperty ¶
func (p Properties) GetProperty(name string) (*NamedProperty, bool)
func (Properties) MarshalJSON ¶
func (p Properties) MarshalJSON() ([]byte, error)
type Ref ¶
type Ref struct { String *string Schema *Schema `json:"-"` // contains filtered or unexported fields }
func (Ref) MarshalJSON ¶
type Schema ¶
type Schema struct { Schema *string `json:"$schema,omitempty"` ID *string `json:"$id,omitempty"` // NOTE: draft-04 has id instead if $id IDDraft04 *string `json:"id,omitempty"` // NOTE: draft-04 has id instead if $id Ref *Ref `json:"$ref,omitempty"` Comment *string `json:"$comment,omitempty"` Title *string `json:"title,omitempty"` Description *string `json:"description,omitempty"` Type *Type `json:"type,omitempty"` // Must have at least 1 value Enum *Enum `json:"enum,omitempty"` Default *Value `json:"default,omitempty"` Examples *Values `json:"examples,omitempty"` // Draft 6 // Only allow 1 value Const *Value `json:"const,omitempty"` // Draft 7 ReadOnly *bool `json:"readOnly,omitempty"` WriteOnly *bool `json:"writeOnly,omitempty"` Definitions *Properties `json:"definitions,omitempty"` // If schemas should look something like (const being the important part): // { "if": { "properties": { "propertyX": { "const": "ValueX" } }, "required": ["propertyX"] } } If *Schema `json:"if,omitempty"` // One (or both?) of these can be omitted. // Both then and else will be ignore, if If is not defined. // If any of them are omitted, the value true is used in their place. // NOTE: It's not entirely obvious in the documentation, if both can be omitted: // https://json-schema.org/understanding-json-schema/reference/conditionals.html#if-then-else Then *Schema `json:"then,omitempty"` Else *Schema `json:"else,omitempty"` AllOf *Schemas `json:"allOf,omitempty"` AnyOf *Schemas `json:"anyOf,omitempty"` OneOf *Schemas `json:"oneOf,omitempty"` Not *Schema `json:"not,omitempty"` ContentEncoding *string `json:"contentEncoding,omitempty"` // e.g. base64 ContentMediaType *string `json:"contentMediaType,omitempty"` // e.g. image/png Properties *Properties `json:"properties,omitempty"` // Draft 4 requires at least 1 string Required *Strings `json:"required,omitempty"` MaxProperties *int64 `json:"maxProperties,omitempty"` MinProperties *int64 `json:"minProperties,omitempty"` // Dependencies is either: // - if propertyX is set, then propertyY and propertyZ is required // e.g.: { "propertyX": ["propertyY", "propertyZ"] } // - if propertyX is set, then schemaX is also required to match // e.g.: { "propertyX": { "properties": { "propertyY": { "type": "string" } }, "required": ["propertyY"] } } Dependencies *Dependencies `json:"dependencies,omitempty"` // patternProperties is used to match property names against a regex and for each a schema. // It's basically a map of schemas, but with regex instead of property names. PatternProperties *Properties `json:"patternProperties,omitempty"` // additionalProperties is a schema that will be used to validate any properties // in the instance that are not matched by properties or patternProperties. // Setting it to false means no additional properties will be allowed. AdditionalProperties *Schema `json:"additionalProperties,omitempty"` // // Draft 6 // Useful for enforcing a certain property name format // Property names implies { "type": "string" } // "propertyNames": { "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"} PropertyNames *Schema `json:"propertyNames,omitempty"` // When items is an array of multiples Schemas, each refers to their own index. Items *Items `json:"items,omitempty"` // TODO: Can actually also be boolean MaxItems *int64 `json:"maxItems,omitempty"` MinItems *int64 `json:"minItems,omitempty"` UniqueItems *bool `json:"uniqueItems,omitempty"` // Should only be evaluated when items is multiple schemas. // Any values that does not have an explicit schmea (multi schema), // will validate according to this schema. // Setting it to false, means that no other values are allowed. AdditionalItems *Schema `json:"additionalItems,omitempty"` // contains only need to match 1 item in the documents array Contains *Schema `json:"contains,omitempty"` MaxLength *int64 `json:"maxLength,omitempty"` MinLength *int64 `json:"minLength,omitempty"` Format *string `json:"format,omitempty"` Pattern *string `json:"pattern,omitempty"` // The type (int/float) should of course match the type of the property MultipleOf *json.Number `json:"multipleOf,omitempty"` // Draft 4: x ≥ minimum unless exclusiveMinimum == true, x ≤ maximum unless exclusiveMaximum == true // Draft 6: x ≥ minimum, x > exclusiveMinimum, x ≤ maximum, x < exclusiveMaximum Maximum *Value `json:"maximum,omitempty"` ExclusiveMaximum *Value `json:"exclusiveMaximum,omitempty"` // bool in draft 4 Minimum *Value `json:"minimum,omitempty"` ExclusiveMinimum *Value `json:"exclusiveMinimum,omitempty"` // bool in draft 4 // contains filtered or unexported fields }
func NewFromString ¶
func (*Schema) AddSchemaString ¶
func (*Schema) GetUnknown ¶ added in v0.1.1
func (Schema) IsEmpty ¶
Checks if everything is nil and thereby an empty schema, similar to a "true" schema TODO: Update with 20xx-xx props
func (Schema) MarshalJSON ¶
func (*Schema) SetCircularRefThresHold ¶
func (*Schema) SetUnknown ¶ added in v0.1.1
func (*Schema) UnmarshalJSON ¶
type SchemaProp ¶
type SchemaProp uint8
const ( PropSchema SchemaProp = iota PropID PropIDDraft04 PropRef PropComment PropTitle PropDescription PropType PropEnum PropDefault PropConst PropExamples PropReadOnly PropWriteOnly PropDefinitions PropIf PropThen PropElse PropAllOf PropAnyOf PropOneOf PropNot PropContentEncoding PropContentMediaType PropProperties PropRequired PropMaxProperties PropMinProperties PropDependencies PropPatternProperties PropAdditionalProperties PropPropertyNames PropItems PropMaxItems PropMinItems PropUniqueItems PropAdditionalItems PropContains PropMaxLength PropMinLength PropFormat PropPattern PropMultipleOf PropMaximum PropExclusiveMaximum PropMinimum PropExclusiveMinimum )
TODO: Update with 20xx-xx props
type Strings ¶
type Strings []*string
func NewStrings ¶
func NewStrings(jsonVal []byte, vt jsonparser.ValueType) (*Strings, error)
func (Strings) MarshalJSON ¶
type Type ¶
func (Type) MarshalJSON ¶
type Value ¶
type Value struct { String *string Number *big.Float Boolean *bool Null *bool Object *map[string]*Value Array *[]*Value // contains filtered or unexported fields }
func (Value) MarshalJSON ¶
type ValueType ¶
type ValueType uint8
These are the same as jsonparser.ValueType - except Integer, which jsonparser does not have
func DetectJSONType ¶
This should more or less match what jsonparser detects. Unfortunately jsonparser doesn't expose it's detect type function.
func (ValueType) ParserValueType ¶
func (v ValueType) ParserValueType() jsonparser.ValueType
Source Files ¶
Click to show internal directories.
Click to hide internal directories.