validate

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package validate exposes the CLI's validation logic as a programmatic, I/O-free API. SchemaValidate returns a structured *ValidationResult that callers can inspect directly or hand to the sibling render package for human or machine-readable output.

Downstream consumers (for example crossplane-diff) should pin a specific crossplane/cli version. Type and function signatures may evolve.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResultError

func ResultError(result *ValidationResult, errorOnMissingSchemas bool) error

ResultError returns an error summarizing the outcome of validation, or nil if validation succeeded. This preserves the historical error semantics of SchemaValidation for programmatic consumers who want a boolean pass/fail.

Types

type FieldErrorType

type FieldErrorType string

FieldErrorType categorizes the kind of validation error a FieldValidationError describes. The supported set is closed; producers and consumers should use the named constants below.

const (
	// FieldErrorTypeSchema indicates a schema validation error from OpenAPI validation.
	FieldErrorTypeSchema FieldErrorType = "schema"
	// FieldErrorTypeCEL indicates a CEL rule validation error.
	FieldErrorTypeCEL FieldErrorType = "cel"
	// FieldErrorTypeUnknownField indicates an unknown field was present in the resource.
	FieldErrorTypeUnknownField FieldErrorType = "unknownField"
	// FieldErrorTypeDefaulting indicates defaults could not be applied to the resource.
	FieldErrorTypeDefaulting FieldErrorType = "defaulting"
)

FieldErrorType values.

type FieldValidationError

type FieldValidationError struct {
	// Type categorizes the error.
	Type FieldErrorType `json:"type"`
	// Field is the path to the invalid field (e.g. "spec.forProvider.region").
	Field string `json:"field,omitempty"`
	// Message is a human-readable description of the error.
	Message string `json:"message"`
	// Value is the invalid value, if applicable.
	Value any `json:"value,omitempty"`
}

FieldValidationError represents a single field-level validation error.

type ResourceValidationResult

type ResourceValidationResult struct {
	APIVersion string                 `json:"apiVersion"`
	Kind       string                 `json:"kind"`
	Name       string                 `json:"name"`
	Namespace  string                 `json:"namespace,omitempty"`
	Status     ValidationStatus       `json:"status"`
	Errors     []FieldValidationError `json:"errors,omitempty"`
}

ResourceValidationResult contains validation results for a single resource.

type ValidationResult

type ValidationResult struct {
	Summary   ValidationSummary          `json:"summary"`
	Resources []ResourceValidationResult `json:"resources"`
}

ValidationResult contains the complete results of schema validation.

func SchemaValidate

func SchemaValidate(ctx context.Context, resources []*unstructured.Unstructured, crds []*extv1.CustomResourceDefinition) (*ValidationResult, error)

SchemaValidate performs schema validation and returns structured results.

This is the processing-only API: no I/O is performed, allowing programmatic consumers to inspect the result directly or hand it to a renderer. The returned error is non-nil only for setup failures (for example, a CRD that cannot be converted or compiled); per-resource validation failures are reported via ResourceValidationResult.Status and .Errors, not via the error.

Caller-owned resources are not mutated. SchemaValidate operates on a deep copy of each input, so the structural defaulting and unknown-field pruning it performs internally are not visible after the call returns.

type ValidationStatus

type ValidationStatus string

ValidationStatus indicates the validation result for a resource.

const (
	// ValidationStatusValid indicates the resource passed all validation checks.
	ValidationStatusValid ValidationStatus = "valid"
	// ValidationStatusInvalid indicates the resource failed one or more validation checks.
	ValidationStatusInvalid ValidationStatus = "invalid"
	// ValidationStatusMissingSchema indicates no schema (CRD/XRD) was found for the resource.
	ValidationStatusMissingSchema ValidationStatus = "missingSchema"
	// ValidationStatusDefaultingFailed indicates defaults could not be applied to the resource.
	ValidationStatusDefaultingFailed ValidationStatus = "defaultingFailed"
)

ValidationStatus values.

type ValidationSummary

type ValidationSummary struct {
	Total          int `json:"total"`
	Valid          int `json:"valid"`
	Invalid        int `json:"invalid"`
	MissingSchemas int `json:"missingSchemas"`
}

ValidationSummary provides aggregate counts across all validated resources.

Directories

Path Synopsis
Package output writes *validate.ValidationResult values in text, JSON or YAML form.
Package output writes *validate.ValidationResult values in text, JSON or YAML form.

Jump to

Keyboard shortcuts

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