schema

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AnnotationNullable     template.AnnotationName = "schema/nullable"
	AnnotationType         template.AnnotationName = "schema/type"
	AnnotationDefault      template.AnnotationName = "schema/default"
	AnnotationDescription  template.AnnotationName = "schema/desc"
	AnnotationTitle        template.AnnotationName = "schema/title"
	AnnotationExamples     template.AnnotationName = "schema/examples"
	AnnotationDeprecated   template.AnnotationName = "schema/deprecated"
	TypeAnnotationKwargAny string                  = "any"
)
View Source
const (
	FloatType  = float64(0)
	StringType = ""
	IntType    = int64(0)
	BoolType   = false
)

The total set of supported scalars.

Variables

This section is empty.

Functions

func NewMismatchedTypeAssertionError added in v0.35.0

func NewMismatchedTypeAssertionError(foundNode yamlmeta.Node, expectedType Type) error

NewMismatchedTypeAssertionError generates an error given that `foundNode` is not of the `expectedType`.

func NewSchemaError added in v0.35.0

func NewSchemaError(summary string, errs ...error) error

func NewUnexpectedKeyAssertionError added in v0.35.0

func NewUnexpectedKeyAssertionError(found *yamlmeta.MapItem, definition *filepos.Position, allowedKeys []string) error

NewUnexpectedKeyAssertionError generates a schema assertion error including the context (and hints) needed to report it to the user

func SetType added in v0.39.0

func SetType(n yamlmeta.Node, t Type)

SetType attaches schema metadata to `n`, later retrieved via GetType().

Types

type Annotation added in v0.34.0

type Annotation interface {
	NewTypeFromAnn() (Type, error)
	GetPosition() *filepos.Position
}

type AnyType added in v0.34.0

type AnyType struct {
	Position *filepos.Position
	// contains filtered or unexported fields
}

func (AnyType) AssignTypeTo added in v0.34.0

func (a AnyType) AssignTypeTo(yamlmeta.Node) TypeCheck

AssignTypeTo is a no-op given that AnyType allows all types.

func (AnyType) CheckType added in v0.34.0

func (a AnyType) CheckType(node yamlmeta.Node) TypeCheck

CheckType is a no-op because AnyType allows any value.

Always returns an empty TypeCheck.

func (AnyType) GetDefaultValue added in v0.35.0

func (a AnyType) GetDefaultValue() interface{}

GetDefaultValue provides the default value

func (AnyType) GetDefinitionPosition added in v0.35.0

func (a AnyType) GetDefinitionPosition() *filepos.Position

GetDefinitionPosition reports the location in source schema that contains this type definition.

func (*AnyType) GetDescription added in v0.38.0

func (a *AnyType) GetDescription() string

GetDescription provides descriptive information

func (*AnyType) GetExamples added in v0.39.0

func (a *AnyType) GetExamples() []Example

GetExamples provides descriptive example information

func (*AnyType) GetTitle added in v0.39.0

func (a *AnyType) GetTitle() string

GetTitle provides title information

func (AnyType) GetValueType added in v0.34.0

func (a AnyType) GetValueType() Type

GetValueType provides the type of the value

func (*AnyType) IsDeprecated added in v0.39.0

func (a *AnyType) IsDeprecated() (bool, string)

IsDeprecated provides deprecated field information

func (*AnyType) SetDefaultValue added in v0.38.0

func (a *AnyType) SetDefaultValue(val interface{})

SetDefaultValue does nothing

func (*AnyType) SetDeprecated added in v0.39.0

func (a *AnyType) SetDeprecated(deprecated bool, notice string)

SetDeprecated sets the deprecated field value

func (*AnyType) SetDescription added in v0.38.0

func (a *AnyType) SetDescription(desc string)

SetDescription sets the description of the type

func (*AnyType) SetExamples added in v0.39.0

func (a *AnyType) SetExamples(exs []Example)

SetExamples sets the description and example of the type

func (*AnyType) SetTitle added in v0.39.0

func (a *AnyType) SetTitle(title string)

SetTitle sets the title of the type

func (AnyType) String added in v0.34.0

func (a AnyType) String() string

String produces a user-friendly name of the expected type.

type ArrayItemType

