schema

package
v0.49.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package schema enhances yamlmeta.Node structures with fine-grain data types.

Type and Checking

Within a schema document (which itself is a yamlmeta.Document), type metadata is attached to nodes via @schema/... annotations. Those annotations are parsed and digested into a composite tree of schema.Type.

With such a schema.Type hierarchy in hand, other YAML documents can be "typed" (via Type.AssignTypeTo()). This process walks the target yamlmeta.Document and attaches the corresponding type as metadata on each corresponding yamlmeta.Node.

"Typed" documents can then be "checked" (via schema.CheckNode()) to determine if their fine-grain types conform to the assigned schema.

Documenting

Other @schema/... annotations are used to describe the exact syntax and semantic of values.

Other Schema Formats

Like other Carvel tools, ytt aims to interoperate well with other tooling. In this vein, ytt can export schema defined within ytt as an OpenAPI v3 document.

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"
	AnnotationValidation   template.AnnotationName = "schema/validation"
)

Declare @schema/... annotation names

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

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

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

func NewSchemaError

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

func NewUnexpectedKeyAssertionError

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

func SetType(n yamlmeta.Node, t Type)

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

Types

type Annotation

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

type AnyType

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

func (AnyType) AssignTypeTo

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

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

func (AnyType) CheckType

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

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

Always returns an empty TypeCheck.

func (AnyType) GetDefaultValue

func (a AnyType) GetDefaultValue() interface{}

GetDefaultValue provides the default value

func (AnyType) GetDefinitionPosition

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

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

func (*AnyType) GetDescription

func (a *AnyType) GetDescription() string

GetDescription provides descriptive information

func (*AnyType) GetExamples

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

GetExamples provides descriptive example information

func (*AnyType) GetTitle

func (a *AnyType) GetTitle() string

GetTitle provides title information

func (AnyType) GetValidation

func (a AnyType) GetValidation() *validations.NodeValidation

GetValidation provides the validation from @schema/validation for a node

func (AnyType) GetValueType

func (a AnyType) GetValueType() Type

GetValueType provides the type of the value

func (*AnyType) IsDeprecated

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

IsDeprecated provides deprecated field information

func (*AnyType) SetDefaultValue

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

SetDefaultValue does nothing

func (*AnyType) SetDeprecated

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

SetDeprecated sets the deprecated field value

func (*AnyType) SetDescription

func (a *AnyType) SetDescription(desc string)

SetDescription sets the description of the type

func (*AnyType) SetExamples

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

SetExamples sets the description and example of the type

func (*AnyType) SetTitle

func (a *AnyType) SetTitle(title string)

SetTitle sets the title of the type

func (AnyType) String

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

func (a ArrayItemType) GetDefaultValue() interface{}

GetDefaultValue provides the default value

func (ArrayItemType) GetDefinitionPosition

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

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

func (*ArrayItemType) GetDescription

func (a *ArrayItemType) GetDescription() string

GetDescription provides descriptive information

func (*ArrayItemType) GetExamples

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

GetExamples provides descriptive example information

func (*ArrayItemType) GetTitle

func (a *ArrayItemType) GetTitle() string

GetTitle provides title information

func (*ArrayItemType) GetValidation

func (a *ArrayItemType) GetValidation() *validations.NodeValidation

GetValidation provides the validation from @schema/validation for a node

func (ArrayItemType) GetValueType

func (a ArrayItemType) GetValueType() Type

GetValueType provides the type of the value

func (*ArrayItemType) IsDeprecated

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

IsDeprecated provides deprecated field information

func (*ArrayItemType) SetDefaultValue

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

SetDefaultValue sets the default value to `val`

func (*ArrayItemType) SetDeprecated

func (a *ArrayItemType) SetDeprecated(_ bool, _ string)

SetDeprecated sets the deprecated field value

func (*ArrayItemType) SetDescription

func (a *ArrayItemType) SetDescription(_ string)

SetDescription sets the description of the type

func (*ArrayItemType) SetExamples

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

SetExamples sets the description and example of the type

