jsonschema

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 16 Imported by: 2

README

Custom scalar wire schemas

A field whose type owns custom JSON/text serialization can declare its scalar wire representation without executing its methods during discovery:

type Filter struct {
    Since *FlexibleTime `json:"since,omitempty" wireSchema:"{\"type\":[\"string\",\"integer\"]}"`
}

The declaration describes the existing wire contract; it does not change marshaling, decoding or validation. Here FlexibleTime must actually support the declared text and integer forms. Pointer fields retain nullability.

wireSchema accepts type (one scalar or a nonempty union of string, integer, number, boolean, null) and an optional string format. A format requires a string member. Ordinary Go fields and standard time.Time keep their canonical schemas. Duplicate declarations/types, quoted JSON conflicts, object/array schemas, references and other schema keywords fail discovery. Field visibility is applied first. This tag cannot rename members or expose excluded fields.

ScalarWireSchema provides the same declaration parsing for output-schema owners. No custom serializer or decoder is executed while interpreting the tag.

Documentation

Overview

Package jsonschema compiles native MCP JSON schemas from canonical type and resource owners. It never inspects invocation values or executes user code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ScalarWireSchema added in v0.19.1

func ScalarWireSchema(field reflect.StructField) (map[string]any, bool, error)

ScalarWireSchema reads an owner-authored wireSchema tag for a custom JSON scalar. It never invokes serialization methods or changes runtime binding. Callers must apply their ordinary field visibility policy first. Supported declarations contain type (a scalar name or union) and optional format. Object graphs, references and arbitrary schema overrides are excluded.

Types

type Bundle

type Bundle struct {
	Schema      map[string]any
	Definitions map[string]map[string]any
	Resources   []string
}

type Reflector

type Reflector struct {
	// WireTypes declares owner-authored canonical wire representations for custom
	// JSON types. It never infers a contract or invokes custom marshal methods.
	WireTypes map[reflect.Type]reflect.Type

	// ExcludeInternal removes internal-tagged JSON winners from public input schemas.
	// The zero value retains ordinary encoding/json schema semantics.
	ExcludeInternal bool
	// ExcludeField applies owner-defined visibility to canonical JSON winners
	// and their embedding owners before compiling child schemas or annotations.
	// Nil preserves ordinary JSON field visibility.
	ExcludeField func(reflect.StructField) bool
	Annotate     func(string, reflect.StructField) (string, any)
}

Reflector uses X's encoding/json field projection; annotations cannot change selection, Go identity, JSON names, or source types.

func (Reflector) Compile

func (r Reflector) Compile(request Request) (map[string]any, error)

type Request

type Request struct {
	Type     reflect.Type
	Path     string
	Property string
}

type ResourceCompiler

type ResourceCompiler struct{ FS fs.FS }

ResourceCompiler validates and bundles authored JSON Schema documents. All external references pass through FS; there is no HTTP or OS fallback loader.

func (ResourceCompiler) Compile

func (c ResourceCompiler) Compile(request ResourceRequest) (*Bundle, error)

type ResourceRequest

type ResourceRequest struct {
	Schema map[string]any
	Base   string
	Prefix string
}

Jump to

Keyboard shortcuts

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