schema

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildCUEFromBytes

func BuildCUEFromBytes(data []byte) (cue.Value, error)

BuildCUEFromBytes compiles CUE bytes into a cue.Value.

func FormatCUEDefinitions

func FormatCUEDefinitions(val cue.Value) []byte

FormatCUEDefinitions extracts top-level definitions from a CUE value and formats them as readable CUE syntax.

func ImportPathForModule

func ImportPathForModule(modPath string) string

ImportPathForModule returns the CUE import path for a module path.

func IsJSONSchema

func IsJSONSchema(data []byte) bool

IsJSONSchema returns true if the data looks like JSON (starts with '{').

func IsMajorOnly

func IsMajorOnly(v string) bool

IsMajorOnly returns true if v matches "v0", "v1", "v2", etc.

func SplitModuleVersion

func SplitModuleVersion(input string) (string, string)

SplitModuleVersion separates a module path from its version.

Types

type CUELoader

type CUELoader struct{}

CUELoader loads schemas from the CUE Central Registry.

func (*CUELoader) Load

func (l *CUELoader) Load(ctx context.Context, source string, platform string) (*Schema, error)

func (*CUELoader) Match

func (l *CUELoader) Match(source string) bool

type FileLoader

type FileLoader struct{}

FileLoader loads schemas from file:// URIs.

func (*FileLoader) Load

func (l *FileLoader) Load(ctx context.Context, source string, platform string) (*Schema, error)

func (*FileLoader) Match

func (l *FileLoader) Match(source string) bool

type LegacyLoader

type LegacyLoader struct{}

LegacyLoader handles bare file paths without any scheme prefix.

func (*LegacyLoader) Load

func (l *LegacyLoader) Load(ctx context.Context, source string, platform string) (*Schema, error)

func (*LegacyLoader) Match

func (l *LegacyLoader) Match(source string) bool

type Loader

type Loader interface {
	Match(source string) bool
	Load(ctx context.Context, source string, platform string) (*Schema, error)
}

Loader loads a schema from a source string.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry holds an ordered list of loaders and dispatches to the first match.

func DefaultRegistry

func DefaultRegistry() *Registry

DefaultRegistry returns a registry with all built-in loaders in priority order.

func NewRegistry

func NewRegistry(loaders ...Loader) *Registry

NewRegistry creates a Registry with the given loaders.

func (*Registry) Load

func (r *Registry) Load(ctx context.Context, source string, platform string) (*Schema, error)

Load finds the first matching loader and delegates to it.

type Schema

type Schema struct {
	Platform string
	Bytes    []byte
	CUE      cue.Value
}

Schema holds a loaded platform schema with both raw bytes (for serving) and compiled CUE (for validation).

type SchemaFormat

type SchemaFormat int

SchemaFormat identifies the schema file format.

const (
	FormatUnknown SchemaFormat = iota
	FormatJSON
	FormatCUE
)

func DetectFormat

func DetectFormat(path string) SchemaFormat

DetectFormat determines the schema format from file extension.

type URLLoader

type URLLoader struct{}

URLLoader loads schemas from HTTP/HTTPS URLs.

func (*URLLoader) Load

func (l *URLLoader) Load(ctx context.Context, source string, platform string) (*Schema, error)

func (*URLLoader) Match

func (l *URLLoader) Match(source string) bool

Jump to

Keyboard shortcuts

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