package module
Version: v0.0.0-...-b0ff291 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2021 License: LGPL-3.0 Imports: 8 Imported by: 37



This is a juju-specific jsonschema package that adds some metadata to schema values for the purposes generating UX to prompt users for configuration values.

Otherwise, it is 100% just normal jsonschema.

This is effectively just a custom frontend on top of https://github.com/lestrrat/go-jsschema



Package jsonschema adds juju-specific metadata to jsonschema.



This section is empty.


This section is empty.


func Bool

func Bool(b bool) *bool

Bool is a helper function for use in struct literals.

func Float

func Float(f float64) *float64

Float is a helper function for use in struct literals.

func Int

func Int(i int) *int

Int is a helper function for use in struct literals.


type DependencyMap

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

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

type ItemSpec struct {
	TupleMode bool
	Schemas   []*Schema

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

type Schema

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

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

FromGo extracts the jsonschema represented by v.

func FromJSON

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

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

func FromYAML

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

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

func (*Schema) InsertDefaults

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

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

MarshalJSON implements the json.Marshaler.

func (*Schema) UnmarshalJSON

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

UnmarshalJSON implements the json.Marshaler.

func (*Schema) Validate

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

type Type int

Type defines the standard jsonschema value types.IntegerType

const (
	UnspecifiedType Type = iota

Standard jsonschema types.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL