schema

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package schema provides utilities for JSON Schema embedding and validation in structured document projects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractSchemaRef

func ExtractSchemaRef(data []byte) (string, error)

ExtractSchemaRef extracts the $schema field from JSON data.

func ValidateSchemaRef

func ValidateSchemaRef(data []byte, expectedID string) error

ValidateSchemaRef checks if the document's $schema matches the expected schema ID.

Types

type Registry

type Registry struct {
	// ID is the schema identifier URL (e.g., "https://github.com/grokify/structured-goals/schema/v2mom.schema.json").
	ID string

	// Version is the schema version (e.g., "1.0.0").
	Version string

	// Data is the raw JSON schema bytes.
	Data []byte
}

Registry holds embedded JSON schemas for a document type.

func NewRegistry

func NewRegistry(id, version string, data []byte) *Registry

NewRegistry creates a new schema registry.

func (*Registry) JSON

func (r *Registry) JSON() []byte

JSON returns the schema as bytes.

func (*Registry) JSONString

func (r *Registry) JSONString() string

JSONString returns the schema as a string.

func (*Registry) Unmarshal

func (r *Registry) Unmarshal(v any) error

Unmarshal parses the schema into the provided struct.

type SchemaRef

type SchemaRef struct {
	Schema string `json:"$schema,omitempty"`
}

SchemaRef represents a $schema reference in a document.

Jump to

Keyboard shortcuts

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