schemaregistry

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 15 Imported by: 0

README

schema-registry

CI CodeQL Coverage Mutation Documentation Go Reference Release Go License

schema-registry provides provider-neutral contracts for explicit schema registration, resolution, compatibility, bounded caching, offline bundles, and wire integration. It preserves provider identity and lifecycle differences: portable SHA-256 fingerprints never stand in for Confluent IDs or AWS Glue schema-version UUIDs.

The core module has no implicit registry client. Provider adapters are separate modules under providers/; format adapters are explicit dependencies under formats/.

Quick start

adapter, err := registryjsonschema.New(registryjsonschema.Config{
    Dialect:             registryjsonschema.Draft202012,
    MaxSchemaBytes:      64 << 10,
    MaxTotalSchemaBytes: 256 << 10,
    MaxPayloadBytes:     1 << 20,
    MaxResources:        32,
})
if err != nil {
    return err
}

schema, err := schemaregistry.Compile(ctx, schemaregistry.Definition{
    Format:  schemaregistry.FormatJSONSchema,
    Content: rawSchema,
}, adapter)
if err != nil {
    return err
}
fmt.Println(schema.Fingerprint())

Construct a Client with explicit byte, listing, and concurrency limits. Use a provider adapter only when network operations are intended. Decoding is split into parse, resolve, and decode phases, so ordinary value access cannot trigger hidden network I/O.

Contracts

The minimum supported toolchain is Go 1.26.6. The module follows stable v1 compatibility; see CHANGELOG.md and RELEASING.md.

make clean-consumer compiles the core, all format adapters, and both provider modules from a fresh module with workspace resolution disabled. make check also runs provider-local verification and the official AWS Java wire differential; make check-release additionally requires both live provider integration suites.

The release gate also runs bounded leak, fault-injection, race-stress, and soak exercises for the core and both provider modules. Each Go invocation receives a fresh disposable build cache.

License

MIT. See LICENSE and NOTICE.

Ecosystem

Use the Golib documentation portal to choose companion packages, supported stacks, recipes, and operations guidance.

Documentation

Overview

Package schemaregistry defines provider-neutral contracts for explicit, versioned schema registration and resolution.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrReferenceMissing marks a bundle whose transitive graph is incomplete.
	ErrReferenceMissing = errors.New("schema registry: missing reference")
	// ErrReferenceCycle marks a cycle in a provider-coordinate reference graph.
	ErrReferenceCycle = errors.New("schema registry: reference cycle")
	// ErrReferenceLimit marks a schema graph that exceeds caller-selected bounds.
	ErrReferenceLimit = errors.New("schema registry: reference limit exceeded")
	// ErrFingerprintCollision marks unequal canonical schemas with one claimed
	// portable fingerprint.
	ErrFingerprintCollision = errors.New("schema registry: fingerprint collision")
)
View Source
var (
	// ErrNotFound marks an authoritative provider absence.
	ErrNotFound = errors.New("schema registry: not found")
	// ErrUnavailable marks a provider or policy that cannot resolve now.
	ErrUnavailable = errors.New("schema registry: unavailable")
	// ErrOfflineMiss marks a cache-only lookup with no usable local entry.
	ErrOfflineMiss = errors.New("schema registry: offline cache miss")
	// ErrResolutionMismatch marks a provider response whose identity does not
	// match the requested selector and therefore cannot be cached safely.
	ErrResolutionMismatch = errors.New("schema registry: resolution identity mismatch")
)
View Source
var (
	// ErrInvalidRequest marks an invalid operation request.
	ErrInvalidRequest = errors.New("schema registry: invalid request")
	// ErrUnsupportedOperation marks behavior the selected provider cannot
	// represent safely.
	ErrUnsupportedOperation = errors.New("schema registry: unsupported operation")
	// ErrLimitExceeded marks a configured resource bound violation.
	ErrLimitExceeded = errors.New("schema registry: limit exceeded")
	// ErrConfirmationRequired marks a destructive request without an exact
	// portable identity guard.
	ErrConfirmationRequired = errors.New("schema registry: deletion confirmation required")
)
View Source
var (
	// ErrUnauthorized marks authentication or authorization rejection.
	ErrUnauthorized = errors.New("schema registry: unauthorized")
	// ErrIncompatible marks provider-enforced schema incompatibility.
	ErrIncompatible = errors.New("schema registry: incompatible")
	// ErrRejected marks a definitive provider rejection other than
	// incompatibility or authorization.
	ErrRejected = errors.New("schema registry: rejected")
	// ErrUnknownOutcome marks an operation whose effect cannot be determined.
	ErrUnknownOutcome = errors.New("schema registry: unknown outcome")
)
View Source
var (
	// ErrInvalidSchema marks malformed or otherwise invalid schema input.
	ErrInvalidSchema = errors.New("schema registry: invalid schema")
	// ErrUnsupportedFormat marks a schema format for which no canonical
	// implementation was supplied.
	ErrUnsupportedFormat = errors.New("schema registry: unsupported format")
)

Functions

This section is empty.

Types

type AvailabilityPolicy

type AvailabilityPolicy string

AvailabilityPolicy selects outage and offline behavior for each lookup.

const (
	// FailClosed returns the current upstream failure rather than cached stale data.
	FailClosed AvailabilityPolicy = "fail-closed"
	// AllowStale permits an eligible validated entry only during provider unavailability.
	AllowStale AvailabilityPolicy = "allow-stale"
	// CacheOnly prohibits provider I/O and resolves only from local entries.
	CacheOnly AvailabilityPolicy = "cache-only"
	// ReturnUnavailable prohibits lookup and immediately reports unavailability.
	ReturnUnavailable AvailabilityPolicy = "unavailable"
)

type Bundle

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

Bundle is an immutable, content-addressed graph for startup and offline use. Resolution performs no network access.

func LoadBundle

func LoadBundle(
	ctx context.Context,
	encoded []byte,
	canonicalizers map[Format]Canonicalizer,
	limits GraphLimits,
	maxBundleBytes int,
) (Bundle, error)

LoadBundle validates and recompiles a bounded artifact with caller-supplied local canonicalizers. Canonicalizers must not perform network access.

func NewBundle

func NewBundle(
	root Schema,
	dependencies []Schema,
	limits GraphLimits,
	provenance Provenance,
) (Bundle, error)

NewBundle validates a complete bounded graph rooted at root.

func (Bundle) MarshalBinary

func (bundle Bundle) MarshalBinary() ([]byte, error)

MarshalBinary returns a deterministic, versioned offline artifact. Loading recompiles every definition; the artifact never authorizes network access.

func (Bundle) Provenance

func (bundle Bundle) Provenance() Provenance

Provenance returns the immutable bundle source metadata.

func (Bundle) Resolve

func (bundle Bundle) Resolve(fingerprint Fingerprint) (Schema, bool)

Resolve returns a schema solely from the immutable local bundle.

func (Bundle) Root

func (bundle Bundle) Root() Schema

Root returns the bundle root schema.

type CacheResolution

type CacheResolution struct {
	Result     ResolveResult
	State      CacheState
	Age        time.Duration
	StaleCause error
}

CacheResolution returns stale causes explicitly instead of hiding outages.

type CacheState

type CacheState string

CacheState exposes how a resolution was obtained.

const (
	// CacheLoaded identifies a result loaded during this call.
	CacheLoaded CacheState = "loaded"
	// CacheFresh identifies a fresh positive cache hit.
	CacheFresh CacheState = "fresh"
	// CacheStale identifies an explicitly permitted stale positive hit.
	CacheStale CacheState = "stale"
	// CacheNegative identifies a cached authoritative absence.
	CacheNegative CacheState = "negative"
)

type Canonicalizer

type Canonicalizer interface {
	Canonicalize(context.Context, Definition) ([]byte, error)
}

Canonicalizer validates a definition and returns the canonical bytes used for portable identity. Implementations must not contact a registry.

type Capabilities

type Capabilities struct {
	Provider           string
	Formats            []Format
	Lookups            []LookupKind
	CompatibilityModes []CompatibilityMode
	NumericVersions    bool
	OpaqueVersions     bool
	SchemaReferences   bool
	BoundedListing     bool
	// RegistrationCreationOutcome reports whether the provider can safely
	// distinguish newly-created from concurrently-existing registration.
	RegistrationCreationOutcome bool
	SoftDelete                  bool
	HardDelete                  bool
}

Capabilities describes semantic support without claiming providers are interchangeable.

type Client

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

Client validates portable requests against provider capabilities and caller bounds before any provider I/O.

func NewClient

func NewClient(provider Provider, limits Limits) (*Client, error)

NewClient constructs a bounded client over one provider.

func (*Client) Capabilities

func (client *Client) Capabilities() Capabilities

Capabilities returns an immutable snapshot of provider semantics.

func (*Client) CheckCompatibility

func (client *Client) CheckCompatibility(
	ctx context.Context,
	request CompatibilityRequest,
) (CompatibilityResult, error)

CheckCompatibility returns an explicit unsupported result without provider I/O when the requested semantics are unavailable.

func (*Client) Delete

func (client *Client) Delete(ctx context.Context, request DeleteRequest) (DeleteResult, error)

Delete requires an exact portable fingerprint guard for both soft and hard deletion, then delegates only to an advertised provider capability.

func (*Client) List

func (client *Client) List(ctx context.Context, request ListRequest) (ListPage, error)

List delegates only when the provider advertises bounded listing and the request fits caller limits.

func (*Client) Register

func (client *Client) Register(ctx context.Context, request RegisterRequest) (RegisterResult, error)

Register validates bounds and format support before provider I/O.

func (*Client) Resolve

func (client *Client) Resolve(ctx context.Context, lookup Lookup) (ResolveResult, error)

Resolve rejects selectors the provider cannot define safely.

type Clock

type Clock interface{ Now() time.Time }

Clock supplies deterministic cache time.

type CodecIntegration

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

CodecIntegration composes a business codec and provider framer without a registry dependency or hidden I/O.

func NewCodecIntegration

func NewCodecIntegration(
	codec ValueCodec,
	framer Framer,
	limits CodecLimits,
) (*CodecIntegration, error)

NewCodecIntegration validates explicit codec and framing bounds.

func (*CodecIntegration) Decode

func (integration *CodecIntegration) Decode(
	ctx context.Context,
	schema Schema,
	message WireMessage,
	target any,
) error

Decode applies an already-resolved schema to one parsed payload. Registry access cannot occur through this API.

func (*CodecIntegration) Encode

func (integration *CodecIntegration) Encode(
	ctx context.Context,
	schema Schema,
	id ProviderID,
	value any,
) ([]byte, error)

Encode serializes against an explicit schema, checks payload bounds, and frames with an explicit provider ID.

func (*CodecIntegration) Parse

func (integration *CodecIntegration) Parse(
	ctx context.Context,
	framed []byte,
) (WireMessage, error)

Parse validates the complete frame bound before delegating to the explicit provider framer. It never resolves the returned ID.

type CodecLimits

type CodecLimits struct {
	MaxPayloadBytes int
	MaxFrameBytes   int
}

CodecLimits bound both business payloads and complete framed messages.

type CompatibilityMode

type CompatibilityMode string

CompatibilityMode is a portable request only when advertised by provider capabilities. Provider-specific modes use CompatibilityProviderSpecific and ProviderMode.

const (
	// CompatibilityBackward requests provider-defined backward compatibility.
	CompatibilityBackward CompatibilityMode = "backward"
	// CompatibilityBackwardTransitive requests backward compatibility across provider-defined history.
	CompatibilityBackwardTransitive CompatibilityMode = "backward-transitive"
	// CompatibilityForward requests provider-defined forward compatibility.
	CompatibilityForward CompatibilityMode = "forward"
	// CompatibilityForwardTransitive requests forward compatibility across provider-defined history.
	CompatibilityForwardTransitive CompatibilityMode = "forward-transitive"
	// CompatibilityFull requests both backward and forward compatibility.
	CompatibilityFull CompatibilityMode = "full"
	// CompatibilityFullTransitive requests full compatibility across provider-defined history.
	CompatibilityFullTransitive CompatibilityMode = "full-transitive"
	// CompatibilityNone requests an explicit provider policy with compatibility disabled.
	CompatibilityNone CompatibilityMode = "none"
	// CompatibilityProviderSpecific carries an explicit non-portable ProviderMode.
	CompatibilityProviderSpecific CompatibilityMode = "provider-specific"
)