type ArrayItemType struct {
	ValueType Type
	Position  *filepos.Position
	// contains filtered or unexported fields
}

func NewArrayItemType

func NewArrayItemType(item *yamlmeta.ArrayItem) (*ArrayItemType, error)

func (*ArrayItemType) AssignTypeTo

func (a *ArrayItemType) AssignTypeTo(node yamlmeta.Node) TypeCheck

AssignTypeTo assigns this schema metadata to `node`.

If `node` is not a yamlmeta.ArrayItem, `chk` contains a violation describing the mismatch If `node`'s value is not of the same structure (i.e. yamlmeta.Node type), `chk` contains a violation describing this mismatch

func (*ArrayItemType) CheckType

func (a *ArrayItemType) CheckType(node yamlmeta.Node) TypeCheck

CheckType checks the type of `node` against this ArrayItemType.

If `node` is not a yamlmeta.ArrayItem, `chk` contains a violation describing this mismatch If this array item's value is a scalar, checks its type against this ArrayItemType.ValueType

func (ArrayItemType) GetDefaultValue added in v0.35.0

func (a ArrayItemType) GetDefaultValue() interface{}

GetDefaultValue provides the default value

func (ArrayItemType) GetDefinitionPosition added in v0.35.0

func (a ArrayItemType) GetDefinitionPosition() *filepos.Position

GetDefinitionPosition reports the location in source schema that contains this type definition.

func (*ArrayItemType) GetDescription added in v0.38.0

func (a *ArrayItemType) GetDescription() string

GetDescription provides descriptive information

func (*ArrayItemType) GetExamples added in v0.39.0

func (a *ArrayItemType) GetExamples() []Example

GetExamples provides descriptive example information

func (*ArrayItemType) GetTitle added in v0.39.0

func (a *ArrayItemType) GetTitle() string

GetTitle provides title information

func (ArrayItemType) GetValueType

func (a ArrayItemType) GetValueType() Type

GetValueType provides the type of the value

func (*ArrayItemType) IsDeprecated added in v0.39.0

func (a *ArrayItemType) IsDeprecated() (bool, string)

IsDeprecated provides deprecated field information

func (*ArrayItemType) SetDefaultValue added in v0.38.0

func (a *ArrayItemType) SetDefaultValue(val interface{})

SetDefaultValue sets the default value to `val`

func (*ArrayItemType) SetDeprecated added in v0.39.0

func (a *ArrayItemType) SetDeprecated(deprecated bool, notice string)

SetDeprecated sets the deprecated field value

func (*ArrayItemType) SetDescription added in v0.38.0

func (a *ArrayItemType) SetDescription(desc string)

SetDescription sets the description of the type

func (*ArrayItemType) SetExamples added in v0.39.0

func (a *ArrayItemType) SetExamples(exs []Example)

SetExamples sets the description and example of the type

func (*ArrayItemType) SetTitle added in v0.39.0

func (a *ArrayItemType) SetTitle(title string)

SetTitle sets the title of the type

func (ArrayItemType) String added in v0.32.0

func (a ArrayItemType) String() string

String produces a user-friendly name of the expected type.

type ArrayType

type ArrayType struct {
	ItemsType Type
	Position  *filepos.Position
	// contains filtered or unexported fields
}

func NewArrayType

func NewArrayType(a *yamlmeta.Array) (*ArrayType, error)

func (*ArrayType) AssignTypeTo

func (a *ArrayType) AssignTypeTo(node yamlmeta.Node) TypeCheck

AssignTypeTo assigns this schema metadata to `node`.

If `node` is not a yamlmeta.Array, `chk` contains a violation describing the mismatch For each `node`'s yamlmeta.ArrayItem's that cannot be assigned this ArrayType's ArrayItemType, `chk` contains a violation describing the mismatch

func (*ArrayType) CheckType

func (a *ArrayType) CheckType(node yamlmeta.Node) TypeCheck

CheckType checks the type of `node` against this ArrayType

If `node` is not a yamlmeta.Array, `chk` contains a violation describing the mismatch

func (ArrayType) GetDefaultValue added in v0.35.0

func (a ArrayType) GetDefaultValue() interface{}

GetDefaultValue provides the default value

func (ArrayType) GetDefinitionPosition added in v0.35.0

