diff

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatSummary

func FormatSummary(fields []FieldDiff, color bool) string

FormatSummary produces a one-line summary of classified diffs. Example: "2 critical, 1 warning, 3 info"

func InferSchema

func InferSchema(body string) map[string]interface{}

InferSchema extracts a type-only schema from a JSON body. Values are replaced with their types: "string", "number", "boolean", "null", "array", "object". Nested structures are preserved.

Types

type ClassifiedDiff

type ClassifiedDiff struct {
	FieldDiff
	Severity Severity
	Reason   string
}

ClassifiedDiff wraps a FieldDiff with a severity classification.

func ClassifyDiffs

func ClassifyDiffs(fields []FieldDiff) []ClassifiedDiff

ClassifyDiffs takes raw field diffs and assigns a severity to each one based on what changed and where.

type DiffEngine

type DiffEngine struct {
	IgnoreRules IgnoreChecker
	Normalizer  ValueNormalizer
	SchemaMode  bool // when true, compare types/structure only, ignore values
}

DiffEngine compares stored and live snapshot entries.

func NewDiffEngine

func NewDiffEngine() *DiffEngine

NewDiffEngine creates a new DiffEngine with no ignore rules.

func NewDiffEngineFull

func NewDiffEngineFull(rules IgnoreChecker, normalizer ValueNormalizer) *DiffEngine

NewDiffEngineFull creates a DiffEngine with both ignore rules and normalization.

func NewDiffEngineWithIgnore

func NewDiffEngineWithIgnore(rules IgnoreChecker) *DiffEngine

NewDiffEngineWithIgnore creates a DiffEngine that skips fields matching the given rules.

func (*DiffEngine) Compare

func (d *DiffEngine) Compare(stored, live *snapshot.SnapshotEntry) DiffResult

Compare compares stored vs live snapshot, filtering ignored fields.

func (*DiffEngine) FormatDiff

func (d *DiffEngine) FormatDiff(result DiffResult, color bool) string

FormatDiff formats a DiffResult as a human-readable string with severity indicators. When color is true, ANSI escape codes are used.

type DiffResult

type DiffResult struct {
	RequestHash string
	URL         string
	Matched     bool
	Fields      []FieldDiff
}

DiffResult represents the comparison result for a single request.

type FieldDiff

type FieldDiff struct {
	Path     string
	Expected string
	Actual   string
}

FieldDiff represents a single field-level difference.

func CompareSchemas

func CompareSchemas(path string, expected, actual interface{}) []FieldDiff

CompareSchemas compares two inferred schemas and returns field diffs for structural/type changes only. Value changes are completely ignored.

type IgnoreChecker

type IgnoreChecker interface {
	ShouldIgnore(path string) bool
}

IgnoreChecker decides whether a field path should be skipped during comparison.

type Severity

type Severity int

Severity classifies how important a diff is.

const (
	SeverityInfo     Severity = iota // cosmetic, probably ignorable
	SeverityWarning                  // worth looking at
	SeverityCritical                 // likely a breaking change
)

func (Severity) String

func (s Severity) String() string

func (Severity) Symbol

func (s Severity) Symbol(color bool) string

Symbol returns a colored indicator for terminal output.

type ValueNormalizer

type ValueNormalizer interface {
	NormalizeBody(body string) string
	NormalizeHeaders(headers map[string][]string) map[string][]string
}

ValueNormalizer replaces dynamic values with stable placeholders before comparison.

Jump to

Keyboard shortcuts

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