validation

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: MPL-2.0 Imports: 13 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 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.

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 (*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.

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 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

Jump to

Keyboard shortcuts

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