schema

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package schema provides validation for the loaded tests description and documentation generation leveraging JSON schemas.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Validate

func Validate(obj any) error

Validate validates the provided object against the schema.

Types

type EnumRequirement

type EnumRequirement struct {
	// PathSegments is the list of enum path segments.
	PathSegments []string
	// Value is the enum value.
	Value string
}

EnumRequirement specifies an enumerated value in the node tree and the corresponding value to set.

type Node

type Node struct {
	// Name is the name of the node.
	Name string `yaml:"name"`
	// Descriptions is the list of node's descriptions. A node can have multiple descriptions if it is the result of the
	// merging of multiple nodes. The list does not contain duplicates.
	Descriptions []string `yaml:"descriptions,omitempty"`
	// JSONTypes is the node's optional list of JSON types.
	JSONTypes []string `yaml:"types,omitempty"`
	// Required is true if the user is required to provide the current node in order to completely describe the
	// containing node.
	Required bool `yaml:"required,omitempty"`
	// Minimum is the minimum supported integer value (it can be different from nil only if JSONTypes contains the
	// integer type).
	Minimum *float64 `yaml:"minimum,omitempty"`
	// MinLength is the minimum string value length (it can be different from nil only if JSONTypes contains the string
	// type).
	MinLength *int `yaml:"minLength,omitempty"`
	// MinItems is the minimum number of node items (it can be different from nil only if JSONTypes contains the array
	// type).
	MinItems *int `yaml:"minItems,omitempty"`
	// MinProperties is the minimum number of properties the node can contain (it can be different from nil only if
	// JSONTypes contains the object type).
	MinProperties *int `yaml:"minProperties,omitempty"`
	// Pattern is the regular expression the node is constrained to adhere (it can be different from nil only if
	// JSONTypes contains the string type).
	Pattern *string `yaml:"pattern,omitempty"`
	// Default is the node's optional default value.
	Default *any `yaml:"default,omitempty"`
	// Examples is the node's optional list of examples.
	Examples []any `yaml:"examples,omitempty"`
	// Enum is the node's optional list of enumerated values that are allowed to be set as node's value. It is only
	// populated if the node represents an enumerated value.
	Enum []any `yaml:"enum,omitempty"`
	// Children is the node's optional list of child nodes (a.k.a node's fields).
	Children []*Node `yaml:"fields,omitempty"`
	// PseudoChildren is the node's optional list of pseudo child nodes (a.k.a node's exposed fields).
	PseudoChildren []*Node `yaml:"exposedFields,omitempty"`
	// Pseudo is true if the node is "pseudo" node. In the context of a node tree, a pseudo node is a node not present
	// in the original schema: it is added to augment the schema with additional information, such as node's additional
	// exposed fields.
	Pseudo bool `yaml:"-"`
	// Metadata are the node's metadata.
	Metadata *NodeMetadata `yaml:",inline"`
}

A Node represents a single schema element.

func Describe

func Describe(nodePath []string, requirements []*EnumRequirement) (*Node, error)

Describe returns a node tree describing the fields along the path described by the provided node path. The provided requirements are used to set values for nodes representing enumerated values (this can be used to "unlock" node tree paths enabled only if specific values are provided for the aforementioned nodes).

type NodeMetadata

type NodeMetadata struct {
	Type       string `yaml:"fieldType,omitempty"`
	IsBindOnly bool   `yaml:"isBindOnly,omitempty"`
}

NodeMetadata contains node metadata.

Jump to

Keyboard shortcuts

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