Documentation
¶
Index ¶
- Constants
- func BoolValidator() survey.Validator
- func DateTimeValidator() survey.Validator
- func DateValidator() survey.Validator
- func EmailValidator() survey.Validator
- func EnumValidator(enum []interface{}) survey.Validator
- func FloatValidator() survey.Validator
- func HostnameValidator() survey.Validator
- func IntegerValidator() survey.Validator
- func Ipv4Validator() survey.Validator
- func Ipv6Validator() survey.Validator
- func JSONPointerValidator() survey.Validator
- func MaxItemsValidator(maxItems *int, value []interface{}) survey.Validator
- func MaxLengthValidator(maxLength *int) survey.Validator
- func MaxPropertiesValidator(maxItems *int, value *orderedmap.OrderedMap, key string) survey.Validator
- func MaxValidator(max *float64, exclusive bool) survey.Validator
- func MinItemsValidator(minItems *int, value []interface{}) survey.Validator
- func MinLengthValidator(minLength *int) survey.Validator
- func MinPropertiesValidator(minItems *int, value *orderedmap.OrderedMap, key string) survey.Validator
- func MinValidator(min *float64, exclusive bool) survey.Validator
- func MultipleOfValidator(multipleOf *float64) survey.Validator
- func NoWhiteSpaceValidator() survey.Validator
- func NoopValidator() survey.Validator
- func OverrideAnswerValidator(ans interface{}, validator survey.Validator) survey.Validator
- func PatternValidator(pattern *string) survey.Validator
- func RequiredValidator(required bool) survey.Validator
- func TimeValidator() survey.Validator
- func URIReferenceValidator() survey.Validator
- func URIValidator() survey.Validator
- func UniqueItemsValidator(value []interface{}) survey.Validator
- type Definitions
- type Dependency
- type Items
- type JSONSchemaOptions
- func (o *JSONSchemaOptions) GenerateValues(schemaBytes []byte, existingValues map[string]interface{}) ([]byte, error)
- func (o *JSONSchemaOptions) Recurse(ctx SchemaContext) error
- func (o *JSONSchemaOptions) RecurseArray(ctx SchemaContext) error
- func (o *JSONSchemaOptions) RecurseBoolean(ctx SchemaContext) error
- func (o *JSONSchemaOptions) RecurseInteger(ctx SchemaContext) error
- func (o *JSONSchemaOptions) RecurseNull(ctx SchemaContext) error
- func (o *JSONSchemaOptions) RecurseNumber(ctx SchemaContext) error
- func (o *JSONSchemaOptions) RecurseObject(ctx SchemaContext) error
- func (o *JSONSchemaOptions) RecurseOneOf(ctx SchemaContext) error
- func (o *JSONSchemaOptions) RecurseString(ctx SchemaContext) error
- type JSONSchemaType
- type Properties
- type SchemaContext
Constants ¶
const ( RefPathPrefixDefs = "#/$defs/" RefPathPrefixDefinitions = "#/definitions/" )
Variables ¶
This section is empty.
Functions ¶
func BoolValidator ¶
BoolValidator validates that val is a bool
func DateTimeValidator ¶
DateTimeValidator validates that a string is a RFC 3339 date-time format
func DateValidator ¶
DateValidator validates that a string is a RFC 3339 full-date format
func EmailValidator ¶
EmailValidator validates that a string is a RFC 5322 email
func EnumValidator ¶
EnumValidator validates that val appears in the enum
func FloatValidator ¶
FloatValidator validates that val is a float
func HostnameValidator ¶
HostnameValidator validates that a string is a RFC 1034 hostname
func IntegerValidator ¶
IntegerValidator validates that val is an int
func Ipv4Validator ¶
Ipv4Validator validates that a string is a RFC 2673 IPv4 address
func Ipv6Validator ¶
Ipv6Validator validates that a string is a RFC 4291 IPv6 address
func JSONPointerValidator ¶
JSONPointerValidator validates that a string is a JSON Pointer
func MaxItemsValidator ¶
MaxItemsValidator validates that at most the maxItems number of items exist in a slice
func MaxLengthValidator ¶
MaxLengthValidator validates that val is shorter in length than maxLength
func MaxPropertiesValidator ¶
func MaxPropertiesValidator(maxItems *int, value *orderedmap.OrderedMap, key string) survey.Validator
MaxPropertiesValidator validates that at most the maxItems number of key-value pairs exist in a map
func MaxValidator ¶
MaxValidator validates that the val is less than the max, if exclusive, then less than or equal to
func MinItemsValidator ¶
MinItemsValidator validates that at least the minItems number of items exist in a slice
func MinLengthValidator ¶
MinLengthValidator validates that val is longer in length than minLength
func MinPropertiesValidator ¶
func MinPropertiesValidator(minItems *int, value *orderedmap.OrderedMap, key string) survey.Validator
MinPropertiesValidator validates that at least the minItems number of key-value pairs exist in a map
func MinValidator ¶
MinValidator validates that the val is more than the min, if exclusive then more than or equal to
func MultipleOfValidator ¶
MultipleOfValidator validates that the val is a multiple of multipleOf
func NoWhiteSpaceValidator ¶
NoWhiteSpaceValidator is an input validator for the survey package that disallows any whitespace in the val
func NoopValidator ¶
NoopValidator always passes (use instead of nil in a slice of validators)
func OverrideAnswerValidator ¶
OverrideAnswerValidator will validate the answer supplied as an argument, rather the answer the user provides this is useful when you want to validate the value a confirm dialog is confirming, rather than the Y/n
func PatternValidator ¶
PatternValidator validates that the val matches the regex pattern
func RequiredValidator ¶
RequiredValidator applies the RequiredValidator if required is true
func TimeValidator ¶
TimeValidator validates that a string is a RFC3339 full-time format
func URIReferenceValidator ¶
URIReferenceValidator validates that a string is a valid RFC 3986 URI Reference
func URIValidator ¶
URIValidator validates that a string is a valid RFC 3986 URI
func UniqueItemsValidator ¶
UniqueItemsValidator validates that the val is unique in a slice
Types ¶
type Dependency ¶
type Dependency struct {
Type *JSONSchemaType `json:-`
Array []string `json:-`
}
Dependency is either a Type or an array of strings, and so requires special unmarshaling from JSON
func (*Dependency) UnmarshalJSON ¶
func (d *Dependency) UnmarshalJSON(b []byte) error
UnmarshalJSON performs unmarshals Dependency from JSON, required as the json field can be one of two types
type Items ¶
type Items struct {
Types []*JSONSchemaType `json:-`
Type *JSONSchemaType `json:-`
}
Items is a either a Type or a array of types, and so requires special unmarshaling from JSON
func (*Items) UnmarshalJSON ¶
UnmarshalJSON performs unmarshals Items from JSON, required as the json field can be one of two types
type JSONSchemaOptions ¶
type JSONSchemaOptions struct {
// If there are existingValues then those questions will be
// ignored and the existing value used unless askExisting is true
AskExisting bool
// If AutoAcceptDefaults is true, then default values will be used automatically.
AutoAcceptDefaults bool
NoAsk bool
// If IgnoreMissingValues is false then any values which don't have an existing value
// (or a default value if autoAcceptDefaults is true) will cause an error
IgnoreMissingValues bool
In terminal.FileReader
Out terminal.FileWriter
OutErr io.Writer
Overrides map[string]func(o *JSONSchemaOptions, ctx SchemaContext) error
}
JSONSchemaOptions are options for generating values from a schema
func (*JSONSchemaOptions) GenerateValues ¶
func (o *JSONSchemaOptions) GenerateValues(schemaBytes []byte, existingValues map[string]interface{}) ([]byte, error)
GenerateValues examines the schema in schemaBytes, asks a series of questions using in, out and outErr,
func (*JSONSchemaOptions) Recurse ¶ added in v0.10.0
func (o *JSONSchemaOptions) Recurse(ctx SchemaContext) error
func (*JSONSchemaOptions) RecurseArray ¶ added in v0.10.0
func (o *JSONSchemaOptions) RecurseArray(ctx SchemaContext) error
func (*JSONSchemaOptions) RecurseBoolean ¶ added in v0.10.0
func (o *JSONSchemaOptions) RecurseBoolean(ctx SchemaContext) error
func (*JSONSchemaOptions) RecurseInteger ¶ added in v0.10.0
func (o *JSONSchemaOptions) RecurseInteger(ctx SchemaContext) error
func (*JSONSchemaOptions) RecurseNull ¶ added in v0.10.0
func (o *JSONSchemaOptions) RecurseNull(ctx SchemaContext) error
func (*JSONSchemaOptions) RecurseNumber ¶ added in v0.10.0
func (o *JSONSchemaOptions) RecurseNumber(ctx SchemaContext) error
func (*JSONSchemaOptions) RecurseObject ¶ added in v0.10.0
func (o *JSONSchemaOptions) RecurseObject(ctx SchemaContext) error
func (*JSONSchemaOptions) RecurseOneOf ¶ added in v0.13.0
func (o *JSONSchemaOptions) RecurseOneOf(ctx SchemaContext) error
func (*JSONSchemaOptions) RecurseString ¶ added in v0.10.0
func (o *JSONSchemaOptions) RecurseString(ctx SchemaContext) error
type JSONSchemaType ¶
type JSONSchemaType struct {
Version string `json:"$schema,omitempty"`
Ref string `json:"$ref,omitempty"`
MultipleOf *float64 `json:"multipleOf,omitempty"`
Maximum *float64 `json:"maximum,omitempty"`
ExclusiveMaximum *float64 `json:"exclusiveMaximum,omitempty"`
Minimum *float64 `json:"minimum,omitempty"`
ExclusiveMinimum *float64 `json:"exclusiveMinimum,omitempty"`
MaxLength *int `json:"maxLength,omitempty"`
MinLength *int `json:"minLength,omitempty"`
Pattern *string `json:"pattern,omitempty"`
AdditionalItems *JSONSchemaType `json:"additionalItems,omitempty"`
Items Items `json:"items,omitempty"`
MaxItems *int `json:"maxItems,omitempty"`
MinItems *int `json:"minItems,omitempty"`
UniqueItems bool `json:"uniqueItems,omitempty"`
MaxProperties *int `json:"maxProperties,omitempty"`
MinProperties *int `json:"minProperties,omitempty"`
Required []string `json:"required,omitempty"`
Properties *Properties `json:"properties,omitempty"`
PatternProperties map[string]*JSONSchemaType `json:"patternProperties,omitempty"`
AdditionalProperties *interface{} `json:"additionalProperties,omitempty"`
Dependencies map[string]Dependency `json:"dependencies,omitempty"`
PropertyNames *JSONSchemaType `json:"propertyNames,omitempty"`
Enum []interface{} `json:"enum,omitempty"`
Type string `json:"type,omitempty"`
If *JSONSchemaType `json:"if,omitempty"`
Then *JSONSchemaType `json:"then,omitempty"`
Else *JSONSchemaType `json:"else,omitempty"`
AllOf []*JSONSchemaType `json:"allOf,omitempty"`
AnyOf []*JSONSchemaType `json:"anyOf,omitempty"`
OneOf []*JSONSchemaType `json:"oneOf,omitempty"`
Not *JSONSchemaType `json:"not,omitempty"`
Definitions Definitions `json:"$defs,omitempty"`
DefinitionsAlias Definitions `json:"definitions,omitempty"`
Contains *JSONSchemaType `json:"contains,omitempty"`
Const *interface{} `json:"const,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Default interface{} `json:"default,omitempty"`
Format *string `json:"format,omitempty"`
ContentMediaType *string `json:"contentMediaType,omitempty"`
ContentEncoding *string `json:"contentEncoding,omitempty"`
}
Based of https://www.ietf.org/archive/id/draft-handrews-json-schema-validation-01.txt
func (*JSONSchemaType) ToString ¶ added in v0.13.0
func (schema *JSONSchemaType) ToString() string
type Properties ¶
type Properties struct {
*orderedmap.OrderedMap
}
Properties is a set of ordered key-value pairs, as it is ordered it requires special marshaling to/from JSON
func (*Properties) UnmarshalJSON ¶
func (p *Properties) UnmarshalJSON(b []byte) error
UnmarshalJSON performs custom Unmarshaling for Properties allowing us to preserve order, which is not a standard JSON feature
type SchemaContext ¶ added in v0.10.0
type SchemaContext struct {
Name string
Prefixes []string
RequiredFields []string
SchemaType *JSONSchemaType
ParentType *JSONSchemaType
Output *orderedmap.OrderedMap
AdditionalValidators []survey.Validator
ExistingValues map[string]interface{}
Definitions *map[string]*interface{}
Required bool
}