schema

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package schema defines the types that are used to represent schemas for validation and auto-complete.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Any

type Any struct{}

Any represents an unknown type that can be satisfied by any value.

func (Any) ConstraintType

func (ae Any) ConstraintType() (cty.Type, bool)

func (Any) Copy

func (ae Any) Copy() Constraint

func (Any) EmptyCompletionData

func (ae Any) EmptyCompletionData(nextPlaceholder int, nestingLevel int) CompletionData

func (Any) FriendlyName

func (ae Any) FriendlyName() string

type AttributeSchema

type AttributeSchema struct {
	Description lang.MarkupContent
	IsRequired  bool
	IsOptional  bool
	// Constraint represents expression constraint e.g. what types of
	// expressions are expected for the attribute
	//
	// Constraints are immutable after construction by convention. It is
	// particularly important not to mutate a constraint after it has been
	// added to an AttributeSchema.
	Constraint Constraint
	// CompletionHooks represent any hooks which provide
	// additional completion candidates for the attribute.
	// These are typically candidates which cannot be provided
	// via schema and come from external APIs or other sources.
	CompletionHooks lang.CompletionHooks
}

AttributeSchema describes schema for an attribute

func (*AttributeSchema) Copy

func (as *AttributeSchema) Copy() *AttributeSchema

func (*AttributeSchema) Validate

func (as *AttributeSchema) Validate() error

type BasicBlockSchema

type BasicBlockSchema struct {
	Description   lang.MarkupContent
	Labels        []*LabelSchema
	AllowMultiple bool
}

BasicBlockSchema provides a block description and associated label schemas.

func (*BasicBlockSchema) Copy

type BlockStack

type BlockStack interface {
	Push(*hclsyntax.Block)
	Peek(n int) *hclsyntax.Block
	Pop()
	HasAncestorOfType(t string) bool
}

BlockStack provides a mechanism to track the current block structure that is seen in LIFO manner. Peek and Pop never panic and always return an empty block for out of bounds calls.

func NewBlockStack

func NewBlockStack() BlockStack

type BodySchema

type BodySchema struct {
	Description  lang.MarkupContent
	Attributes   map[string]*AttributeSchema
	NestedBlocks map[string]*BasicBlockSchema
}

BodySchema describes the schema for a block

func (*BodySchema) Copy

func (bs *BodySchema) Copy() *BodySchema

type Bool

type Bool struct{}

Bool represents a boolean type.

func (Bool) ConstraintType

func (b Bool) ConstraintType() (cty.Type, bool)

func (Bool) Copy

func (b Bool) Copy() Constraint

func (Bool) EmptyCompletionData

func (b Bool) EmptyCompletionData(nextPlaceholder int, nestingLevel int) CompletionData

func (Bool) FriendlyName

func (b Bool) FriendlyName() string

type CompletionData

type CompletionData struct {
	NewText string
	// Snippet represents text to be inserted via text edits,
	// with snippet placeholder identifiers such as ${1} (if any) starting
	// from given nextPlaceholder (provided as arg to EmptyCompletionData).
	Snippet         string
	TriggerSuggest  bool
	NextPlaceholder int
}

type Constraint

type Constraint interface {
	FriendlyName() string
	Copy() Constraint
	// EmptyCompletionData provides completion data in context where
	// there is no corresponding configuration, such as when the Constraint
	// is part of another, and it is desirable to complete
	// the parent constraint as whole.
	EmptyCompletionData(nextPlaceholder int, nestingLevel int) CompletionData
	// contains filtered or unexported methods
}

type FunctionSignature

type FunctionSignature struct {
	// Description is an optional human-readable description
	// of the function.
	Description string
	// Detail is additional detail that can be used in hover descriptions.
	Detail string
	// ReturnType is the ctyjson representation of the function's
	// return types based on supplying all parameters using
	// dynamic types. Functions can have dynamic return types.
	ReturnType cty.Type
	// Params describes the function's fixed positional parameters.
	Params []function.Parameter
	// VarParam describes the function's variadic
	// parameter if it is supported.
	VarParam *function.Parameter
}

