Documentation
¶
Overview ¶
Package schema validates Meshery documents against the embedded schemas published by github.com/meshery/schemas.
Index ¶
- Variables
- func DecodeAndValidate[T any](data []byte) (T, error)
- func DecodeAndValidateWithRef[T any](ref Ref, data []byte) (T, error)
- func DecodeAndValidateWithValidator[T any](validator *Validator, ref Ref, data []byte) (T, error)
- func ErrCompileSchema(location string, err error) error
- func ErrDecodeDocument(err error) error
- func ErrDecodeTypedDocument(err error) error
- func ErrDetectSchemaVersion() error
- func ErrInvalidRegistration(err error) error
- func ErrResolveSchema(ref Ref) error
- func ErrUnmarshalSchemaAsset(assetPath string, err error) error
- func ErrValidateDocument(details ValidationDetails) error
- func Validate(data []byte) error
- func ValidateAs(documentType DocumentType, data []byte) error
- func ValidateWithRef(ref Ref, data []byte) error
- type DocumentType
- type Ref
- type Registration
- type ValidationDetails
- type Validator
- type Violation
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidRegistrationCode = "meshkit-11320" ErrDetectSchemaVersionCode = "meshkit-11321" ErrResolveSchemaCode = "meshkit-11322" ErrDecodeDocumentCode = "meshkit-11323" ErrCompileSchemaCode = "meshkit-11324" ErrValidateDocumentCode = "meshkit-11325" ErrDecodeTypedDocumentCode = "meshkit-11326" ErrUnmarshalSchemaAssetCode = "meshkit-11327" )
var RegexpMatchStringErrorf = log.Printf
RegexpMatchStringErrorf is called when regexp2 pattern matching fails at runtime (e.g. due to a match timeout). It defaults to log.Printf. Library consumers may replace it with their own structured logger before the Validator is used, for example:
schema.RegexpMatchStringErrorf = myLogger.Errorf
Functions ¶
func DecodeAndValidate ¶
DecodeAndValidate validates the supplied document after auto-detecting its schema and then decodes it into T.
func DecodeAndValidateWithRef ¶
DecodeAndValidateWithRef validates the supplied document against the explicitly identified schema and then decodes it into T.
func DecodeAndValidateWithValidator ¶
DecodeAndValidateWithValidator validates the supplied document using the provided validator and then decodes it into T.
func ErrCompileSchema ¶
func ErrDecodeDocument ¶
func ErrDecodeTypedDocument ¶
func ErrDetectSchemaVersion ¶
func ErrDetectSchemaVersion() error
func ErrInvalidRegistration ¶
func ErrResolveSchema ¶
func ErrUnmarshalSchemaAsset ¶
func ErrValidateDocument ¶
func ErrValidateDocument(details ValidationDetails) error
func Validate ¶
Validate validates the supplied document after auto-detecting the schema from schemaVersion.
func ValidateAs ¶
func ValidateAs(documentType DocumentType, data []byte) error
ValidateAs validates the supplied document against the schema registered for the given document type.
func ValidateWithRef ¶
ValidateWithRef validates the supplied document against the explicitly identified schema.
Types ¶
type DocumentType ¶
type DocumentType string
DocumentType identifies a Meshery document family.
const ( TypeComponent DocumentType = "component" TypeConnection DocumentType = "connection" TypeDesign DocumentType = "design" TypeEnvironment DocumentType = "environment" TypeModel DocumentType = "model" TypeRelationship DocumentType = "relationship" )
type Ref ¶
type Ref struct {
SchemaVersion string `json:"schemaVersion,omitempty" yaml:"schemaVersion,omitempty"`
Type DocumentType `json:"type,omitempty" yaml:"type,omitempty"`
}
Ref identifies which schema should be used to validate a document.
type Registration ¶
type Registration struct {
Ref Ref
Location string
// AssetVersion is the schema asset version segment derived from the embedded
// schemas path (for example, "v1beta1"). It is used to resolve schemaVersion
// strings even when the underlying schema asset does not embed a literal
// schemaVersion constant/default.
AssetVersion string
}
Registration associates a schema reference with an embedded schema location.
type ValidationDetails ¶
type ValidationDetails struct {
Ref Ref `json:"ref"`
SchemaLocation string `json:"schemaLocation"`
Violations []Violation `json:"violations,omitempty"`
}
ValidationDetails contains field-level validation failures for a rejected document.
func ValidationDetailsFromError ¶
func ValidationDetailsFromError(err error) (ValidationDetails, bool)
ValidationDetailsFromError extracts structured validation details from a MeshKit validation error.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator validates Meshery documents against embedded schemas from github.com/meshery/schemas.
func Default ¶
func Default() *Validator
Default returns the process-wide validator backed by the embedded schemas module.
func MustNew ¶
func MustNew() *Validator
MustNew returns a validator preloaded with the built-in Meshery schema registrations. It panics if any builtin registration fails.
func (*Validator) Register ¶
func (v *Validator) Register(registration Registration) error
func (*Validator) Validate ¶
Validate validates the supplied document after auto-detecting the schema from schemaVersion. The document bytes are decoded exactly once; the resulting value is reused for both schema-version detection and validation, avoiding a redundant unmarshal.
func (*Validator) ValidateAny ¶
ValidateAny validates the supplied value against the explicitly identified schema.