func (a ArrayType) GetDefinitionPosition() *filepos.Position

GetDefinitionPosition reports the location in source schema that contains this type definition.

func (*ArrayType) GetDescription added in v0.38.0

func (a *ArrayType) GetDescription() string

GetDescription provides descriptive information

func (*ArrayType) GetExamples added in v0.39.0

func (a *ArrayType) GetExamples() []Example

GetExamples provides descriptive example information

func (*ArrayType) GetTitle added in v0.39.0

func (a *ArrayType) GetTitle() string

GetTitle provides title information

func (ArrayType) GetValueType

func (a ArrayType) GetValueType() Type

GetValueType provides the type of the value

func (*ArrayType) IsDeprecated added in v0.39.0

func (a *ArrayType) IsDeprecated() (bool, string)

IsDeprecated provides deprecated field information

func (*ArrayType) SetDefaultValue added in v0.38.0

func (a *ArrayType) SetDefaultValue(val interface{})

SetDefaultValue sets the default value to `val`

func (*ArrayType) SetDeprecated added in v0.39.0

func (a *ArrayType) SetDeprecated(deprecated bool, notice string)

SetDeprecated sets the deprecated field value

func (*ArrayType) SetDescription added in v0.38.0

func (a *ArrayType) SetDescription(desc string)

SetDescription sets the description of the type

func (*ArrayType) SetExamples added in v0.39.0

func (a *ArrayType) SetExamples(exs []Example)

SetExamples sets the description and example of the type

func (*ArrayType) SetTitle added in v0.39.0

func (a *ArrayType) SetTitle(title string)

SetTitle sets the title of the type

func (ArrayType) String added in v0.32.0

func (a ArrayType) String() string

String produces a user-friendly name of the expected type.

type DefaultAnnotation added in v0.38.0

type DefaultAnnotation struct {
	// contains filtered or unexported fields
}

DefaultAnnotation is a wrapper for a value provided via @schema/default annotation

func NewDefaultAnnotation added in v0.38.0

func NewDefaultAnnotation(ann template.NodeAnnotation, effectiveType Type, pos *filepos.Position) (*DefaultAnnotation, error)

NewDefaultAnnotation checks the argument provided via @schema/default annotation, and returns wrapper for that value.

func (*DefaultAnnotation) GetPosition added in v0.39.0

func (d *DefaultAnnotation) GetPosition() *filepos.Position

GetPosition returns position of the source comment used to create this annotation.

func (*DefaultAnnotation) NewTypeFromAnn added in v0.38.0

func (d *DefaultAnnotation) NewTypeFromAnn() (Type, error)

NewTypeFromAnn returns type information given by annotation.

func (*DefaultAnnotation) Val added in v0.38.0

func (d *DefaultAnnotation) Val() interface{}

Val returns default value specified in annotation.

type DeprecatedAnnotation added in v0.39.0

type DeprecatedAnnotation struct {
	// contains filtered or unexported fields
}

DeprecatedAnnotation is a wrapper for a value provided via @schema/deprecated annotation

func NewDeprecatedAnnotation added in v0.39.0

func NewDeprecatedAnnotation(ann template.NodeAnnotation, pos *filepos.Position) (*DeprecatedAnnotation, error)

NewDeprecatedAnnotation validates the value from the AnnotationDeprecated, and returns the value

func (*DeprecatedAnnotation) GetPosition added in v0.39.0

func (d *DeprecatedAnnotation) GetPosition() *filepos.Position

GetPosition returns position of the source comment used to create this annotation.

func (*DeprecatedAnnotation) NewTypeFromAnn added in v0.39.0

func (d *DeprecatedAnnotation) NewTypeFromAnn() (Type, error)

NewTypeFromAnn returns type information given by annotation. DeprecatedAnnotation has no type information.

type DescriptionAnnotation added in v0.38.0

type DescriptionAnnotation struct {
	// contains filtered or unexported fields
}

DescriptionAnnotation documents the purpose of a node

func NewDescriptionAnnotation added in v0.38.0

func NewDescriptionAnnotation(ann template.NodeAnnotation, pos *filepos.Position) (*DescriptionAnnotation, error)

NewDescriptionAnnotation validates the value from the AnnotationDescription, and returns the value