func (*FunctionSignature) Copy

type HoverData

type HoverData struct {
	Content lang.MarkupContent
}

type LabelSchema

type LabelSchema struct {
	Name          string
	Description   lang.MarkupContent
	AllowedValues []string
}

LabelSchema describes schema for a label on a particular position

func (*LabelSchema) CanComplete

func (ls *LabelSchema) CanComplete() bool

func (*LabelSchema) Copy

func (ls *LabelSchema) Copy() *LabelSchema

type List

type List struct {
	// Elem defines constraint to apply to each item
	Elem Constraint
	// Description defines description of the whole list (affects hover)
	Description lang.MarkupContent
	// MinItems defines minimum number of items (affects completion)
	MinItems uint64
	// MaxItems defines maximum number of items (affects completion)
	MaxItems uint64
}

List represents a list, equivalent of a TupleConsExpr interpreted as list, i.e. ordering of item (which are all the same type) matters.

func (List) ConstraintType

func (l List) ConstraintType() (cty.Type, bool)

func (List) Copy

func (l List) Copy() Constraint

func (List) EmptyCompletionData

func (l List) EmptyCompletionData(nextPlaceholder int, nestingLevel int) CompletionData

func (List) FriendlyName

func (l List) FriendlyName() string

type LiteralType

type LiteralType struct {
	Type cty.Type
}

LiteralType represents literal type constraint e.g. any literal string ("foo"), number (42), etc.

Non-literal expressions (even if these evaluate to the given type) are excluded.

Complex types are supported, but dedicated List, Set, Map and other types are preferred, as these can convey more details, such as description, unlike e.g. LiteralType{Type: cty.List(...)}.

func (LiteralType) ConstraintType

func (lt LiteralType) ConstraintType() (cty.Type, bool)

func (LiteralType) Copy

func (lt LiteralType) Copy() Constraint

func (LiteralType) EmptyCompletionData

func (lt LiteralType) EmptyCompletionData(nextPlaceholder int, nestingLevel int) CompletionData

func (LiteralType) FriendlyName

func (lt LiteralType) FriendlyName() string

func (LiteralType) Validate

func (lt LiteralType) Validate() error

type Lookup

type Lookup interface {
	// BodySchema returns the body schema at the current block position.
	BodySchema(bs BlockStack) *BodySchema
	// LabelSchema returns the label schema at the current block position.
	LabelSchema(bs BlockStack) []*LabelSchema
	// AttributeSchema returns the attribute schema at the current block and attribute position.
	AttributeSchema(bs BlockStack, attrName string) *AttributeSchema
	// Functions returns available function signatures keyed by function name.
	Functions() map[string]FunctionSignature
	// ImpliedAttributeSchema returns a computed schema implied by the attribute expression.
	// This is typically called when hovering over the name of an attribute.
	ImpliedAttributeSchema(bs BlockStack, attrName string) *AttributeSchema
}

Lookup provides a mechanism to provide just-in-time schema information for an entity at a specific position.

type Map

type Map struct {
	// Elem defines constraint to apply to each item of the map
	Elem Constraint

	// Name overrides friendly name of the constraint
	Name string

	// Description defines description of the whole map (affects hover)
	Description lang.MarkupContent

	// MinItems defines minimum number of items (affects completion)
	MinItems uint64

	// MaxItems defines maximum number of items (affects completion)
	MaxItems uint64

	// AllowInterpolatedKeys determines whether the key names can be
	// interpolated (true) or static (literal strings only).
	AllowInterpolatedKeys bool
}

Map represents a map, equivalent of hclsyntax.ObjectConsExpr interpreted as map, i.e. with items of unknown keys and same value types.

func (Map) ConstraintType

func (m Map) ConstraintType() (cty.Type, bool)

func (Map) Copy

func (m Map) Copy() Constraint

