jsonschema: github.com/juju/jsonschema Index | Files

package jsonschema

import "github.com/juju/jsonschema"

Package jsonschema adds juju-specific metadata to jsonschema.


Package Files


func Bool Uses

func Bool(b bool) *bool

Bool is a helper function for use in struct literals.

func Float Uses

func Float(f float64) *float64

Float is a helper function for use in struct literals.

func Int Uses

func Int(i int) *int

Int is a helper function for use in struct literals.

type DependencyMap Uses

type DependencyMap struct {
    Names   map[string][]string
    Schemas map[string]*Schema

DependencyMap contains the dependencies defined within this schema. for a given dependency name, you can have either a schema or a list of property names

type Format Uses

type Format string

Format defines well-known jsonschema formats for strings.

const (
    FormatDateTime Format = "date-time"
    FormatEmail    Format = "email"
    FormatHostname Format = "hostname"
    FormatIPv4     Format = "ipv4"
    FormatIPv6     Format = "ipv6"
    FormatURI      Format = "uri"

Standard jsonschema formats.

type ItemSpec Uses

type ItemSpec struct {
    TupleMode bool
    Schemas   []*Schema

ItemSpec contains the schemas for any items in an array type.

type Schema Uses

type Schema struct {
    ID          string             `json:"id,omitempty"`
    Title       string             `json:"title,omitempty"`
    Description string             `json:"description,omitempty"`
    Default     interface{}        `json:"default,omitempty"`
    Type        []Type             `json:"type,omitempty"`
    SchemaRef   string             `json:"$schema,omitempty"`
    Definitions map[string]*Schema `json:"definitions,omitempty"`
    Reference   string             `json:"$ref,omitempty"`
    Format      Format             `json:"format,omitempty"`

    // NumericValidations
    MultipleOf       *float64 `json:"multipleOf,omitempty"`
    Minimum          *float64 `json:"minimum,omitempty"`
    Maximum          *float64 `json:"maximum,omitempty"`
    ExclusiveMinimum *bool    `json:"exclusiveMinimum,omitempty"`
    ExclusiveMaximum *bool    `json:"exclusiveMaximum,omitempty"`

    // StringValidation
    MaxLength *int           `json:"maxLength,omitempty"`
    MinLength *int           `json:"minLength,omitempty"`
    Pattern   *regexp.Regexp `json:"pattern,omitempty"`

    // ArrayValidations
    AdditionalItems *Schema   `json:"additionalItems,omitempty"`
    Items           *ItemSpec `json:"items,omitempty"`
    MinItems        *int      `json:"minItems,omitempty"`
    MaxItems        *int      `json:"maxItems,omitempty"`
    UniqueItems     *bool     `json:"uniqueItems,omitempty"`

    // ObjectValidations
    MaxProperties        *int                       `json:"maxProperties,omitempty"`
    MinProperties        *int                       `json:"minProperties,omitempty"`
    Required             []string                   `json:"required,omitempty"`
    Dependencies         DependencyMap              `json:"dependencies,omitempty"`
    Properties           map[string]*Schema         `json:"properties,omitempty"`
    AdditionalProperties *Schema                    `json:"additionalProperties,omitempty"`
    PatternProperties    map[*regexp.Regexp]*Schema `json:"patternProperties,omitempty"`

    Enum  []interface{} `json:"enum,omitempty"`
    AllOf []*Schema     `json:"allOf,omitempty"`
    AnyOf []*Schema     `json:"anyOf,omitempty"`
    OneOf []*Schema     `json:"oneOf,omitempty"`
    Not   *Schema       `json:"not,omitempty"`

    // Immutable specifies whether the attribute cannot
    // be changed once set.
    Immutable bool `json:"immutable,omitempty"`

    // Secret specifies whether the attribute should be
    // considered secret.
    Secret bool `json:"secret,omitempty"`

    // EnvVars holds environment variables that will be used to obtain the
    // default value if it isn't specified, they are checked from highest to
    // lowest priority.
    EnvVars []string `json:"env-vars,omitempty"`

    // Example holds an example value for the attribute
    // that can be used to produce a plausible-looking
    // entry for the attribute without necessarily using
    // it as a default value.
    // TODO if the example holds some special values, use
    // it as a template to generate initial random values
    // (for example for admin-password) ?
    Example interface{} `json:"example,omitempty"`

    // Order is the order in which properties should be requested of the user
    // during an interactive session.
    Order []string `json:"order,omitempty"`

    // Singular contains the singular version of the human-friendly name of this
    // property.
    Singular string `json:"singular,omitempty"`

    // Plural contains the plural version of the human-friendly name of this
    // property.
    Plural string `json:"plural,omitempty"`

    // PromptDefault contains the default value the user can accept during
    // interactive add-cloud.
    PromptDefault interface{} `json:"prompt-default,omitempty"`

    // PathFor should contain the name of another property in this schema. If a
    // value for that property does not exist, and this property's value is set,
    // the value from this property is interpreted as a filepath, and the
    // contents of that filepath are used as the value of the given property.
    // This is useful for properties with large values, such as encryption keys.
    PathFor string `json:"path-for,omitempty"`

Schema represents a fully defined jsonschema plus some metadata for the purposes of UX generation. See http://jsonschema.org for details.

func FromGo Uses

func FromGo(v interface{}) (*Schema, error)

FromGo extracts the jsonschema represented by v.

func FromJSON Uses

func FromJSON(r io.Reader) (*Schema, error)

FromJSON returns a schema created from the json value in r.

func FromYAML Uses

func FromYAML(r io.Reader) (*Schema, error)

FromYAML returns a schema created from the yaml value in r.

func (*Schema) InsertDefaults Uses

func (s *Schema) InsertDefaults(into map[string]interface{})

InsertDefaults takes a target map and inserts any missing default values as specified in the properties map, according to JSON-Schema.

func (*Schema) MarshalJSON Uses

func (s *Schema) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler.

func (*Schema) UnmarshalJSON Uses

func (s *Schema) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Marshaler.

func (*Schema) Validate Uses

func (s *Schema) Validate(x interface{}) error

Validate validates the given value based on the jsonschema in s. Values are expected to be map[string]interface{} for object types, strings for string type, int for integer type, float64 or integer for number type, or an array of one of the previous types.

type Type Uses

type Type int

Type defines the standard jsonschema value types.IntegerType

const (
    UnspecifiedType Type = iota

Standard jsonschema types.

Package jsonschema imports 8 packages (graph) and is imported by 130 packages. Updated 2016-11-08. Refresh now. Tools for package owners.