type CompatibilityRequest

type CompatibilityRequest struct {
	Subject      Subject
	Candidate    Schema
	Mode         CompatibilityMode
	ProviderMode string
}

CompatibilityRequest asks the provider to compare a candidate against an explicit subject history according to one advertised mode.

type CompatibilityResult

type CompatibilityResult struct {
	Supported   bool
	Compatible  bool
	Diagnostics []Diagnostic
}

CompatibilityResult never treats unsupported or indeterminate checks as compatible.

type CompileLimits

type CompileLimits struct {
	MaxSchemaBytes    int
	MaxCanonicalBytes int
	MaxReferences     int
	MaxMetadata       int
}

CompileLimits bound hostile schema definitions before and after format canonicalization.

func DefaultCompileLimits

func DefaultCompileLimits() CompileLimits

DefaultCompileLimits returns conservative portable bounds. Provider adapters may impose stricter service limits.

type Definition

type Definition struct {
	Format     Format
	Content    []byte
	References []Reference
	Metadata   map[string]string
}

Definition is caller-owned schema input. Compile copies all mutable fields.

type DeleteRequest

type DeleteRequest struct {
	Subject Subject
	Version Version
	Policy  DeletionPolicy
}

DeleteRequest targets one exact subject version.

type DeleteResult

type DeleteResult struct {
	Lifecycle LifecycleState
}

DeleteResult reports the provider-observed terminal or transitional state.

type DeletingProvider

type DeletingProvider interface {
	Delete(context.Context, DeleteRequest) (DeleteResult, error)
}

DeletingProvider is an optional destructive administrative capability.

type DeletionMode

type DeletionMode string

DeletionMode preserves soft and hard deletion differences.

const (
	// DeleteSoft requests recoverable provider deletion when advertised.
	DeleteSoft DeletionMode = "soft"
	// DeleteHard requests permanent provider deletion when advertised.
	DeleteHard DeletionMode = "hard"
)

type DeletionPolicy

type DeletionPolicy struct {
	Mode                DeletionMode
	ExpectedFingerprint Fingerprint
}

DeletionPolicy makes destructive intent exact and collision-resistant.

type Diagnostic

type Diagnostic struct {
	Code    string
	Message string
	Path    string
}

Diagnostic is safe structured context; adapters must not place full schema contents or credentials in these fields.

type Fingerprint

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

Fingerprint is a portable SHA-256 identity over the format and canonical schema. It is never interchangeable with a provider-issued identifier.

func ParseFingerprint

func ParseFingerprint(value string) (Fingerprint, error)

ParseFingerprint parses the stable algorithm-qualified portable identity.

func (Fingerprint) String

func (fingerprint Fingerprint) String() string

String returns the algorithm-qualified lowercase hexadecimal fingerprint.

type Format

type Format string

Format identifies one schema language. Format is portable; provider-specific names are mapped only by adapters.

const (
	// FormatJSONSchema identifies JSON Schema documents.
	FormatJSONSchema Format = "json-schema"
	// FormatAvro identifies Apache Avro schemas.
	FormatAvro Format = "avro"
	// FormatProtobuf identifies Protocol Buffers schemas.
	FormatProtobuf Format = "protobuf"
)

type Framer

type Framer interface {
	Frame(context.Context, ProviderID, []byte) ([]byte, error)
	Unframe(context.Context, []byte) (ProviderID, []byte, error)
}

Framer owns one explicitly versioned provider wire format. It receives and returns opaque provider IDs, never portable fingerprints.

type GraphLimits

type GraphLimits struct {
	MaxSchemas    int
	MaxDepth      int
	MaxReferences int
}

GraphLimits bound local and provider reference traversal.

type LifecycleState

type LifecycleState string

LifecycleState is the provider-observed schema version lifecycle.