func (*DescriptionAnnotation) GetPosition added in v0.39.0

func (d *DescriptionAnnotation) GetPosition() *filepos.Position

GetPosition returns position of the source comment used to create this annotation.

func (*DescriptionAnnotation) NewTypeFromAnn added in v0.38.0

func (d *DescriptionAnnotation) NewTypeFromAnn() (Type, error)

NewTypeFromAnn returns type information given by annotation. DescriptionAnnotation has no type information.

type DocumentType

type DocumentType struct {
	Source    *yamlmeta.Document
	ValueType Type // typically one of: MapType, ArrayType, ScalarType
	Position  *filepos.Position
	// contains filtered or unexported fields
}

func NewDocumentType added in v0.32.0

func NewDocumentType(doc *yamlmeta.Document) (*DocumentType, error)

NewDocumentType constructs a complete DocumentType based on the contents of a schema YAML document.

func (*DocumentType) AssignTypeTo

func (t *DocumentType) AssignTypeTo(node yamlmeta.Node) TypeCheck

AssignTypeTo assigns this schema metadata to `node`.

If `node` is not a yamlmeta.Document, `chk` contains a violation describing the mismatch If `node`'s value is not of the same structure (i.e. yamlmeta.Node type), `chk` contains a violation describing this mismatch

func (*DocumentType) CheckType

func (t *DocumentType) CheckType(node yamlmeta.Node) TypeCheck

CheckType checks the type of `node` against this DocumentType.

If `node` is not a yamlmeta.Document, `chk` contains a violation describing this mismatch If this document's value is a scalar, checks its type against this DocumentType.ValueType

func (DocumentType) GetDefaultValue added in v0.35.0

func (t DocumentType) GetDefaultValue() interface{}

GetDefaultValue provides the default value

func (*DocumentType) GetDefinitionPosition added in v0.35.0

func (t *DocumentType) GetDefinitionPosition() *filepos.Position

GetDefinitionPosition reports the location in source schema that contains this type definition.

func (*DocumentType) GetDescription added in v0.38.0

func (t *DocumentType) GetDescription() string

GetDescription provides descriptive information

func (*DocumentType) GetExamples added in v0.39.0

func (t *DocumentType) GetExamples() []Example

GetExamples provides descriptive example information

func (*DocumentType) GetTitle added in v0.39.0

func (t *DocumentType) GetTitle() string

GetTitle provides title information

func (*DocumentType) GetValueType

func (t *DocumentType) GetValueType() Type

GetValueType provides the type of the value

func (*DocumentType) IsDeprecated added in v0.39.0

func (t *DocumentType) IsDeprecated() (bool, string)

IsDeprecated provides deprecated field information

func (*DocumentType) SetDefaultValue added in v0.38.0

func (t *DocumentType) SetDefaultValue(val interface{})

SetDefaultValue sets the default value of the entire document to `val`

func (*DocumentType) SetDeprecated added in v0.39.0

func (t *DocumentType) SetDeprecated(deprecated bool, notice string)

SetDeprecated sets the deprecated field value

func (*DocumentType) SetDescription added in v0.38.0

func (t *DocumentType) SetDescription(desc string)

SetDescription sets the description of the type

func (*DocumentType) SetExamples added in v0.39.0

func (t *DocumentType) SetExamples(data []Example)

SetExamples sets the description and example of the type

func (*DocumentType) SetTitle added in v0.39.0

func (t *DocumentType) SetTitle(title string)

SetTitle sets the title of the type

func (*DocumentType) String added in v0.32.0

func (t *DocumentType) String() string

String produces a user-friendly name of the expected type.

type Example added in v0.39.0

type Example struct {
	// contains filtered or unexported fields
}

Example contains a yaml example and its description

type ExampleAnnotation added in v0.39.0

type ExampleAnnotation struct {
	// contains filtered or unexported fields
}

ExampleAnnotation provides the Examples of a node

func NewExampleAnnotation added in v0.39.0

func NewExampleAnnotation(ann template.NodeAnnotation, pos *filepos.Position) (*ExampleAnnotation, error)

NewExampleAnnotation validates the value(s) from the AnnotationExamples, and returns the value(s)

func (*ExampleAnnotation) GetPosition added in v0.39.0

