schema

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompatibilityMode

type CompatibilityMode string

CompatibilityMode defines how schema evolution is validated

const (
	// CompatibilityNone allows any schema change
	CompatibilityNone CompatibilityMode = "NONE"

	// CompatibilityBackward allows deletion of fields and addition of optional fields
	// New schema can read data written with old schema
	CompatibilityBackward CompatibilityMode = "BACKWARD"

	// CompatibilityForward allows addition of fields and deletion of optional fields
	// Old schema can read data written with new schema
	CompatibilityForward CompatibilityMode = "FORWARD"

	// CompatibilityFull is both backward and forward compatible
	CompatibilityFull CompatibilityMode = "FULL"

	// CompatibilityBackwardTransitive checks compatibility against all previous versions
	CompatibilityBackwardTransitive CompatibilityMode = "BACKWARD_TRANSITIVE"

	// CompatibilityForwardTransitive checks compatibility against all previous versions
	CompatibilityForwardTransitive CompatibilityMode = "FORWARD_TRANSITIVE"

	// CompatibilityFullTransitive checks compatibility against all previous versions
	CompatibilityFullTransitive CompatibilityMode = "FULL_TRANSITIVE"
)

type DefaultValidator

type DefaultValidator struct{}

DefaultValidator provides basic schema validation

func NewDefaultValidator

func NewDefaultValidator() *DefaultValidator

NewDefaultValidator creates a new default validator

func (*DefaultValidator) CheckCompatibility

func (v *DefaultValidator) CheckCompatibility(format SchemaFormat, oldSchema, newSchema string, mode CompatibilityMode) (bool, error)

CheckCompatibility checks if two schemas are compatible

func (*DefaultValidator) Validate

func (v *DefaultValidator) Validate(format SchemaFormat, definition string) error

Validate validates a schema definition

type DeleteSchemaRequest

type DeleteSchemaRequest struct {
	Subject Subject
	Version Version
}

DeleteSchemaRequest deletes a schema version

type DeleteSchemaResponse

type DeleteSchemaResponse struct {
	ErrorCode ErrorCode
}

DeleteSchemaResponse confirms deletion

type DeleteSubjectRequest

type DeleteSubjectRequest struct {
	Subject Subject
}

DeleteSubjectRequest deletes all versions of a subject

type DeleteSubjectResponse

type DeleteSubjectResponse struct {
	Versions  []Version // Deleted versions
	ErrorCode ErrorCode
}

DeleteSubjectResponse confirms deletion

type ErrorCode

type ErrorCode int

ErrorCode represents schema registry error codes

const (
	ErrorNone ErrorCode = iota
	ErrorSchemaNotFound
	ErrorSubjectNotFound
	ErrorVersionNotFound
	ErrorInvalidSchema
	ErrorIncompatibleSchema
	ErrorSubjectAlreadyExists
	ErrorVersionAlreadyExists
	ErrorInvalidCompatibilityMode
	ErrorInvalidSubject
	ErrorInvalidVersion
	ErrorSchemaRegistryError
)

func (ErrorCode) Error

func (e ErrorCode) Error() string

Error returns the error message

func (ErrorCode) String

func (e ErrorCode) String() string

String returns the string representation of ErrorCode

type GetCompatibilityRequest

type GetCompatibilityRequest struct {
	Subject Subject
}

GetCompatibilityRequest retrieves compatibility mode for a subject

type GetCompatibilityResponse

type GetCompatibilityResponse struct {
	Compatibility CompatibilityMode
	ErrorCode     ErrorCode
}

GetCompatibilityResponse returns compatibility mode

type GetLatestSchemaRequest

type GetLatestSchemaRequest struct {
	Subject Subject
}

GetLatestSchemaRequest retrieves the latest schema for a subject

type GetLatestSchemaResponse

type GetLatestSchemaResponse struct {
	Schema    *Schema
	ErrorCode ErrorCode
}

GetLatestSchemaResponse returns the latest schema

type GetSchemaBySubjectVersionRequest

type GetSchemaBySubjectVersionRequest struct {
	Subject Subject
	Version Version
}

GetSchemaBySubjectVersionRequest retrieves a schema by subject and version

type GetSchemaBySubjectVersionResponse

type GetSchemaBySubjectVersionResponse struct {
	Schema    *Schema
	ErrorCode ErrorCode
}

GetSchemaBySubjectVersionResponse returns the schema

type GetSchemaRequest

type GetSchemaRequest struct {
	ID SchemaID
}

GetSchemaRequest retrieves a schema by ID

type GetSchemaResponse

type GetSchemaResponse struct {
	Schema    *Schema
	ErrorCode ErrorCode
}

GetSchemaResponse returns the schema

type ListSubjectsRequest

type ListSubjectsRequest struct {
	Prefix string // Optional prefix filter
}

ListSubjectsRequest lists all subjects

type ListSubjectsResponse

type ListSubjectsResponse struct {
	Subjects  []Subject
	ErrorCode ErrorCode
}

ListSubjectsResponse returns list of subjects

type ListVersionsRequest

type ListVersionsRequest struct {
	Subject Subject
}

ListVersionsRequest lists all versions for a subject

type ListVersionsResponse

type ListVersionsResponse struct {
	Versions  []Version
	ErrorCode ErrorCode
}

ListVersionsResponse returns list of versions

type RegisterSchemaRequest

type RegisterSchemaRequest struct {
	Subject    Subject
	Format     SchemaFormat
	Definition string
}

RegisterSchemaRequest registers a new schema

