validation

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InvalidGroupPrefix = "invalid:"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Index    *int
	Group    string
	Version  string
	Kind     string
	Name     string
	Messages []string
}

type ErrorKind

type ErrorKind int
const (
	ErrKindChangesValidationFailed ErrorKind = iota + 1
	ErrKindValidationFailed
	ErrKindInvalidYAML
	ErrDocumentValidationFailed
	ErrSchemaNotFound
	ErrRead
	ErrUnknown
)

func (ErrorKind) Error

func (k ErrorKind) Error() string

func (ErrorKind) String

func (k ErrorKind) String() string

type ExtensionsValidator

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

func NewExtensionsValidator

func NewExtensionsValidator(extensionName string, validators map[string]ExtensionsValidatorHandler) *ExtensionsValidator

func NewXRulesExtensionsValidator

func NewXRulesExtensionsValidator(validators map[string]ExtensionsValidatorHandler) *ExtensionsValidator

func (*ExtensionsValidator) ExtensionName

func (v *ExtensionsValidator) ExtensionName() string

func (*ExtensionsValidator) Validate

func (v *ExtensionsValidator) Validate(data json.RawMessage, schema spec.Schema) error

type ExtensionsValidatorHandler

type ExtensionsValidatorHandler func(oldValue json.RawMessage) error

type OpenAPISchema

type OpenAPISchema struct {
	Kind     string                 `json:"kind"`
	Versions []OpenAPISchemaVersion `json:"apiVersions"`
}

type OpenAPISchemaVersion

type OpenAPISchemaVersion struct {
	Version string      `json:"apiVersion"`
	Schema  interface{} `json:"openAPISpec"`
}

type ParseIndexOption added in v0.9.0

type ParseIndexOption func(*parseIndexOption)

func ParseIndexWithoutCheckValid added in v0.9.0

func ParseIndexWithoutCheckValid() ParseIndexOption

type PreValidator

type PreValidator interface {
	// Validate
	// if validator does not provide our own schema please return nil
	// will use schema getting for index
	Validate(doc []byte, logger log.Logger) (*spec.Schema, error)
}

type SchemaIndex

type SchemaIndex struct {
	Kind    string `json:"kind"`
	Version string `json:"apiVersion"`
}

func ParseIndex added in v0.9.0

func ParseIndex(reader io.Reader, opts ...ParseIndexOption) (*SchemaIndex, error)

ParseIndex parse SchemaIndex from reader if reader returns error - wrap reader error with ErrRead also function validate is SchemaIndex is valid. Is invalid returns ErrKindValidationFailed with pretty error with input doc in error if content was not unmarshal wrap unmarshal error with ErrKindValidationFailed ErrKindInvalidYAML

func (*SchemaIndex) Group added in v0.9.0

func (i *SchemaIndex) Group() string

Group returns group (deckhouse.io if passed like deckhouse.io/v1) if Version is invalid (for example deckhouse.io/dhctl/v1) returns invalid: deckhouse.io/dhctl/v1 string check is invalid as strings.HasPrefix(s, InvalidGroupPrefix) if Version does not contain group (if Version is v1 for example) returns empty string

func (*SchemaIndex) GroupAndGroupVersion added in v0.9.0

func (i *SchemaIndex) GroupAndGroupVersion() (string, string)

GroupAndGroupVersion returns group (like deckhouse.io) as first value and group version (like v1) as second value if Version is invalid (for example deckhouse.io/dhctl/v1) returns invalid: deckhouse.io/dhctl/v1 string as all arguments check is invalid as strings.HasPrefix(s, InvalidGroupPrefix) if Version contains only group version (if Version is v1 for example) returns empty string as first value and version as second

func (*SchemaIndex) GroupVersion added in v0.9.0

func (i *SchemaIndex) GroupVersion() string

GroupVersion returns group version (v1 if passed like deckhouse.io/v1) if Version is invalid (for example deckhouse.io/dhctl/v1) returns invalid: deckhouse.io/dhctl/v1 string check is invalid as strings.HasPrefix(s, InvalidGroupPrefix)

func (*SchemaIndex) IsValid

func (i *SchemaIndex) IsValid() bool

func (*SchemaIndex) String

func (i *SchemaIndex) String() string

type SchemaWithIndex

type SchemaWithIndex struct {
	Schema *spec.Schema
	Index  SchemaIndex
}

func LoadSchemas

func LoadSchemas(reader io.Reader) ([]*SchemaWithIndex, error)

type ValidateOption

type ValidateOption func(o *validateOptions)

func ValidateWithNoPrettyError

func ValidateWithNoPrettyError(v bool) ValidateOption

func ValidateWithOmitDocInError

func ValidateWithOmitDocInError(v bool) ValidateOption

func ValidateWithStrictUnmarshal

func ValidateWithStrictUnmarshal(v bool) ValidateOption

type ValidationError

type ValidationError struct {
	Kind   ErrorKind
	Errors []Error
}

func (*ValidationError) Append

func (v *ValidationError) Append(kind ErrorKind, e Error)

func (*ValidationError) Error

func (v *ValidationError) Error() string

func (*ValidationError) ErrorOrNil

func (v *ValidationError) ErrorOrNil() error

type Validator

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

func NewValidator

func NewValidator(schemas map[SchemaIndex]*spec.Schema) *Validator

func NewValidatorWithLogger

func NewValidatorWithLogger(schemas map[SchemaIndex]*spec.Schema, loggerProvider log.LoggerProvider) *Validator

func (*Validator) AddExtensionsValidators

func (v *Validator) AddExtensionsValidators(validators ...*ExtensionsValidator) *Validator

func (*Validator) AddPreValidator

func (v *Validator) AddPreValidator(index SchemaIndex, validator PreValidator) *Validator

func (*Validator) AddSchema

func (v *Validator) AddSchema(index SchemaIndex, schema *spec.Schema) *Validator

func (*Validator) AddTransformers

func (v *Validator) AddTransformers(index SchemaIndex, t ...transformer.SchemaTransformer) *Validator

func (*Validator) AddVersionFallback

func (v *Validator) AddVersionFallback(failVersion, fallback string) *Validator

func (*Validator) Get

func (v *Validator) Get(index *SchemaIndex) *spec.Schema

func (*Validator) LoadSchemas

func (v *Validator) LoadSchemas(reader io.Reader) error

func (*Validator) SetDefaultTransformers

func (v *Validator) SetDefaultTransformers(transformers ...transformer.SchemaTransformer) *Validator

func (*Validator) SetLogger

func (v *Validator) SetLogger(loggerProvider log.LoggerProvider) *Validator

func (*Validator) Validate

func (v *Validator) Validate(doc *[]byte, opts ...ValidateOption) (*SchemaIndex, error)

func (*Validator) ValidateWithIndex

func (v *Validator) ValidateWithIndex(index *SchemaIndex, doc *[]byte, opts ...ValidateOption) error

ValidateWithIndex validate one document with schema if schema not fount then return ErrSchemaNotFound

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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