Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AdditionalItems ¶
type AdditionalItems = rawAdditional
AdditionalItems is JSON Schema additionalItems validator description.
type AdditionalProperties ¶
type AdditionalProperties = rawAdditional
AdditionalProperties is JSON Schema additionalProperties validator description.
type Dependencies ¶
Dependencies is unparsed JSON Schema dependencies validator description.
func (Dependencies) MarshalJSON ¶
func (r Dependencies) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (*Dependencies) UnmarshalJSON ¶
func (r *Dependencies) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
type Items ¶
type Items struct {
Array bool // If set, "items" defined as array.
Schema RawSchema
Schemas []RawSchema
}
Items is JSON Schema items validator description.
func (Items) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Items) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type NoRemote ¶
type NoRemote struct {
}
NoRemote is no-op implementation of RemoteResolver. Always returns error.
type Num ¶
Num represents JSON number.
func (Num) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Num) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type RawPatternProperties ¶
type RawPatternProperties []RawPatternProperty
RawPatternProperties is unparsed JSON Schema patternProperties validator description.
func (RawPatternProperties) MarshalJSON ¶
func (r RawPatternProperties) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (*RawPatternProperties) UnmarshalJSON ¶
func (r *RawPatternProperties) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
type RawPatternProperty ¶
RawPatternProperty is item of RawPatternProperties.
type RawProperties ¶
type RawProperties []RawProperty
RawProperties is unparsed JSON Schema properties validator description.
func (RawProperties) MarshalJSON ¶
func (p RawProperties) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (*RawProperties) UnmarshalJSON ¶
func (p *RawProperties) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
type RawProperty ¶
RawProperty is item of RawProperties.
type RawSchema ¶
type RawSchema struct {
ID string `json:"id,omitempty"` // TODO(tdakkota): get id field name from draft struct
Ref string `json:"$ref,omitempty"`
Type SchemaType `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Enum []json.RawMessage `json:"enum,omitempty"`
AllOf []RawSchema `json:"allOf,omitempty"`
AnyOf []RawSchema `json:"anyOf,omitempty"`
OneOf []RawSchema `json:"oneOf,omitempty"`
Not *RawSchema `json:"not,omitempty"`
MinProperties *uint64 `json:"minProperties,omitempty"`
MaxProperties *uint64 `json:"maxProperties,omitempty"`
Required []string `json:"required,omitempty"`
Properties RawProperties `json:"properties,omitempty"`
PatternProperties RawPatternProperties `json:"patternProperties,omitempty"`
AdditionalProperties *AdditionalProperties `json:"additionalProperties,omitempty"`
Dependencies Dependencies `json:"dependencies,omitempty"`
MinItems *uint64 `json:"minItems,omitempty"`
MaxItems *uint64 `json:"maxItems,omitempty"`
UniqueItems bool `json:"uniqueItems,omitempty"`
Items *Items `json:"items,omitempty"`
AdditionalItems *AdditionalItems `json:"additionalItems,omitempty"`
Minimum Num `json:"minimum,omitempty"`
ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"`
Maximum Num `json:"maximum,omitempty"`
ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"`
MultipleOf Num `json:"multipleOf,omitempty"`
MaxLength *uint64 `json:"maxLength,omitempty"`
MinLength *uint64 `json:"minLength,omitempty"`
Pattern string `json:"pattern,omitempty"`
}
RawSchema is unparsed JSON Schema.
type RemoteResolver ¶
RemoteResolver resolves remote references.
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema is a parsed schema structure.
func Parse ¶
Parse parses given JSON and compiles JSON Schema validator.
Example ¶
package main
import (
"fmt"
"github.com/tdakkota/jsonschema"
)
func main() {
schema, err := jsonschema.Parse([]byte(`{
"type": "object",
"properties": {
"number": { "type": "number" },
"street_name": { "type": "string" },
"street_type": { "enum": ["Street", "Avenue", "Boulevard"] }
}
}`))
if err != nil {
panic(err)
}
if err := schema.Validate(
[]byte(`{ "number": 1600, "street_name": "Pennsylvania", "street_type": "Avenue" }`),
); err != nil {
panic(err)
}
fmt.Println(schema.Validate([]byte(`{"number": "1600"}`)))
}
Output: object: "number": string: type is not allowed
type SchemaType ¶
type SchemaType []string
SchemaType represents JSON Schema type list.
func (*SchemaType) UnmarshalJSON ¶
func (r *SchemaType) UnmarshalJSON(data []byte) error