type RegisterSchemaResponse

type RegisterSchemaResponse struct {
	ID        SchemaID
	ErrorCode ErrorCode
}

RegisterSchemaResponse returns the registered schema ID

type RegistryStats

type RegistryStats struct {
	TotalSchemas  int
	TotalSubjects int
}

RegistryStats holds registry statistics

type Schema

type Schema struct {
	ID         SchemaID
	Subject    Subject
	Version    Version
	Format     SchemaFormat
	Definition string // The actual schema definition (JSON, Avro, Proto)
	CreatedAt  time.Time
	UpdatedAt  time.Time
}

Schema represents a schema definition

type SchemaFormat

type SchemaFormat string

SchemaFormat represents the schema format/type

const (
	// FormatJSON represents JSON schema format
	FormatJSON SchemaFormat = "JSON"

	// FormatAvro represents Apache Avro schema format
	FormatAvro SchemaFormat = "AVRO"

	// FormatProtobuf represents Protocol Buffers schema format
	FormatProtobuf SchemaFormat = "PROTOBUF"
)

type SchemaID

type SchemaID int32

SchemaID is a unique identifier for a schema

type SchemaMetadata

type SchemaMetadata struct {
	ID          SchemaID
	Subject     Subject
	Version     Version
	Format      SchemaFormat
	Fingerprint string // Hash of schema definition
	CreatedAt   time.Time
}

SchemaMetadata contains metadata about a schema

type SchemaReference

type SchemaReference struct {
	Name    string
	Subject Subject
	Version Version
}

SchemaReference represents a reference to another schema

type SchemaRegistry

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

SchemaRegistry manages schemas and their versions

func NewSchemaRegistry

func NewSchemaRegistry(validator SchemaValidator, logger *logging.Logger) *SchemaRegistry

NewSchemaRegistry creates a new schema registry

func (*SchemaRegistry) DeleteSchema

func (sr *SchemaRegistry) DeleteSchema(req *DeleteSchemaRequest) (*DeleteSchemaResponse, error)

DeleteSchema deletes a specific schema version

func (*SchemaRegistry) DeleteSubject

func (sr *SchemaRegistry) DeleteSubject(req *DeleteSubjectRequest) (*DeleteSubjectResponse, error)

DeleteSubject deletes all versions of a subject

func (*SchemaRegistry) GetCompatibility

GetCompatibility retrieves compatibility mode for a subject

func (*SchemaRegistry) GetLatestSchema

GetLatestSchema retrieves the latest schema for a subject

func (*SchemaRegistry) GetSchema

func (sr *SchemaRegistry) GetSchema(req *GetSchemaRequest) (*GetSchemaResponse, error)

GetSchema retrieves a schema by ID

func (*SchemaRegistry) GetSchemaBySubjectVersion

GetSchemaBySubjectVersion retrieves a schema by subject and version

func (*SchemaRegistry) ListSubjects

func (sr *SchemaRegistry) ListSubjects(req *ListSubjectsRequest) (*ListSubjectsResponse, error)

ListSubjects lists all subjects

func (*SchemaRegistry) ListVersions

func (sr *SchemaRegistry) ListVersions(req *ListVersionsRequest) (*ListVersionsResponse, error)

ListVersions lists all versions for a subject

func (*SchemaRegistry) RegisterSchema

RegisterSchema registers a new schema

func (*SchemaRegistry) SetGlobalCompatibility

func (sr *SchemaRegistry) SetGlobalCompatibility(mode CompatibilityMode) error

SetGlobalCompatibility sets the global compatibility mode

func (*SchemaRegistry) Stats

func (sr *SchemaRegistry) Stats() RegistryStats

Stats returns registry statistics

func (*SchemaRegistry) TestCompatibility

TestCompatibility tests if a schema is compatible

func (*SchemaRegistry) UpdateCompatibility

UpdateCompatibility updates compatibility mode for a subject

type SchemaValidator

type SchemaValidator interface {
	Validate(format SchemaFormat, definition string) error
	CheckCompatibility(format SchemaFormat, oldSchema, newSchema string, mode CompatibilityMode) (bool, error)
}

SchemaValidator validates schemas and checks compatibility

type SchemaWithReferences

type SchemaWithReferences struct {
	Schema     *Schema
	References []SchemaReference
}

SchemaWithReferences represents a schema with references to other schemas

type Subject

type Subject string

Subject is a namespace for schemas (typically topic-key or topic-value)

type SubjectVersion

type SubjectVersion struct {
	Subject Subject
	Version Version
}

SubjectVersion represents a subject and version pair

type TestCompatibilityRequest

type TestCompatibilityRequest struct {
	Subject    Subject
	Version    Version // Test against this version
	Format     SchemaFormat
	Definition string
}

TestCompatibilityRequest tests if a schema is compatible

type TestCompatibilityResponse

type TestCompatibilityResponse struct {
	Compatible bool
	ErrorCode  ErrorCode
	Message    string // Error/warning message
}

TestCompatibilityResponse returns compatibility result

type UpdateCompatibilityRequest

type UpdateCompatibilityRequest struct {
	Subject       Subject
	Compatibility CompatibilityMode
}

UpdateCompatibilityRequest updates compatibility mode for a subject

type UpdateCompatibilityResponse

type UpdateCompatibilityResponse struct {
	ErrorCode ErrorCode
}

UpdateCompatibilityResponse confirms update

type Version

type Version int32

Version is a schema version number

Jump to

Keyboard shortcuts

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