func (e *ExampleAnnotation) GetPosition() *filepos.Position

GetPosition returns position of the source comment used to create this annotation.

func (*ExampleAnnotation) NewTypeFromAnn added in v0.39.0

func (e *ExampleAnnotation) NewTypeFromAnn() (Type, error)

NewTypeFromAnn returns type information given by annotation.

type MapItemType

type MapItemType struct {
	Key       interface{} // usually a string
	ValueType Type
	Position  *filepos.Position
	// contains filtered or unexported fields
}

func NewMapItemType

func NewMapItemType(item *yamlmeta.MapItem) (*MapItemType, error)

func (*MapItemType) AssignTypeTo

func (t *MapItemType) AssignTypeTo(node yamlmeta.Node) TypeCheck

AssignTypeTo assigns this schema metadata to `node`.

If `node` is not a yamlmeta.MapItem, `chk` contains a violation describing the mismatch If `node`'s value is not of the same structure (i.e. yamlmeta.Node type), `chk` contains a violation describing this mismatch

func (*MapItemType) CheckType

func (t *MapItemType) CheckType(node yamlmeta.Node) TypeCheck

CheckType checks the type of `node` against this MapItemType.

If `node` is not a yamlmeta.MapItem, `chk` contains a violation describing this mismatch If this map item's value is a scalar, checks its type against this MapItemType.ValueType

func (MapItemType) GetDefaultValue added in v0.35.0

func (t MapItemType) GetDefaultValue() interface{}

GetDefaultValue provides the default value

func (MapItemType) GetDefinitionPosition added in v0.35.0

func (t MapItemType) GetDefinitionPosition() *filepos.Position

GetDefinitionPosition reports the location in source schema that contains this type definition.

func (*MapItemType) GetDescription added in v0.38.0

func (t *MapItemType) GetDescription() string

GetDescription provides descriptive information

func (*MapItemType) GetExamples added in v0.39.0

func (t *MapItemType) GetExamples() []Example

GetExamples provides descriptive example information

func (*MapItemType) GetTitle added in v0.39.0

func (t *MapItemType) GetTitle() string

GetTitle provides title information

func (MapItemType) GetValueType

func (t MapItemType) GetValueType() Type

GetValueType provides the type of the value

func (*MapItemType) IsDeprecated added in v0.39.0

func (t *MapItemType) IsDeprecated() (bool, string)

IsDeprecated provides deprecated field information

func (*MapItemType) SetDefaultValue added in v0.38.0

func (t *MapItemType) SetDefaultValue(val interface{})

SetDefaultValue sets the default value to `val`

func (*MapItemType) SetDeprecated added in v0.39.0

func (t *MapItemType) SetDeprecated(deprecated bool, notice string)

SetDeprecated sets the deprecated field value

func (*MapItemType) SetDescription added in v0.38.0

func (t *MapItemType) SetDescription(desc string)

SetDescription sets the description of the type

func (*MapItemType) SetExamples added in v0.39.0

func (t *MapItemType) SetExamples(exs []Example)

SetExamples sets the description and example of the type

func (*MapItemType) SetTitle added in v0.39.0

func (t *MapItemType) SetTitle(title string)

SetTitle sets the title of the type

func (MapItemType) String added in v0.32.0

func (t MapItemType) String() string

String produces a user-friendly name of the expected type.

type MapType

type MapType struct {
	Items    []*MapItemType
	Position *filepos.Position
	// contains filtered or unexported fields
}

func NewMapType

func NewMapType(m *yamlmeta.Map) (*MapType, error)

func (*MapType) AllowedKeys added in v0.38.0

func (m *MapType) AllowedKeys() []string

AllowedKeys returns the set of keys (in string format) permitted in this map.

func (*MapType) AllowsKey

func (m *MapType) AllowsKey(key interface{}) bool

AllowsKey determines whether this MapType permits a MapItem with the key of `key`

func (*MapType) AssignTypeTo

func (m *MapType) AssignTypeTo(node yamlmeta.Node) TypeCheck

AssignTypeTo assigns this schema metadata to `node`.