func (*ArrayItemType) SetTitle

func (a *ArrayItemType) SetTitle(_ string)

SetTitle sets the title of the type

func (ArrayItemType) String

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

func (a ArrayType) GetDefaultValue() interface{}

GetDefaultValue provides the default value

func (ArrayType) GetDefinitionPosition

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

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

func (*ArrayType) GetDescription

func (a *ArrayType) GetDescription() string

GetDescription provides descriptive information

func (*ArrayType) GetExamples

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

GetExamples provides descriptive example information

func (*ArrayType) GetTitle

func (a *ArrayType) GetTitle() string

GetTitle provides title information

func (*ArrayType) GetValidation

func (a *ArrayType) GetValidation() *validations.NodeValidation

GetValidation provides the validation from @schema/validation for a node

func (ArrayType) GetValueType

func (a ArrayType) GetValueType() Type

GetValueType provides the type of the value

func (*ArrayType) IsDeprecated

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

IsDeprecated provides deprecated field information

func (*ArrayType) SetDefaultValue

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

SetDefaultValue sets the default value to `val`

func (*ArrayType) SetDeprecated

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

SetDeprecated sets the deprecated field value

func (*ArrayType) SetDescription

func (a *ArrayType) SetDescription(desc string)

SetDescription sets the description of the type

func (*ArrayType) SetExamples

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

SetExamples sets the description and example of the type

func (*ArrayType) SetTitle

func (a *ArrayType) SetTitle(title string)

SetTitle sets the title of the type

func (ArrayType) String

func (a ArrayType) String() string

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

type AssignSchemaValidations

type AssignSchemaValidations struct{}

AssignSchemaValidations implements the visitor interface to set validations from the schema type

func (AssignSchemaValidations) Visit

Visit Extracts the validations from Node's Type and sets them in Node's meta This visitor returns nil if node has no assigned type or when the execution is completed

type DefaultAnnotation

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

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

func NewDefaultAnnotation

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

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

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

func (*DefaultAnnotation) NewTypeFromAnn

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

NewTypeFromAnn returns type information given by annotation.

func (*DefaultAnnotation) Val

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

Val returns default value specified in annotation.

type DeprecatedAnnotation

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

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

func NewDeprecatedAnnotation

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

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

func (*DeprecatedAnnotation) GetPosition

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

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

func (*DeprecatedAnnotation) NewTypeFromAnn

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

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

type DescriptionAnnotation

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

DescriptionAnnotation documents the purpose of a node

func NewDescriptionAnnotation

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

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

func (*DescriptionAnnotation) GetPosition

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

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

func (*DescriptionAnnotation) NewTypeFromAnn

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

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

func (t DocumentType) GetDefaultValue() interface{}

GetDefaultValue provides the default value

func (*DocumentType) GetDefinitionPosition

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

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

func (*DocumentType) GetDescription

func (t *DocumentType) GetDescription() string

GetDescription provides descriptive information

func (*DocumentType) GetExamples

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

GetExamples provides descriptive example information

func (*DocumentType) GetTitle

func (t *DocumentType) GetTitle() string

GetTitle provides title information

func (*DocumentType) GetValidation

func (t *DocumentType) GetValidation() *validations.NodeValidation

GetValidation provides the validation from @schema/validation for a node

func (*DocumentType) GetValueType

func (t *DocumentType) GetValueType() Type

GetValueType provides the type of the value

func (*DocumentType) IsDeprecated

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

IsDeprecated provides deprecated field information

func (*DocumentType) SetDefaultValue

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

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

func (*DocumentType) SetDeprecated

func (t *DocumentType) SetDeprecated(_ bool, _ string)

SetDeprecated sets the deprecated field value

func (*DocumentType) SetDescription

func (t *DocumentType) SetDescription(_ string)

SetDescription sets the description of the type

func (*DocumentType) SetExamples

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

SetExamples sets the description and example of the type

func (*DocumentType) SetTitle

func (t *DocumentType) SetTitle(_ string)

SetTitle sets the title of the type

func (*DocumentType) String

func (t *DocumentType) String() string

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