const (
	// LifecyclePending identifies a provider version not yet available.
	LifecyclePending LifecycleState = "pending"
	// LifecycleAvailable identifies a provider version available for use.
	LifecycleAvailable LifecycleState = "available"
	// LifecycleDeleting identifies a transitional deletion state.
	LifecycleDeleting LifecycleState = "deleting"
	// LifecycleDeleted identifies a provider-confirmed deleted version.
	LifecycleDeleted LifecycleState = "deleted"
	// LifecycleFailed identifies a provider-reported failed version.
	LifecycleFailed LifecycleState = "failed"
	// LifecycleUnknown identifies lifecycle state the provider response cannot establish.
	LifecycleUnknown LifecycleState = "unknown"
)

type Limits

type Limits struct {
	MaxSchemaBytes int
	MaxListResults int
	MaxConcurrent  int
}

Limits are caller-selected operation bounds.

type ListPage

type ListPage struct {
	Schemas       []SchemaDescriptor
	NextPageToken string
}

ListPage is one bounded provider page.

type ListRequest

type ListRequest struct {
	SubjectPrefix string
	Limit         int
	PageToken     string
}

ListRequest is always bounded. PageToken is provider-opaque.

type ListingProvider

type ListingProvider interface {
	List(context.Context, ListRequest) (ListPage, error)
}

ListingProvider is an optional bounded administrative capability.

type Lookup

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

Lookup is constructed by the selector functions below so conflicting identity systems cannot be combined accidentally.

func AtVersion

func AtVersion(subject Subject, version Version) Lookup

AtVersion constructs a lookup for one exact subject version.

func ByFingerprint

func ByFingerprint(fingerprint Fingerprint) Lookup

ByFingerprint constructs a lookup by portable canonical identity.

func ByProviderID

func ByProviderID(id ProviderID) Lookup

ByProviderID constructs a lookup scoped to one provider-issued identity.

func Latest

func Latest(subject Subject) Lookup

Latest constructs a provider-defined latest-version lookup for a subject.

func (Lookup) Fingerprint

func (lookup Lookup) Fingerprint() Fingerprint

Fingerprint returns the portable selector, or its zero value for other kinds.

func (Lookup) Kind

func (lookup Lookup) Kind() LookupKind

Kind returns the lookup's single selector kind.

func (Lookup) ProviderID

func (lookup Lookup) ProviderID() ProviderID

ProviderID returns the provider selector, or its zero value for other kinds.

func (Lookup) Subject

func (lookup Lookup) Subject() Subject

Subject returns the subject selector, or its zero value for identity-only kinds.

func (Lookup) Version

func (lookup Lookup) Version() Version

Version returns the exact version selector, or its zero value for other kinds.

type LookupKind

type LookupKind string

LookupKind identifies one unambiguous resolution selector.

const (
	// LookupByProviderID selects an opaque provider-issued identity.
	LookupByProviderID LookupKind = "provider-id"
	// LookupByFingerprint selects a portable canonical identity.
	LookupByFingerprint LookupKind = "fingerprint"
	// LookupByVersion selects one exact subject version.
	LookupByVersion LookupKind = "subject-version"
	// LookupLatest selects the provider-defined latest subject version.
	LookupLatest LookupKind = "latest"
)

type Provenance

type Provenance struct {
	Source   string
	Revision string
}

Provenance records the immutable source and revision of an offline bundle.

type Provider

type Provider interface {
	Capabilities() Capabilities
	Register(context.Context, RegisterRequest) (RegisterResult, error)
	Resolve(context.Context, Lookup) (ResolveResult, error)
	CheckCompatibility(context.Context, CompatibilityRequest) (CompatibilityResult, error)
}

Provider is the narrow remote-provider boundary used by Client.

type ProviderID

type ProviderID struct {
	Provider string
	Scope    string
	Value    string
}

ProviderID is an opaque provider-issued identity scoped to one provider and provider-defined namespace. It is not a portable schema fingerprint.

type ProviderReference

type ProviderReference struct {
	Name   string
	Target ReferenceCoordinate
}

ProviderReference is a named edge in a provider-coordinate graph.

type Reference

type Reference struct {
	Name        string
	Subject     string
	Version     uint64
	Fingerprint Fingerprint
}

Reference identifies another versioned schema used by a definition.

type ReferenceCoordinate

type ReferenceCoordinate struct {
	Subject Subject
	Version Version
}