If `node` is not a yamlmeta.Map, `chk` contains a violation describing the mismatch If `node`'s yamlmeta.MapItem's cannot be assigned their corresponding MapItemType, `chk` contains a violation describing the mismatch If `node` is missing any yamlmeta.MapItem's specified in this MapType, they are added to `node`.

func (*MapType) CheckType

func (m *MapType) CheckType(node yamlmeta.Node) TypeCheck

CheckType checks the type of `node` against this MapType.

If `node` is not a yamlmeta.Map, `chk` contains a violation describing this mismatch If a contained yamlmeta.MapItem is not allowed by this MapType, `chk` contains a corresponding violation

func (MapType) GetDefaultValue added in v0.35.0

func (m MapType) GetDefaultValue() interface{}

GetDefaultValue provides the default value

func (MapType) GetDefinitionPosition added in v0.35.0

func (m MapType) GetDefinitionPosition() *filepos.Position

GetDefinitionPosition reports the location in source schema that contains this type definition.

func (*MapType) GetDescription added in v0.38.0

func (m *MapType) GetDescription() string

GetDescription provides descriptive information

func (*MapType) GetExamples added in v0.39.0

func (m *MapType) GetExamples() []Example

GetExamples provides descriptive example information

func (*MapType) GetTitle added in v0.39.0

func (m *MapType) GetTitle() string

GetTitle provides title information

func (MapType) GetValueType

func (m MapType) GetValueType() Type

GetValueType provides the type of the value

func (*MapType) IsDeprecated added in v0.39.0

func (m *MapType) IsDeprecated() (bool, string)

IsDeprecated provides deprecated field information

func (*MapType) SetDefaultValue added in v0.38.0

func (m *MapType) SetDefaultValue(val interface{})

SetDefaultValue is ignored as default values should be set on each MapItemType, individually.

func (*MapType) SetDeprecated added in v0.39.0

func (m *MapType) SetDeprecated(deprecated bool, notice string)

SetDeprecated sets the deprecated field value

func (*MapType) SetDescription added in v0.38.0

func (m *MapType) SetDescription(desc string)

SetDescription sets the description of the type

func (*MapType) SetExamples added in v0.39.0

func (m *MapType) SetExamples(exs []Example)

SetExamples sets the description and example of the type

func (*MapType) SetTitle added in v0.39.0

func (m *MapType) SetTitle(title string)

SetTitle sets the title of the type

func (MapType) String added in v0.32.0

func (m MapType) String() string

String produces a user-friendly name of the expected type.

type NullType added in v0.34.0

type NullType struct {
	ValueType Type
	Position  *filepos.Position
	// contains filtered or unexported fields
}

func (NullType) AssignTypeTo added in v0.34.0

func (n NullType) AssignTypeTo(node yamlmeta.Node) TypeCheck

AssignTypeTo assigns this NullType's wrapped Type to `node`.

func (NullType) CheckType added in v0.34.0

func (n NullType) CheckType(node yamlmeta.Node) TypeCheck

CheckType checks the type of `node` against this NullType

If `node`'s value is null, this check passes If `node`'s value is not null, then it is checked against this NullType's wrapped Type.

func (NullType) GetDefaultValue added in v0.35.0

func (n NullType) GetDefaultValue() interface{}

GetDefaultValue provides the default value

func (NullType) GetDefinitionPosition added in v0.35.0

func (n NullType) GetDefinitionPosition() *filepos.Position

GetDefinitionPosition reports the location in source schema that contains this type definition.

func (*NullType) GetDescription added in v0.38.0

func (n *NullType) GetDescription() string

GetDescription provides descriptive information

func (*NullType) GetExamples added in v0.39.0

func (n *NullType) GetExamples() []Example

GetExamples provides descriptive example information

func (*NullType) GetTitle added in v0.39.0

func (n *NullType) GetTitle() string

GetTitle provides title information

func (NullType) GetValueType added in v0.34.0

func (n NullType) GetValueType() Type

GetValueType provides the type of the value

func (*NullType) IsDeprecated added in v0.39.0

func (n *NullType) IsDeprecated() (bool, string)

IsDeprecated provides deprecated field information

func (*NullType) SetDefaultValue added in v0.38.0

func (n *NullType) SetDefaultValue(val interface{})

SetDefaultValue sets the default value of the wrapped type to `val`

