fix

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyNodeFix

func ApplyNodeFix(fix validation.Fix, doc *openapi.OpenAPI, rootNode *yaml.Node) error

ApplyNodeFix is a helper that applies a NodeFix if the fix implements the interface, otherwise falls back to Apply.

Types

type AppliedFix

type AppliedFix struct {
	Error  *validation.Error
	Fix    validation.Fix
	Before string // populated from ChangeDescriber if implemented
	After  string // populated from ChangeDescriber if implemented
}

AppliedFix records a successfully applied fix.

type Engine

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

Engine applies fixes to an OpenAPI document.

func NewEngine

func NewEngine(opts Options, prompter validation.Prompter, registry *FixRegistry) *Engine

NewEngine creates a new fix engine.

func (*Engine) ProcessErrors

func (e *Engine) ProcessErrors(ctx context.Context, doc *openapi.OpenAPI, errs []error) (*Result, error)

ProcessErrors takes lint output errors and applies fixes where available. The doc is modified in-place by successful fixes.

Pipeline ordering:

  1. Fixable errors are collected from both Error.Fix fields and the FixRegistry.
  2. Errors are sorted by document location (line, column ascending) so fixes are applied in first-in-document-order. This ensures deterministic results.
  3. Conflict detection: the key is {line, column, rule}. If two errors from the same rule share a location, only the first (by sort order) is applied. Different rules CAN independently fix the same location.
  4. Interactive fixes are skipped in ModeAuto or when no prompter is available.
  5. In dry-run mode, fixes are recorded without modifying the document but conflict detection still operates.

type FailedFix

type FailedFix struct {
	Error    *validation.Error
	Fix      validation.Fix
	FixError error
}

FailedFix records a fix that failed to apply.

type FixProvider

type FixProvider func(err *validation.Error) validation.Fix

FixProvider creates a Fix for a specific validation error. It receives the error and returns a Fix, or nil if no fix is applicable for this particular error instance.

type FixRegistry

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

FixRegistry maps validation rule IDs to fix providers. This allows registering fix providers for pre-existing validation errors that don't come from linter rules (e.g., errors from unmarshal/indexing).

func NewFixRegistry

func NewFixRegistry() *FixRegistry

NewFixRegistry creates a new fix registry.

func (*FixRegistry) GetFix

func (r *FixRegistry) GetFix(err *validation.Error) validation.Fix

GetFix returns a Fix for the given validation error, or nil if no provider can fix it.

func (*FixRegistry) Register

func (r *FixRegistry) Register(ruleID string, provider FixProvider)

Register registers a fix provider for a validation rule ID. Multiple providers can be registered for the same rule ID; the first one that returns a non-nil Fix wins.

type Mode

type Mode int

Mode controls how fixes are applied.

const (
	// ModeNone means no fixing (normal lint).
	ModeNone Mode = iota
	// ModeAuto applies only non-interactive fixes.
	ModeAuto
	// ModeInteractive applies all fixes, prompting for interactive ones.
	ModeInteractive
)

type Options

type Options struct {
	// Mode controls which fixes are applied.
	Mode Mode
	// DryRun when true reports what would be fixed without applying changes.
	// Acts as a modifier on ModeAuto or ModeInteractive.
	DryRun bool
}

Options configures fix engine behavior.

type Result

type Result struct {
	Applied []AppliedFix
	Skipped []SkippedFix
	Failed  []FailedFix
}

Result tracks what the engine did.

type SkipReason

type SkipReason int

SkipReason explains why a fix was skipped.

const (
	// SkipInteractive means the fix requires user input but the mode is non-interactive.
	SkipInteractive SkipReason = iota
	// SkipConflict means another fix already modified the same location.
	SkipConflict
	// SkipUser means the user chose to skip the fix in interactive mode.
	SkipUser
)

type SkippedFix

type SkippedFix struct {
	Error  *validation.Error
	Fix    validation.Fix
	Reason SkipReason
}

SkippedFix records a fix that was skipped.

type TerminalPrompter

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

TerminalPrompter implements Prompter using stdin/stdout for terminal interaction.

func NewTerminalPrompter

func NewTerminalPrompter(in io.Reader, out io.Writer) *TerminalPrompter

NewTerminalPrompter creates a new terminal-based prompter.

func (*TerminalPrompter) Confirm

func (p *TerminalPrompter) Confirm(message string) (bool, error)

func (*TerminalPrompter) PromptFix

func (p *TerminalPrompter) PromptFix(finding *validation.Error, fix validation.Fix) ([]string, error)

Jump to

Keyboard shortcuts

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