ReferenceCoordinate identifies a provider subject version. It is not a portable schema identity.

type ReferenceDocument

type ReferenceDocument struct {
	Coordinate ReferenceCoordinate
	References []ProviderReference
}

ReferenceDocument is one provider-coordinate graph node.

type ReferenceGraph

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

ReferenceGraph is an immutable validated provider-coordinate graph.

func BuildReferenceGraph

func BuildReferenceGraph(
	ctx context.Context,
	roots []ReferenceCoordinate,
	resolver ReferenceResolver,
	limits GraphLimits,
) (ReferenceGraph, error)

BuildReferenceGraph resolves and validates a bounded graph synchronously.

func (ReferenceGraph) Documents

func (graph ReferenceGraph) Documents() []ReferenceDocument

Documents returns a deep copy in deterministic first-visit order.

type ReferenceResolver

type ReferenceResolver interface {
	ResolveReference(context.Context, ReferenceCoordinate) (ReferenceDocument, error)
}

ReferenceResolver explicitly retrieves graph nodes. Implementations may use I/O only during BuildReferenceGraph; compiled schemas and bundles never call it implicitly.

type RegisterRequest

type RegisterRequest struct {
	Subject Subject
	Schema  Schema
}

RegisterRequest registers one compiled schema under an explicit subject.

type RegisterResult

type RegisterResult struct {
	Outcome RegistrationOutcome
	ID      ProviderID
	Version Version
}

RegisterResult reports the provider's explicit registration outcome.

type RegistrationOutcome

type RegistrationOutcome string

RegistrationOutcome distinguishes idempotent success and every material uncertain or rejected provider result.

const (
	// RegistrationCreated reports a provider-confirmed new version.
	RegistrationCreated RegistrationOutcome = "created"
	// RegistrationExisting reports an idempotently resolved existing version.
	RegistrationExisting RegistrationOutcome = "existing"
	// RegistrationIncompatible reports a definitive compatibility rejection.
	RegistrationIncompatible RegistrationOutcome = "incompatible"
	// RegistrationRejected reports another definitive request rejection.
	RegistrationRejected RegistrationOutcome = "rejected"
	// RegistrationUnauthorized reports an authentication or authorization rejection.
	RegistrationUnauthorized RegistrationOutcome = "unauthorized"
	// RegistrationUnavailable reports no provider result because the provider was unavailable.
	RegistrationUnavailable RegistrationOutcome = "unavailable"
	// RegistrationUnknown reports that the provider effect cannot be determined.
	RegistrationUnknown RegistrationOutcome = "unknown"
)

type ResolveCache

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

ResolveCache is a bounded positive and negative cache. A single caller owns each synchronous upstream load; waiters may cancel independently. It starts no goroutines.

func NewResolveCache

func NewResolveCache(resolver Resolver, config ResolveCacheConfig) (*ResolveCache, error)

NewResolveCache validates and constructs a cache.

func (*ResolveCache) Invalidate

func (cache *ResolveCache) Invalidate(lookup Lookup) error

Invalidate removes both positive and negative state for one selector.

func (*ResolveCache) Prime

func (cache *ResolveCache) Prime(lookup Lookup, result ResolveResult) error

Prime adds one explicitly preloaded positive result without provider I/O. It is fresh for the configured freshness interval and remains eligible for the configured stale interval.

func (*ResolveCache) Resolve

func (cache *ResolveCache) Resolve(
	ctx context.Context,
	lookup Lookup,
	policy AvailabilityPolicy,
) (resolution CacheResolution, err error)

Resolve applies one explicit availability policy.

type ResolveCacheConfig

type ResolveCacheConfig struct {
	MaxEntries    int
	MaxConcurrent int
	FreshFor      time.Duration
	StaleFor      time.Duration
	NegativeFor   time.Duration
	Clock         Clock
	Observer      ResolveCacheObserver
}

ResolveCacheConfig makes cache bounds and freshness policy explicit.

type ResolveCacheEvent

type ResolveCacheEvent struct {
	State   CacheState
	Outcome string
}

ResolveCacheEvent excludes schema contents, subjects, IDs, and credentials.

type ResolveCacheObserver