func (*NullType) SetDeprecated added in v0.39.0

func (n *NullType) SetDeprecated(deprecated bool, notice string)

SetDeprecated sets the deprecated field value

func (*NullType) SetDescription added in v0.38.0

func (n *NullType) SetDescription(desc string)

SetDescription sets the description of the type

func (*NullType) SetExamples added in v0.39.0

func (n *NullType) SetExamples(exs []Example)

SetExamples sets the description and example of the type

func (*NullType) SetTitle added in v0.39.0

func (n *NullType) SetTitle(title string)

SetTitle sets the title of the type

func (NullType) String added in v0.34.0

func (n NullType) String() string

String produces a user-friendly name of the expected type.

type NullableAnnotation added in v0.34.0

type NullableAnnotation struct {
	// contains filtered or unexported fields
}

func NewNullableAnnotation added in v0.34.0

func NewNullableAnnotation(ann template.NodeAnnotation, node yamlmeta.Node) (*NullableAnnotation, error)

NewNullableAnnotation checks that there are no arguments, and returns wrapper for the annotated node.

func (*NullableAnnotation) GetPosition added in v0.39.0

func (n *NullableAnnotation) GetPosition() *filepos.Position

GetPosition returns position of the source comment used to create this annotation.

func (*NullableAnnotation) NewTypeFromAnn added in v0.34.0

func (n *NullableAnnotation) NewTypeFromAnn() (Type, error)

NewTypeFromAnn returns type information given by annotation.

type OpenAPIDocument added in v0.38.0

type OpenAPIDocument struct {
	// contains filtered or unexported fields
}

OpenAPIDocument holds the document type used for creating an OpenAPI document

func NewOpenAPIDocument added in v0.38.0

func NewOpenAPIDocument(docType *DocumentType) *OpenAPIDocument

NewOpenAPIDocument creates an instance of an OpenAPIDocument based on the given DocumentType

func (*OpenAPIDocument) AsDocument added in v0.38.0

func (o *OpenAPIDocument) AsDocument() *yamlmeta.Document

AsDocument generates a new AST of this OpenAPI v3.0.x document, populating the `schemas:` section with the type information contained in `docType`.

type ScalarType

type ScalarType struct {
	ValueType interface{}
	Position  *filepos.Position
	// contains filtered or unexported fields
}

func (*ScalarType) AssignTypeTo

func (s *ScalarType) AssignTypeTo(node yamlmeta.Node) TypeCheck

AssignTypeTo returns a violation describing the type mismatch, given that ScalarType will never accept a yamlmeta.Node

func (*ScalarType) CheckType

func (s *ScalarType) CheckType(node yamlmeta.Node) TypeCheck

CheckType checks the type of `node`'s `value`, which is expected to be a scalar type.

If the value is not a recognized scalar type, `chk` contains a corresponding violation If the value is not of the type specified in this ScalarType, `chk` contains a violation describing the mismatch

func (ScalarType) GetDefaultValue added in v0.35.0

func (s ScalarType) GetDefaultValue() interface{}

GetDefaultValue provides the default value

func (ScalarType) GetDefinitionPosition added in v0.35.0

func (s ScalarType) GetDefinitionPosition() *filepos.Position

GetDefinitionPosition reports the location in source schema that contains this type definition.

func (*ScalarType) GetDescription added in v0.38.0

func (s *ScalarType) GetDescription() string

GetDescription provides descriptive information

func (*ScalarType) GetExamples added in v0.39.0

func (s *ScalarType) GetExamples() []Example

GetExamples provides descriptive example information

func (*ScalarType) GetTitle added in v0.39.0

func (s *ScalarType) GetTitle() string

GetTitle provides title information

func (ScalarType) GetValueType

func (s ScalarType) GetValueType() Type

GetValueType provides the type of the value

func (*ScalarType) IsDeprecated added in v0.39.0

func (s *ScalarType) IsDeprecated() (bool, string)

IsDeprecated provides deprecated field information

func (*ScalarType) SetDefaultValue added in v0.38.0

func (s *ScalarType) SetDefaultValue(val interface{})

SetDefaultValue sets the default value to `val`

func (*ScalarType) SetDeprecated added in v0.39.0

func (s *ScalarType) SetDeprecated(deprecated bool, notice string)