func (Map) EmptyCompletionData

func (m Map) EmptyCompletionData(nextPlaceholder int, nestingLevel int) CompletionData

func (Map) FriendlyName

func (m Map) FriendlyName() string

type Number

type Number struct{}

Number represents a number type.

func (Number) ConstraintType

func (n Number) ConstraintType() (cty.Type, bool)

func (Number) Copy

func (n Number) Copy() Constraint

func (Number) EmptyCompletionData

func (n Number) EmptyCompletionData(nextPlaceholder int, nestingLevel int) CompletionData

func (Number) FriendlyName

func (n Number) FriendlyName() string

type Object

type Object struct {
	Name                  string             // overrides friendly name of the constraint
	Attributes            ObjectAttributes   // names and constraints of attributes within the object
	Description           lang.MarkupContent //  description of the whole object (affects hover)
	AllowInterpolatedKeys bool               // determines whether the attribute names can be interpolated
	AnyAttribute          Constraint         // determines if we allow unknown attributes of this type
	PrefillRequiredKeys   bool               // prefill any required keys for the object
}

Object represents an object, equivalent of hclsyntax.ObjectConsExpr interpreted as object, i.e. with items of known keys and different value types.

func (Object) ConstraintType

func (o Object) ConstraintType() (cty.Type, bool)

func (Object) Copy

func (o Object) Copy() Constraint

func (Object) EmptyCompletionData

func (o Object) EmptyCompletionData(placeholder int, nestingLevel int) CompletionData

func (Object) FriendlyName

func (o Object) FriendlyName() string

type ObjectAttributes

type ObjectAttributes map[string]*AttributeSchema

func (ObjectAttributes) Copy

type Set

type Set struct {
	// Elem defines constraint to apply to each item
	Elem Constraint
	// Description defines description of the whole list (affects hover)
	Description lang.MarkupContent
	// MinItems defines minimum number of items (affects completion)
	MinItems uint64
	// MaxItems defines maximum number of items (affects completion)
	MaxItems uint64
}

Set represents a set, equivalent of hclsyntax.TupleConsExpr interpreted as set, i.e. ordering of items (which are of the same type) does not matter.

func (Set) ConstraintType

func (s Set) ConstraintType() (cty.Type, bool)

func (Set) Copy

func (s Set) Copy() Constraint

func (Set) EmptyCompletionData

func (s Set) EmptyCompletionData(nextPlaceholder int, nestingLevel int) CompletionData

func (Set) FriendlyName

func (s Set) FriendlyName() string

type String

type String struct{}

String represents a string type.

func (String) ConstraintType

func (s String) ConstraintType() (cty.Type, bool)

func (String) Copy

func (s String) Copy() Constraint

func (String) EmptyCompletionData

func (s String) EmptyCompletionData(nextPlaceholder int, nestingLevel int) CompletionData

func (String) FriendlyName

func (s String) FriendlyName() string

type TypeAwareConstraint

type TypeAwareConstraint interface {
	ConstraintType() (cty.Type, bool)
}

TypeAwareConstraint represents a constraint which may be type-aware. Most constraints which implement this are always type-aware, but for some this is runtime concern depending on the configuration.

This makes it comparable to another type for conformity during completion, and enables collection of type-aware reference target, if the attribute itself is targetable as type-aware.

type TypeDeclaration

type TypeDeclaration struct {
}

TypeDeclaration represents a type declaration as interpreted by HCL's ext/typeexpr package, i.e. declaration of cty.Type in HCL

func (TypeDeclaration) Copy

func (td TypeDeclaration) Copy() Constraint

func (TypeDeclaration) EmptyCompletionData

func (td TypeDeclaration) EmptyCompletionData(nextPlaceholder int, nestingLevel int) CompletionData

func (TypeDeclaration) FriendlyName

func (td TypeDeclaration) FriendlyName() string

type Validatable

type Validatable interface {
	Validate() error
}

Jump to

Keyboard shortcuts

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