func Render(node *yaml.Node) string
Render renders a yaml.Node as JSON
NamedSchema is a name-value pair that is used to emulate maps with ordered keys.
type NamedSchema struct { Name string Value *Schema }
func NewNamedSchema(name string, value *Schema) *NamedSchema
NewNamedSchema creates and returns a new object
NamedSchemaOrStringArray is a name-value pair that is used to emulate maps with ordered keys.
type NamedSchemaOrStringArray struct { Name string Value *SchemaOrStringArray }
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() (schema *Schema, err error)
NewBaseSchema builds a schema object from an embedded json representation.
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(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 (s *Schema) AddProperty(name string, property *Schema)
AddProperty adds a named property.
func (schema *Schema) CopyOfficialSchemaProperties(names []string)
CopyOfficialSchemaProperties copies named properties from the official JSON Schema definition
func (schema *Schema) CopyOfficialSchemaProperty(name string)
CopyOfficialSchemaProperty copies a named property from the official JSON Schema definition
func (schema *Schema) CopyProperties(source *Schema)
CopyProperties copies all non-nil properties from the source Schema to the schema Schema.
func (s *Schema) DefinitionWithName(name string) *Schema
DefinitionWithName returns the selected element.
func (schema *Schema) IsEmpty() bool
IsEmpty returns true if no members of the Schema are specified.
func (schema *Schema) IsEqual(schema2 *Schema) bool
IsEqual returns true if two schemas are equal.
func (schema *Schema) JSONString() string
JSONString returns a json representation of a schema.
func (s *Schema) PatternPropertyWithName(name string) *Schema
PatternPropertyWithName returns the selected element.
func (s *Schema) PropertyWithName(name string) *Schema
PropertyWithName returns the selected element.
func (schema *Schema) ResolveAllOfs()
ResolveAllOfs replaces "allOf" elements by merging their properties into the parent Schema.
func (schema *Schema) ResolveAnyOfs()
ResolveAnyOfs replaces all "anyOf" elements with "oneOf".
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 *Schema) String() string
Returns a string representation of a Schema.
func (schema *Schema) TypeIs(typeName string) bool
TypeIs returns true if the Type of a Schema includes the specified type
SchemaEnumValue represents a value that can be part of an enumeration in a Schema.
type SchemaEnumValue struct { String *string Bool *bool }
SchemaNumber represents a value that can be either an Integer or a Float.
type SchemaNumber struct { Integer *int64 Float *float64 }
func NewSchemaNumberWithFloat(f float64) *SchemaNumber
NewSchemaNumberWithFloat creates and returns a new object
func NewSchemaNumberWithInteger(i int64) *SchemaNumber
NewSchemaNumberWithInteger creates and returns a new object
SchemaOperation represents a function that can be applied to a Schema.
type SchemaOperation func(schema *Schema, context string)
SchemaOrBoolean represents a value that can be either a Schema or a Boolean.
type SchemaOrBoolean struct { Schema *Schema Boolean *bool }
func NewSchemaOrBooleanWithBoolean(b bool) *SchemaOrBoolean
NewSchemaOrBooleanWithBoolean creates and returns a new object
func NewSchemaOrBooleanWithSchema(s *Schema) *SchemaOrBoolean
NewSchemaOrBooleanWithSchema creates and returns a new object
SchemaOrSchemaArray represents a value that can be either a Schema or an Array of Schemas.
type SchemaOrSchemaArray struct { Schema *Schema SchemaArray *[]*Schema }
func NewSchemaOrSchemaArrayWithSchema(s *Schema) *SchemaOrSchemaArray
NewSchemaOrSchemaArrayWithSchema creates and returns a new object
func NewSchemaOrSchemaArrayWithSchemaArray(a []*Schema) *SchemaOrSchemaArray
NewSchemaOrSchemaArrayWithSchemaArray creates and returns a new object
SchemaOrStringArray represents a value that can be either a Schema or an Array of Strings.
type SchemaOrStringArray struct { Schema *Schema StringArray *[]string }
StringOrStringArray represents a value that can be either a String or an Array of Strings.
type StringOrStringArray struct { String *string StringArray *[]string }
func NewStringOrStringArrayWithString(s string) *StringOrStringArray
NewStringOrStringArrayWithString creates and returns a new object
func NewStringOrStringArrayWithStringArray(a []string) *StringOrStringArray
NewStringOrStringArrayWithStringArray creates and returns a new object
func (s *StringOrStringArray) Description() string
Description returns a string representation of a string or string array.