validation

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package validation provides config analysis and diagnostics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildProjectResolver added in v0.5.0

func BuildProjectResolver(projectVars map[string]string) vars.Resolver

BuildProjectResolver creates a Resolver that uses project environment variables. The resolver checks: 1) OS env, 2) Project env vars, 3) Empty string fallback.

func FormatDiagnostic added in v0.5.0

func FormatDiagnostic(d Diagnostic, noColor bool) string

FormatDiagnostic formats a single diagnostic with color support.

func PrintDiagnostics added in v0.5.0

func PrintDiagnostics(analysis *Analysis, out io.Writer, filter func(Diagnostic) bool, noColor bool)

PrintDiagnostics prints diagnostics filtered by a predicate.

func PrintErrors added in v0.5.0

func PrintErrors(analysis *Analysis, out io.Writer, noColor bool)

PrintErrors prints error-level diagnostics.

func PrintWarnings added in v0.5.0

func PrintWarnings(analysis *Analysis, out io.Writer, noColor bool)

PrintWarnings prints warnings and non-error diagnostics.

func RedactValue

func RedactValue(value string) string

RedactValue redacts a value for display, showing only first/last chars

Types

type Analysis

type Analysis struct {
	Request     *domain.Request
	Diagnostics []Diagnostic
	Warnings    []string           // parsed-level warnings like missing yapi: v1
	Chain       []config.ChainStep // Chain steps if this is a chain config
	Base        *config.ConfigV1   // Base config for chain merging
	Expect      config.Expectation // Expectations for single request validation
}

Analysis is the shared result type from analyzing a config.

func AnalyzeConfigFile

func AnalyzeConfigFile(path string) (*Analysis, error)

AnalyzeConfigFile loads a file and analyzes it. If path is "-", reads from stdin.

func AnalyzeConfigString

func AnalyzeConfigString(text string) (*Analysis, error)

AnalyzeConfigString is the single entrypoint for analyzing YAML config. Both CLI and LSP should call this function.

func AnalyzeConfigStringWithProject added in v0.5.0

func AnalyzeConfigStringWithProject(text string, project *config.ProjectConfigV1, projectRoot string) (*Analysis, error)

AnalyzeConfigStringWithProject analyzes a YAML config with optional project context. If project is provided, performs cross-environment variable validation, uses project variables from the default environment for resolution, and applies environment defaults.

func (*Analysis) HasErrors

func (a *Analysis) HasErrors() bool

HasErrors returns true if there are any error-level diagnostics.

func (*Analysis) ToJSON

func (a *Analysis) ToJSON() JSONOutput

ToJSON converts the analysis to a JSON-serializable output.

type Diagnostic

type Diagnostic struct {
	Severity Severity
	Field    string // "url", "method", "graphql", "jq_filter", etc
	Message  string // human readable message

	// Optional position info. LSP uses it, CLI may ignore.
	Line int // 0-based, -1 if unknown
	Col  int // 0-based, -1 if unknown
}

Diagnostic is the canonical diagnostic type that both CLI and LSP use.

func ValidateChainAssertions

func ValidateChainAssertions(text string, assertions []string, stepName string) []Diagnostic

ValidateChainAssertions validates JQ syntax for all assertions in chain steps.

func ValidateGraphQLSyntax

func ValidateGraphQLSyntax(fullYaml string, req *domain.Request) []Diagnostic

ValidateGraphQLSyntax validates the GraphQL query syntax if present.

func ValidateJQSyntax

func ValidateJQSyntax(fullYaml string, req *domain.Request) []Diagnostic

ValidateJQSyntax validates the jq filter syntax if present.

func ValidateProjectVars added in v0.5.0

func ValidateProjectVars(text string, project *config.ProjectConfigV1, projectRoot string) []Diagnostic

ValidateProjectVars performs matrix validation of variables across all environments. This is the "smart validation" that enables diagnostics like "API_URL is missing in 'staging'".

type EnvVarInfo

type EnvVarInfo struct {
	Name       string
	Value      string // Empty if not defined
	IsDefined  bool
	Line       int
	Col        int
	StartIndex int
	EndIndex   int
}

EnvVarInfo holds information about an env var reference for hover/diagnostics

func FindEnvVarRefs

func FindEnvVarRefs(text string) []EnvVarInfo

FindEnvVarRefs finds all environment variable references in text

type EnvironmentRequirement added in v0.5.0

type EnvironmentRequirement struct {
	Required         bool              // True if an environment is required
	MissingVariables []string          // Variables that are not defined anywhere
	PartialVariables map[string]string // Variables defined in some envs (var -> envs CSV)
	Message          string            // Helpful error message
}

EnvironmentRequirement describes whether a config requires an environment

func CheckEnvironmentRequirement added in v0.5.0

func CheckEnvironmentRequirement(text string, project *config.ProjectConfigV1, projectRoot string) *EnvironmentRequirement

CheckEnvironmentRequirement analyzes a config to determine if it needs an environment. Returns requirement info including which variables are missing and where they're defined.

type Error added in v0.5.0

type Error struct {
	Diagnostics []Diagnostic
}

Error provides specific information about validation failures.

func (*Error) Error added in v0.5.0

func (e *Error) Error() string

type Issue

type Issue struct {
	Severity Severity
	Field    string // e.g. "url", "method", "service"
	Message  string // human-readable
}

Issue represents a single validation problem.

func ValidateRequest

func ValidateRequest(req *domain.Request) []Issue

ValidateRequest performs semantic validation on a domain.Request.

type JSONDiagnostic

type JSONDiagnostic struct {
	Severity string `json:"severity"`
	Field    string `json:"field,omitempty"`
	Message  string `json:"message"`
	Line     int    `json:"line"`
	Col      int    `json:"col"`
}

JSONDiagnostic is a JSON-serializable diagnostic.

type JSONOutput

type JSONOutput struct {
	Valid       bool             `json:"valid"`
	Diagnostics []JSONDiagnostic `json:"diagnostics"`
	Warnings    []string         `json:"warnings"`
}

JSONOutput is the JSON-serializable output for validation results.

type Severity

type Severity int

Severity indicates the level of a validation issue.

const (
	SeverityInfo Severity = iota
	SeverityWarning
	SeverityError
)

Severity levels for validation issues.

func (Severity) String

func (s Severity) String() string

type VarDiagnosis added in v0.5.0

type VarDiagnosis struct {
	Name          string
	DefinedInEnvs []string
	MissingInEnvs []string
	IsInDefaults  bool
	IsOS          bool
}

VarDiagnosis holds information about a variable's availability across environments.

Jump to

Keyboard shortcuts

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