Documentation
¶
Overview ¶
Package validation provides config analysis and diagnostics.
Index ¶
- func BuildProjectResolver(projectVars map[string]string) vars.Resolver
- func FormatDiagnostic(d Diagnostic, noColor bool) string
- func PrintDiagnostics(analysis *Analysis, out io.Writer, filter func(Diagnostic) bool, noColor bool)
- func PrintErrors(analysis *Analysis, out io.Writer, noColor bool)
- func PrintWarnings(analysis *Analysis, out io.Writer, noColor bool)
- func RedactValue(value string) string
- type Analysis
- type Diagnostic
- func ValidateChainAssertions(text string, assertions []string, stepName string) []Diagnostic
- func ValidateGraphQLSyntax(fullYaml string, req *domain.Request) []Diagnostic
- func ValidateJQSyntax(fullYaml string, req *domain.Request) []Diagnostic
- func ValidateProjectVars(text string, project *config.ProjectConfigV1, projectRoot string) []Diagnostic
- type EnvVarInfo
- type EnvironmentRequirement
- type Error
- type Issue
- type JSONDiagnostic
- type JSONOutput
- type Severity
- type VarDiagnosis
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildProjectResolver ¶ added in v0.5.0
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
PrintErrors prints error-level diagnostics.
func PrintWarnings ¶ added in v0.5.0
PrintWarnings prints warnings and non-error diagnostics.
func RedactValue ¶
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 ¶
AnalyzeConfigFile loads a file and analyzes it. If path is "-", reads from stdin.
func AnalyzeConfigString ¶
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) 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.
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 ¶
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.