type Example

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

Example contains a yaml example and its description

type ExampleAnnotation

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

ExampleAnnotation provides the Examples of a node

func NewExampleAnnotation

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

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

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

func (*ExampleAnnotation) NewTypeFromAnn

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

func (t MapItemType) GetDefaultValue() interface{}

GetDefaultValue provides the default value

func (MapItemType) GetDefinitionPosition

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

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

func (*MapItemType) GetDescription

func (t *MapItemType) GetDescription() string

GetDescription provides descriptive information

func (*MapItemType) GetExamples

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

GetExamples provides descriptive example information

func (*MapItemType) GetTitle

func (t *MapItemType) GetTitle() string

GetTitle provides title information

func (*MapItemType) GetValidation

func (t *MapItemType) GetValidation() *validations.NodeValidation

GetValidation provides the validation from @schema/validation for a node

func (MapItemType) GetValueType

func (t MapItemType) GetValueType() Type

GetValueType provides the type of the value

func (*MapItemType) IsDeprecated

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

IsDeprecated provides deprecated field information

func (*MapItemType) SetDefaultValue

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

SetDefaultValue sets the default value to `val`

func (*MapItemType) SetDeprecated

func (t *MapItemType) SetDeprecated(_ bool, _ string)

SetDeprecated sets the deprecated field value

func (*MapItemType) SetDescription

func (t *MapItemType) SetDescription(_ string)

SetDescription sets the description of the type

func (*MapItemType) SetExamples

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

SetExamples sets the description and example of the type

func (*MapItemType) SetTitle

func (t *MapItemType) SetTitle(_ string)

SetTitle sets the title of the type

func (MapItemType) String

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

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

func (m MapType) GetDefaultValue() interface{}

GetDefaultValue provides the default value

func (MapType) GetDefinitionPosition

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

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

func (*MapType) GetDescription

func (m *MapType) GetDescription() string

GetDescription provides descriptive information

func (*MapType) GetExamples

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

GetExamples provides descriptive example information

func (*MapType) GetTitle

func (m *MapType) GetTitle() string

GetTitle provides title information

func (*MapType) GetValidation

func (m *MapType) GetValidation() *validations.NodeValidation

GetValidation provides the validation from @schema/validation for a node

func (MapType) GetValueType

func (m MapType) GetValueType() Type

GetValueType provides the type of the value

func (*MapType) IsDeprecated

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

IsDeprecated provides deprecated field information

func (*MapType) SetDefaultValue

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

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

func (*MapType) SetDeprecated

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

SetDeprecated sets the deprecated field value

func (*MapType) SetDescription

func (m *MapType) SetDescription(desc string)

SetDescription sets the description of the type

func (*MapType) SetExamples

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

SetExamples sets the description and example of the type

func (*MapType) SetTitle

func (m *MapType) SetTitle(title string)

SetTitle sets the title of the type

func (MapType) String

func (m MapType) String() string

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

type NullType

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

func (NullType) AssignTypeTo

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

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

func (NullType) CheckType

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

func (n NullType) GetDefaultValue() interface{}

GetDefaultValue provides the default value

func (NullType) GetDefinitionPosition

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

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

func (*NullType) GetDescription

func (n *NullType) GetDescription() string

GetDescription provides descriptive information

func (*NullType) GetExamples

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

GetExamples provides descriptive example information

func (*NullType) GetTitle

func (n *NullType) GetTitle() string

GetTitle provides title information

func (NullType) GetValidation

func (n NullType) GetValidation() *validations.NodeValidation

GetValidation provides the validation from @schema/validation for a node

func (NullType) GetValueType

func (n NullType) GetValueType() Type

GetValueType provides the type of the value

func (*NullType) IsDeprecated

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

IsDeprecated provides deprecated field information

func (*NullType) SetDefaultValue

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

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

func (*NullType) SetDeprecated

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

SetDeprecated sets the deprecated field value

func (*NullType) SetDescription

func (n *NullType) SetDescription(desc string)

SetDescription sets the description of the type

