Documentation
¶
Index ¶
- Constants
- Variables
- func GetContextObject[T any](o *Options) *T
- func NewMapKeyError(severity Severity, rule string, err error, core CoreModeler, ...) error
- func NewMapValueError(severity Severity, rule string, err error, core CoreModeler, ...) error
- func NewSliceError(severity Severity, rule string, err error, core CoreModeler, ...) error
- func NewValidationError(severity Severity, rule string, err error, node *yaml.Node) error
- func NewValidationErrorWithDocumentLocation(severity Severity, rule string, err error, node *yaml.Node, ...) error
- func NewValueError(severity Severity, rule string, err error, core CoreModeler, ...) error
- func RuleDescription(ruleID string) string
- func RuleHowToFix(ruleID string) string
- func RuleSummary(ruleID string) string
- func SortValidationErrors(allErrors []error)
- type ChangeDescriber
- type CoreModeler
- type Error
- type Fix
- type MapKeyNodeGetter
- type MapValueNodeGetter
- type NodeFix
- type Option
- type Options
- type Prompt
- type PromptType
- type Prompter
- type RuleInfo
- type Severity
- type SliceNodeGetter
- type TypeMismatchError
- type ValueNodeGetter
Constants ¶
const ( // Spec Validation Rules RuleValidationRequiredField = "validation-required-field" RuleValidationTypeMismatch = "validation-type-mismatch" RuleValidationDuplicateKey = "validation-duplicate-key" RuleValidationInvalidFormat = "validation-invalid-format" RuleValidationEmptyValue = "validation-empty-value" RuleValidationInvalidReference = "validation-invalid-reference" RuleValidationInvalidSyntax = "validation-invalid-syntax" RuleValidationInvalidSchema = "validation-invalid-schema" RuleValidationInvalidTarget = "validation-invalid-target" RuleValidationAllowedValues = "validation-allowed-values" RuleValidationMutuallyExclusiveFields = "validation-mutually-exclusive-fields" RuleValidationOperationNotFound = "validation-operation-not-found" RuleValidationOperationIdUnique = "validation-operation-id-unique" RuleValidationOperationParameters = "validation-operation-parameters" RuleValidationSchemeNotFound = "validation-scheme-not-found" RuleValidationTagNotFound = "validation-tag-not-found" RuleValidationSupportedVersion = "validation-supported-version" RuleValidationCircularReference = "validation-circular-reference" )
Variables ¶
var ErrSkipFix = errors.New("fix skipped by user")
ErrSkipFix is a sentinel error returned by Prompter when the user chooses to skip a fix. Use errors.Is(err, ErrSkipFix) to check.
Functions ¶
func GetContextObject ¶
func NewMapKeyError ¶ added in v0.2.1
func NewMapKeyError(severity Severity, rule string, err error, core CoreModeler, node MapKeyNodeGetter, key string) error
func NewMapValueError ¶ added in v0.2.1
func NewMapValueError(severity Severity, rule string, err error, core CoreModeler, node MapValueNodeGetter, key string) error
func NewSliceError ¶ added in v0.2.1
func NewSliceError(severity Severity, rule string, err error, core CoreModeler, node SliceNodeGetter, index int) error
func NewValidationError ¶ added in v1.0.0
func NewValidationErrorWithDocumentLocation ¶ added in v1.16.0
func NewValidationErrorWithDocumentLocation(severity Severity, rule string, err error, node *yaml.Node, documentLocation string) error
NewValidationErrorWithDocumentLocation creates a validation error with document location metadata.
func NewValueError ¶ added in v0.2.1
func NewValueError(severity Severity, rule string, err error, core CoreModeler, node ValueNodeGetter) error
func RuleDescription ¶ added in v1.16.0
func RuleHowToFix ¶ added in v1.16.0
func RuleSummary ¶ added in v1.16.0
func SortValidationErrors ¶ added in v1.0.0
func SortValidationErrors(allErrors []error)
SortValidationErrors sorts the provided validation errors by line and column number lowest to highest.
Types ¶
type ChangeDescriber ¶ added in v1.17.0
type ChangeDescriber interface {
DescribeChange() (before, after string)
}
ChangeDescriber is an optional interface that fixes can implement to provide human-readable before/after descriptions of what the fix changes. This enables richer dry-run and reporting output.
type CoreModeler ¶ added in v0.2.1
type Error ¶
type Error struct {
UnderlyingError error
Node *yaml.Node
Severity Severity
Rule string
Fix Fix
// DocumentLocation is the absolute location (URL or file path) of the document
// where the error originated. Empty means the main document.
DocumentLocation string
}
Error represents a validation error and the line and column where it occurred TODO allow getting the JSON path for line/column for validation errors
func (Error) GetColumnNumber ¶ added in v1.0.0
func (Error) GetDocumentLocation ¶ added in v1.16.0
GetDocumentLocation returns the document location where the error originated.
func (Error) GetLineNumber ¶ added in v1.0.0
func (Error) GetSeverity ¶ added in v1.16.0
type Fix ¶ added in v1.16.0
type Fix interface {
// Description returns a human-readable description of what the fix does.
Description() string
// Interactive returns true if the fix requires user input before being applied.
// Non-interactive fixes can be applied directly with Apply().
// Interactive fixes must have SetInput() called with user responses before Apply().
Interactive() bool
// Prompts returns the input prompts needed for this fix.
// Returns nil for non-interactive fixes.
Prompts() []Prompt
// SetInput provides user responses for interactive fixes.
// The responses slice must correspond 1:1 with the Prompts() slice.
// Returns an error if the input is invalid.
// Calling this on a non-interactive fix is a no-op.
SetInput(responses []string) error
// Apply applies the fix to the document.
// For interactive fixes, SetInput() must be called first.
// The doc parameter is typically *openapi.OpenAPI.
// Returns an error if the fix cannot be applied.
Apply(doc any) error
}
Fix represents a suggested fix for a validation finding. Fixes can be non-interactive (applied automatically) or interactive (requiring user input before application).
type MapKeyNodeGetter ¶ added in v1.7.12
MapKeyNodeGetter provides access to map key nodes for error reporting.
type MapValueNodeGetter ¶ added in v1.7.12
MapValueNodeGetter provides access to map value nodes for error reporting.
type NodeFix ¶ added in v1.17.0
type NodeFix interface {
Fix
// ApplyNode applies the fix directly to the YAML node tree.
// rootNode is the document root node.
ApplyNode(rootNode *yaml.Node) error
}
NodeFix is an optional interface for fixes that operate directly on yaml.Node trees rather than the high-level document model. This is useful for simple textual changes (renaming a key, changing a value) where going through the model is unnecessary.
The fix engine checks for this interface first; if implemented, ApplyNode is called instead of Apply.
type Options ¶
func NewOptions ¶
type Prompt ¶ added in v1.17.0
type Prompt struct {
// Type is the kind of input needed.
Type PromptType
// Message is a human-readable description of what input is needed and why.
Message string
// Choices is the list of valid choices when Type is PromptChoice.
// Ignored for other prompt types.
Choices []string
// Default is an optional default value.
Default string
}
Prompt describes a single piece of input a fix needs from the user.
type PromptType ¶ added in v1.17.0
type PromptType int
PromptType describes what kind of user input a fix needs.
const ( // PromptChoice indicates the fix requires selecting from a list of options. PromptChoice PromptType = iota // PromptFreeText indicates the fix requires free-form text input. PromptFreeText )
type Prompter ¶ added in v1.17.0
type Prompter interface {
// PromptFix presents a fix to the user and collects input for its prompts.
// finding provides the error being fixed so the prompter can display context.
// fix is the fix that needs input.
// Returns the user's responses corresponding to fix.Prompts(), or an error.
// Return ErrSkipFix (or wrap it) to indicate the user chose to skip this fix.
PromptFix(finding *Error, fix Fix) ([]string, error)
// Confirm asks the user a yes/no question.
Confirm(message string) (bool, error)
}
Prompter collects user input for interactive fixes. Implementations can be terminal-based (stdin/stdout), GUI-based, or test stubs.
type RuleInfo ¶ added in v1.16.0
func RuleInfoForID ¶ added in v1.16.0
type Severity ¶ added in v1.16.0
type Severity string
type SliceNodeGetter ¶ added in v1.7.12
SliceNodeGetter provides access to slice element nodes for error reporting.
type TypeMismatchError ¶ added in v0.2.2
func NewTypeMismatchError ¶ added in v0.2.2
func NewTypeMismatchError(parentName, msg string, args ...any) *TypeMismatchError
func (TypeMismatchError) Error ¶ added in v0.2.2
func (e TypeMismatchError) Error() string