Documentation ¶
Overview ¶
Package jsonschema supports the reading, writing, and manipulation of JSON Schemas.
Index ¶
- func Render(node *yaml.Node) string
- type NamedSchema
- type NamedSchemaOrStringArray
- type Schema
- func (s *Schema) AddProperty(name string, property *Schema)
- func (schema *Schema) CopyOfficialSchemaProperties(names []string)
- func (schema *Schema) CopyOfficialSchemaProperty(name string)
- func (schema *Schema) CopyProperties(source *Schema)
- func (s *Schema) DefinitionWithName(name string) *Schema
- func (schema *Schema) IsEmpty() bool
- func (schema *Schema) IsEqual(schema2 *Schema) bool
- func (schema *Schema) JSONString() string
- func (s *Schema) PatternPropertyWithName(name string) *Schema
- func (s *Schema) PropertyWithName(name string) *Schema
- func (schema *Schema) ResolveAllOfs()
- func (schema *Schema) ResolveAnyOfs()
- func (schema *Schema) ResolveRefs()
- func (schema *Schema) String() string
- func (schema *Schema) TypeIs(typeName string) bool
- type SchemaEnumValue
- type SchemaNumber
- type SchemaOperation
- type SchemaOrBoolean
- type SchemaOrSchemaArray
- type SchemaOrStringArray
- type StringOrStringArray
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type NamedSchema ¶
NamedSchema is a name-value pair that is used to emulate maps with ordered keys.
func NewNamedSchema ¶
func NewNamedSchema(name string, value *Schema) *NamedSchema
NewNamedSchema creates and returns a new object
type NamedSchemaOrStringArray ¶
type NamedSchemaOrStringArray struct { Name string Value *SchemaOrStringArray }
NamedSchemaOrStringArray is a name-value pair that is used to emulate maps with ordered keys.
type Schema ¶
type Schema struct { Schema *string // $schema ID *string // id keyword used for $ref resolution scope Ref *string // $ref, i.e. JSON Pointers ReadOnly *bool WriteOnly *bool // http://json-schema.org/latest/json-schema-validation.html // 5.1. Validation keywords for numeric instances (number and integer) MultipleOf *SchemaNumber Maximum *SchemaNumber ExclusiveMaximum *bool Minimum *SchemaNumber ExclusiveMinimum *bool // 5.2. Validation keywords for strings MaxLength *int64 MinLength *int64 Pattern *string // 5.3. Validation keywords for arrays AdditionalItems *SchemaOrBoolean Items *SchemaOrSchemaArray MaxItems *int64 MinItems *int64 UniqueItems *bool // 5.4. Validation keywords for objects MaxProperties *int64 MinProperties *int64 Required *[]string AdditionalProperties *SchemaOrBoolean Properties *[]*NamedSchema PatternProperties *[]*NamedSchema Dependencies *[]*NamedSchemaOrStringArray // 5.5. Validation keywords for any instance type Enumeration *[]SchemaEnumValue Type *StringOrStringArray AllOf *[]*Schema AnyOf *[]*Schema OneOf *[]*Schema Not *Schema Definitions *[]*NamedSchema // 6. Metadata keywords Title *string Description *string Default *yaml.Node // 7. Semantic validation with "format" Format *string }
The Schema struct models a JSON Schema and, because schemas are defined hierarchically, contains many references to itself. All fields are pointers and are nil if the associated values are not specified.
func NewBaseSchema ¶
NewBaseSchema builds a schema object from an embedded json representation.
func NewSchemaFromFile ¶
NewSchemaFromFile reads a schema from a file. Currently this assumes that schemas are stored in the source distribution of this project.
func NewSchemaFromObject ¶
func NewSchemaFromObject(jsonData *yaml.Node) *Schema
NewSchemaFromObject constructs a schema from a parsed JSON object. Due to the complexity of the schema representation, this is a custom reader and not the standard Go JSON reader (encoding/json).
func (*Schema) AddProperty ¶
AddProperty adds a named property.
func (*Schema) CopyOfficialSchemaProperties ¶
CopyOfficialSchemaProperties copies named properties from the official JSON Schema definition
func (*Schema) CopyOfficialSchemaProperty ¶
CopyOfficialSchemaProperty copies a named property from the official JSON Schema definition
func (*Schema) CopyProperties ¶
CopyProperties copies all non-nil properties from the source Schema to the schema Schema.
func (*Schema) DefinitionWithName ¶
DefinitionWithName returns the selected element.
func (*Schema) JSONString ¶
JSONString returns a json representation of a schema.
func (*Schema) PatternPropertyWithName ¶
PatternPropertyWithName returns the selected element.
func (*Schema) PropertyWithName ¶
PropertyWithName returns the selected element.
func (*Schema) ResolveAllOfs ¶
func (schema *Schema) ResolveAllOfs()
ResolveAllOfs replaces "allOf" elements by merging their properties into the parent Schema.
func (*Schema) ResolveAnyOfs ¶
func (schema *Schema) ResolveAnyOfs()
ResolveAnyOfs replaces all "anyOf" elements with "oneOf".
func (*Schema) ResolveRefs ¶
func (schema *Schema) ResolveRefs()
ResolveRefs resolves "$ref" elements in a Schema and its children. But if a reference refers to an object type, is inside a oneOf, or contains a oneOf, the reference is kept and we expect downstream tools to separately model these referenced schemas.
type SchemaEnumValue ¶
SchemaEnumValue represents a value that can be part of an enumeration in a Schema.
type SchemaNumber ¶
SchemaNumber represents a value that can be either an Integer or a Float.
func NewSchemaNumberWithFloat ¶
func NewSchemaNumberWithFloat(f float64) *SchemaNumber
NewSchemaNumberWithFloat creates and returns a new object
func NewSchemaNumberWithInteger ¶
func NewSchemaNumberWithInteger(i int64) *SchemaNumber
NewSchemaNumberWithInteger creates and returns a new object
type SchemaOperation ¶
SchemaOperation represents a function that can be applied to a Schema.
type SchemaOrBoolean ¶
SchemaOrBoolean represents a value that can be either a Schema or a Boolean.
func NewSchemaOrBooleanWithBoolean ¶
func NewSchemaOrBooleanWithBoolean(b bool) *SchemaOrBoolean
NewSchemaOrBooleanWithBoolean creates and returns a new object
func NewSchemaOrBooleanWithSchema ¶
func NewSchemaOrBooleanWithSchema(s *Schema) *SchemaOrBoolean
NewSchemaOrBooleanWithSchema creates and returns a new object
type SchemaOrSchemaArray ¶
SchemaOrSchemaArray represents a value that can be either a Schema or an Array of Schemas.
func NewSchemaOrSchemaArrayWithSchema ¶
func NewSchemaOrSchemaArrayWithSchema(s *Schema) *SchemaOrSchemaArray
NewSchemaOrSchemaArrayWithSchema creates and returns a new object
func NewSchemaOrSchemaArrayWithSchemaArray ¶
func NewSchemaOrSchemaArrayWithSchemaArray(a []*Schema) *SchemaOrSchemaArray
NewSchemaOrSchemaArrayWithSchemaArray creates and returns a new object
type SchemaOrStringArray ¶
SchemaOrStringArray represents a value that can be either a Schema or an Array of Strings.
type StringOrStringArray ¶
StringOrStringArray represents a value that can be either a String or an Array of Strings.
func NewStringOrStringArrayWithString ¶
func NewStringOrStringArrayWithString(s string) *StringOrStringArray
NewStringOrStringArrayWithString creates and returns a new object
func NewStringOrStringArrayWithStringArray ¶
func NewStringOrStringArrayWithStringArray(a []string) *StringOrStringArray
NewStringOrStringArrayWithStringArray creates and returns a new object
func (*StringOrStringArray) Description ¶
func (s *StringOrStringArray) Description() string
Description returns a string representation of a string or string array.