func (*NullType) SetExamples

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

SetExamples sets the description and example of the type

func (*NullType) SetTitle

func (n *NullType) SetTitle(title string)

SetTitle sets the title of the type

func (NullType) String

func (n NullType) String() string

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

type NullableAnnotation

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

func NewNullableAnnotation

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

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

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

func (*NullableAnnotation) NewTypeFromAnn

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

NewTypeFromAnn returns type information given by annotation.

type OpenAPIDocument

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

OpenAPIDocument holds the document type used for creating an OpenAPI document

func NewOpenAPIDocument

func NewOpenAPIDocument(docType *DocumentType) *OpenAPIDocument

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

func (*OpenAPIDocument) AsDocument

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

func (s ScalarType) GetDefaultValue() interface{}

GetDefaultValue provides the default value

func (ScalarType) GetDefinitionPosition

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

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

func (*ScalarType) GetDescription

func (s *ScalarType) GetDescription() string

GetDescription provides descriptive information

func (*ScalarType) GetExamples

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

GetExamples provides descriptive example information

func (*ScalarType) GetTitle

func (s *ScalarType) GetTitle() string

GetTitle provides title information

func (*ScalarType) GetValidation

func (s *ScalarType) GetValidation() *validations.NodeValidation

GetValidation provides the validation from @schema/validation for a node

func (ScalarType) GetValueType

func (s ScalarType) GetValueType() Type

GetValueType provides the type of the value

func (*ScalarType) IsDeprecated

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

IsDeprecated provides deprecated field information

func (*ScalarType) SetDefaultValue

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

SetDefaultValue sets the default value to `val`

func (*ScalarType) SetDeprecated

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

SetDeprecated sets the deprecated field value

func (*ScalarType) SetDescription

func (s *ScalarType) SetDescription(desc string)

SetDescription sets the description of the type

func (*ScalarType) SetExamples

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

SetExamples sets the description and example of the type

func (*ScalarType) SetTitle

func (s *ScalarType) SetTitle(title string)

SetTitle sets the title of the type

func (ScalarType) String

func (s ScalarType) String() string

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

type TitleAnnotation

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

TitleAnnotation provides title of a node

func NewTitleAnnotation

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

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

func (*TitleAnnotation) GetPosition

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

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

func (*TitleAnnotation) NewTypeFromAnn

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

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

type Type

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)
	GetValidation() *validations.NodeValidation
	String() string
}

Type encapsulates a schema that describes a yamlmeta.Node.

func GetType

func GetType(n yamlmeta.Node) Type

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

func InferTypeFromValue

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

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

type TypeAnnotation

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

func NewTypeAnnotation

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

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

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

func (*TypeAnnotation) IsAny

func (t *TypeAnnotation) IsAny() bool

func (*TypeAnnotation) NewTypeFromAnn

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

NewTypeFromAnn returns type information given by annotation.

type TypeCheck

type TypeCheck struct {
	Violations []error
}

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

func CheckNode

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

func (tc TypeCheck) Error() string

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

func (*TypeCheck) HasViolations

func (tc *TypeCheck) HasViolations() bool

HasViolations indicates whether this TypeCheck contains any violations.

type ValidationAnnotation

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

ValidationAnnotation is a wrapper for validations provided via @schema/validation annotation

func NewValidationAnnotation

func NewValidationAnnotation(ann template.NodeAnnotation) (*ValidationAnnotation, error)

NewValidationAnnotation checks the values provided via @schema/validation annotation, and returns wrapper for the validation defined

func (*ValidationAnnotation) GetPosition

func (v *ValidationAnnotation) GetPosition() *filepos.Position

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

func (*ValidationAnnotation) GetValidation

func (v *ValidationAnnotation) GetValidation() *validations.NodeValidation

GetValidation gets the NodeValidation created from @schema/validation annotation

func (*ValidationAnnotation) NewTypeFromAnn

func (v *ValidationAnnotation) NewTypeFromAnn() (Type, error)

NewTypeFromAnn returns type information given by annotation.

Jump to

Keyboard shortcuts

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