...

Package jsonschema

import "github.com/google/gnostic-models/jsonschema"
Overview
Index

Overview ▾

Package jsonschema supports the reading, writing, and manipulation of JSON Schemas.

Index ▾

func Render(node *yaml.Node) string
type NamedSchema
    func NewNamedSchema(name string, value *Schema) *NamedSchema
type NamedSchemaOrStringArray
type Schema
    func NewBaseSchema() (schema *Schema, err error)
    func NewSchemaFromFile(filename string) (schema *Schema, err error)
    func NewSchemaFromObject(jsonData *yaml.Node) *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
    func NewSchemaNumberWithFloat(f float64) *SchemaNumber
    func NewSchemaNumberWithInteger(i int64) *SchemaNumber
type SchemaOperation
type SchemaOrBoolean
    func NewSchemaOrBooleanWithBoolean(b bool) *SchemaOrBoolean
    func NewSchemaOrBooleanWithSchema(s *Schema) *SchemaOrBoolean
type SchemaOrSchemaArray
    func NewSchemaOrSchemaArrayWithSchema(s *Schema) *SchemaOrSchemaArray
    func NewSchemaOrSchemaArrayWithSchemaArray(a []*Schema) *SchemaOrSchemaArray
type SchemaOrStringArray
type StringOrStringArray
    func NewStringOrStringArrayWithString(s string) *StringOrStringArray
    func NewStringOrStringArrayWithStringArray(a []string) *StringOrStringArray
    func (s *StringOrStringArray) Description() string

Package files

base.go display.go models.go operations.go reader.go writer.go

func Render

func Render(node *yaml.Node) string

Render renders a yaml.Node as JSON

type NamedSchema

NamedSchema is a name-value pair that is used to emulate maps with ordered keys.

type NamedSchema struct {
    Name  string
    Value *Schema
}

func NewNamedSchema

func NewNamedSchema(name string, value *Schema) *NamedSchema

NewNamedSchema creates and returns a new object

type NamedSchemaOrStringArray

NamedSchemaOrStringArray is a name-value pair that is used to emulate maps with ordered keys.

type NamedSchemaOrStringArray struct {
    Name  string
    Value *SchemaOrStringArray
}

type Schema

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.

type Schema struct {
    Schema *string // $schema
    ID     *string // id keyword used for $ref resolution scope
    Ref    *string // $ref, i.e. JSON Pointers

    // 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
}

func NewBaseSchema

func NewBaseSchema() (schema *Schema, err error)

NewBaseSchema builds a schema object from an embedded json representation.

func NewSchemaFromFile

func NewSchemaFromFile(filename string) (schema *Schema, err error)

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

func (s *Schema) AddProperty(name string, property *Schema)

AddProperty adds a named property.

func (*Schema) CopyOfficialSchemaProperties

func (schema *Schema) CopyOfficialSchemaProperties(names []string)

CopyOfficialSchemaProperties copies named properties from the official JSON Schema definition

func (*Schema) CopyOfficialSchemaProperty

func (schema *Schema) CopyOfficialSchemaProperty(name string)

CopyOfficialSchemaProperty copies a named property from the official JSON Schema definition

func (*Schema) CopyProperties

func (schema *Schema) CopyProperties(source *Schema)

CopyProperties copies all non-nil properties from the source Schema to the schema Schema.

func (*Schema) DefinitionWithName

func (s *Schema) DefinitionWithName(name string) *Schema

DefinitionWithName returns the selected element.

func (*Schema) IsEmpty

func (schema *Schema) IsEmpty() bool

IsEmpty returns true if no members of the Schema are specified.

func (*Schema) IsEqual

func (schema *Schema) IsEqual(schema2 *Schema) bool

IsEqual returns true if two schemas are equal.

func (*Schema) JSONString

func (schema *Schema) JSONString() string

JSONString returns a json representation of a schema.

func (*Schema) PatternPropertyWithName

func (s *Schema) PatternPropertyWithName(name string) *Schema

PatternPropertyWithName returns the selected element.

func (*Schema) PropertyWithName

func (s *Schema) PropertyWithName(name string) *Schema

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.

func (*Schema) String

func (schema *Schema) String() string

Returns a string representation of a Schema.

func (*Schema) TypeIs

func (schema *Schema) TypeIs(typeName string) bool

TypeIs returns true if the Type of a Schema includes the specified type

type SchemaEnumValue

SchemaEnumValue represents a value that can be part of an enumeration in a Schema.

type SchemaEnumValue struct {
    String *string
    Bool   *bool
}

type SchemaNumber

SchemaNumber represents a value that can be either an Integer or a Float.

type SchemaNumber struct {
    Integer *int64
    Float   *float64
}

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 SchemaOperation func(schema *Schema, context string)

type SchemaOrBoolean

SchemaOrBoolean represents a value that can be either a Schema or a Boolean.

type SchemaOrBoolean struct {
    Schema  *Schema
    Boolean *bool
}

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.

type SchemaOrSchemaArray struct {
    Schema      *Schema
    SchemaArray *[]*Schema
}

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 SchemaOrStringArray struct {
    Schema      *Schema
    StringArray *[]string
}

type StringOrStringArray

StringOrStringArray represents a value that can be either a String or an Array of Strings.

type StringOrStringArray struct {
    String      *string
    StringArray *[]string
}

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.