SetDeprecated sets the deprecated field value

func (*ScalarType) SetDescription added in v0.38.0

func (s *ScalarType) SetDescription(desc string)

SetDescription sets the description of the type

func (*ScalarType) SetExamples added in v0.39.0

func (s *ScalarType) SetExamples(exs []Example)

SetExamples sets the description and example of the type

func (*ScalarType) SetTitle added in v0.39.0

func (s *ScalarType) SetTitle(title string)

SetTitle sets the title of the type

func (ScalarType) String added in v0.32.0

func (s ScalarType) String() string

String produces a user-friendly name of the expected type.

type TitleAnnotation added in v0.39.0

type TitleAnnotation struct {
	// contains filtered or unexported fields
}

TitleAnnotation provides title of a node

func NewTitleAnnotation added in v0.39.0

func NewTitleAnnotation(ann template.NodeAnnotation, pos *filepos.Position) (*TitleAnnotation, error)

NewTitleAnnotation validates the value from the AnnotationTitle, and returns the value

func (*TitleAnnotation) GetPosition added in v0.39.0

func (t *TitleAnnotation) GetPosition() *filepos.Position

GetPosition returns position of the source comment used to create this annotation.

func (*TitleAnnotation) NewTypeFromAnn added in v0.39.0

func (t *TitleAnnotation) NewTypeFromAnn() (Type, error)

NewTypeFromAnn returns type information given by annotation. TitleAnnotation has no type information.

type Type added in v0.39.0

type Type interface {
	AssignTypeTo(node yamlmeta.Node) TypeCheck
	CheckType(node yamlmeta.Node) TypeCheck

	GetValueType() Type
	GetDefaultValue() interface{}
	SetDefaultValue(interface{})
	GetDefinitionPosition() *filepos.Position

	GetDescription() string
	SetDescription(string)
	GetTitle() string
	SetTitle(string)
	GetExamples() []Example
	SetExamples([]Example)
	IsDeprecated() (bool, string)
	SetDeprecated(bool, string)
	String() string
}

Type encapsulates a schema that describes a yamlmeta.Node.

func GetType added in v0.39.0

func GetType(n yamlmeta.Node) Type

GetType retrieves schema metadata from `n`, set previously via SetType().

func InferTypeFromValue added in v0.39.0

func InferTypeFromValue(value interface{}, position *filepos.Position) (Type, error)

InferTypeFromValue detects and constructs an instance of the Type of `value`.

type TypeAnnotation added in v0.34.0

type TypeAnnotation struct {
	// contains filtered or unexported fields
}

func NewTypeAnnotation added in v0.34.0

func NewTypeAnnotation(ann template.NodeAnnotation, node yamlmeta.Node) (*TypeAnnotation, error)

NewTypeAnnotation checks the keyword argument provided via @schema/type annotation, and returns wrapper for the annotated node.

func (*TypeAnnotation) GetPosition added in v0.39.0

func (t *TypeAnnotation) GetPosition() *filepos.Position

GetPosition returns position of the source comment used to create this annotation.

func (*TypeAnnotation) IsAny added in v0.34.0

func (t *TypeAnnotation) IsAny() bool

func (*TypeAnnotation) NewTypeFromAnn added in v0.34.0

func (t *TypeAnnotation) NewTypeFromAnn() (Type, error)

NewTypeFromAnn returns type information given by annotation.

type TypeCheck added in v0.39.0

type TypeCheck struct {
	Violations []error
}

TypeCheck is the result of checking a yamlmeta.Node structure against a given Type, recursively.

func CheckNode added in v0.39.0

func CheckNode(n yamlmeta.Node) TypeCheck

CheckNode attempts type check of root node and its children.

If `n` has "schema/type" metadata (typically attached using SetType()), `n` is checked against that schema, recursively. `chk` contains all the type violations found in the check.

func (TypeCheck) Error added in v0.39.0

func (tc TypeCheck) Error() string

Error generates the error message composed of the total set of TypeCheck.Violations.

func (*TypeCheck) HasViolations added in v0.39.0

func (tc *TypeCheck) HasViolations() bool

HasViolations indicates whether this TypeCheck contains any violations.

Jump to

Keyboard shortcuts

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