type ResolveCacheObserver interface {
	ObserveResolveCache(context.Context, ResolveCacheEvent)
}

ResolveCacheObserver receives bounded metadata after each lookup. It must not assume calls are serialized and must not retain request contexts.

type ResolveResult

type ResolveResult struct {
	Schema    Schema
	ID        ProviderID
	Subject   Subject
	Version   Version
	Lifecycle LifecycleState
}

ResolveResult identifies both portable schema content and provider identity.

type Resolver

type Resolver interface {
	Resolve(context.Context, Lookup) (ResolveResult, error)
}

Resolver is the minimal schema resolution boundary wrapped by ResolveCache.

type Schema

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

Schema is an immutable compiled definition and its portable identity.

func Compile

func Compile(
	ctx context.Context,
	definition Definition,
	canonicalizer Canonicalizer,
) (Schema, error)

Compile validates and canonicalizes one schema without network access.

Example
package main

import (
	"context"
	"fmt"

	schemaregistry "github.com/faustbrian/go-schema-registry"
	registryjsonschema "github.com/faustbrian/go-schema-registry/formats/jsonschema"
)

func main() {
	adapter, _ := registryjsonschema.New(registryjsonschema.Config{
		Dialect: registryjsonschema.Draft202012, MaxSchemaBytes: 4096,
		MaxTotalSchemaBytes: 4096, MaxPayloadBytes: 4096, MaxResources: 4,
	})
	schema, _ := schemaregistry.Compile(
		context.Background(),
		schemaregistry.Definition{Format: schemaregistry.FormatJSONSchema, Content: []byte(`{"type":"string"}`)},
		adapter,
	)
	fmt.Println(schema.Fingerprint())
}
Output:
sha256:82b5ce4e6a57d9d1707cab819781e7ace6a920b1da6e1def3de0fcd2bf91cd64

func CompileWithLimits

func CompileWithLimits(
	ctx context.Context,
	definition Definition,
	canonicalizer Canonicalizer,
	limits CompileLimits,
) (Schema, error)

CompileWithLimits validates and canonicalizes one schema within explicit caller-selected resource bounds and without network access.

func (Schema) Canonical

func (schema Schema) Canonical() []byte

Canonical returns a copy of the validated canonical representation.

func (Schema) Definition

func (schema Schema) Definition() Definition

Definition returns a copy of the schema definition.

func (Schema) Fingerprint

func (schema Schema) Fingerprint() Fingerprint

Fingerprint returns the portable schema identity.

type SchemaDescriptor

type SchemaDescriptor struct {
	ID          ProviderID
	Subject     Subject
	Version     Version
	Format      Format
	Fingerprint Fingerprint
	Lifecycle   LifecycleState
}

SchemaDescriptor is bounded metadata returned by administrative listing.

type Subject

type Subject struct {
	Registry string
	Name     string
}

Subject is a provider subject or schema name within an optional registry.

type ValueCodec

type ValueCodec interface {
	Encode(context.Context, Schema, any) ([]byte, error)
	Decode(context.Context, Schema, []byte, any) error
}

ValueCodec performs business serialization against an already-resolved schema. Implementations must not access a registry.

type Version

type Version struct {
	Number uint64
	Opaque string
}

Version keeps provider version numbers separate from opaque version tokens. A provider capability documents which field it uses.

type WireMessage

type WireMessage struct {
	ID      ProviderID
	Payload []byte
}

WireMessage is parsed framing metadata plus an owned payload copy. Callers explicitly resolve ID before invoking Decode.

Directories

Path Synopsis
formats
avro
Package avro provides Apache Avro parsing canonical form through goavro.
Package avro provides Apache Avro parsing canonical form through goavro.
jsonschema
Package jsonschema integrates the provider-neutral registry contracts with golib's bounded JSON Schema compiler and validator.
Package jsonschema integrates the provider-neutral registry contracts with golib's bounded JSON Schema compiler and validator.
protobuf
Package protobuf validates and canonicalizes Protocol Buffers source using Buf's maintained native Go compiler.
Package protobuf validates and canonicalizes Protocol Buffers source using Buf's maintained native Go compiler.
providers
confluent module
glue module

Jump to

Keyboard shortcuts

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