validation

package
v0.29.3 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SchemaBytes

func SchemaBytes() []byte

SchemaBytes returns the raw embedded JSON Schema bytes. This is used by the doc package to extract field descriptions.

Types

type RuntimeContext

type RuntimeContext struct {
	// HTTPPaths lists the HTTP paths actually served by the running service.
	HTTPPaths []string

	// EnvVars holds configuration environment variables present at runtime.
	EnvVars map[string]string

	// Ports lists the ports actually exposed by the running service.
	Ports []int
}

RuntimeContext represents observed runtime state collected from the actual environment (e.g. a Kubernetes cluster, local dev, CI). It is intentionally generic — no platform-specific types allowed.

type RuntimeValidationResult

type RuntimeValidationResult struct {
	Errors   []contract.ValidationError
	Warnings []contract.ValidationWarning
}

RuntimeValidationResult holds the outcome of comparing a contract against observed runtime state.

func ValidateRuntime

ValidateRuntime compares a contract's declared state against the observed runtime context. It checks that declared interfaces and configuration are present at runtime.

func (*RuntimeValidationResult) IsValid

func (r *RuntimeValidationResult) IsValid() bool

IsValid returns true if there are no errors.

type ValidationResult

type ValidationResult struct {
	Errors   []contract.ValidationError
	Warnings []contract.ValidationWarning
}

ValidationResult aggregates errors and warnings from all validation layers.

func Validate

func Validate(c *contract.Contract, rawYAML []byte, bundleFS fs.FS) ValidationResult

Validate runs all three validation layers in order on the given contract. If structural validation fails, subsequent layers are skipped. The rawYAML parameter is the original YAML bytes for JSON Schema validation. The bundleFS parameter provides access to bundle files for cross-field validation.

func ValidateCrossField

func ValidateCrossField(c *contract.Contract, bundleFS fs.FS) ValidationResult

ValidateCrossField performs Layer 2 validation: cross-field consistency, file existence, reference validation, and semantic rules that cannot be expressed in JSON Schema alone.

func ValidateSemantic

func ValidateSemantic(c *contract.Contract) ValidationResult

ValidateSemantic performs Layer 3 validation: semantic consistency checks based on cross-concern rules that span multiple sections of the contract.

func ValidateStructural

func ValidateStructural(data interface{}) ValidationResult

ValidateStructural performs Layer 1 validation using JSON Schema. It takes the raw YAML bytes (converted to a generic interface{}) and validates against the embedded pacto v1.0 JSON Schema.

func ValidateStructuralRaw

func ValidateStructuralRaw(rawYAML []byte) ValidationResult

ValidateStructuralRaw performs Layer 1 (JSON Schema) validation on raw YAML bytes. It converts the YAML to a generic interface{} and validates against the schema.

func (*ValidationResult) AddError

func (r *ValidationResult) AddError(path, code, message string)

AddError appends a validation error.

func (*ValidationResult) AddWarning

func (r *ValidationResult) AddWarning(path, code, message string)

AddWarning appends a validation warning.

func (*ValidationResult) IsValid

func (r *ValidationResult) IsValid() bool

IsValid returns true if there are no errors.

func (*ValidationResult) Merge

func (r *ValidationResult) Merge(other ValidationResult)

Merge combines another result into this one.

Jump to

Keyboard shortcuts

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