jsonschema

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package jsonschema writes schemas of the spec IR as JSON Schema 2020-12 documents, the way MCP tools describe their input. Every $ref goes through $defs, so a schema that refers to itself ends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(v spec.Value) []byte

Marshal writes v as compact JSON, its object fields in the order of the spec.

func Misfit

func Misfit(v spec.Value, s *spec.Schema) string

Misfit returns why the default v does not fit s, or "" when it fits.

func Value

func Value(v spec.Value) any

Value converts a spec value into what Object holds.

Types

type Builder

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

Builder converts schemas into one document and collects what they refer to in its $defs: a component under its name, anything else under its JSON pointer.

func NewBuilder

func NewBuilder() *Builder

func (*Builder) Diagnostics

func (b *Builder) Diagnostics() []diag.Diagnostic

Diagnostics are the warnings of the schemas converted so far.

func (*Builder) Document

func (b *Builder) Document(root *Object) []byte

Document returns root with the $defs collected so far, compact. The definitions come sorted by name.

func (*Builder) Schema

func (b *Builder) Schema(s *spec.Schema) *Object

Schema converts s. A nil schema is the empty one, which takes anything. A nullable schema takes null: when its $ref, composition, enum or const could turn null away, it is anyOf of itself and null, with its docs and values outside. A readOnly property is left out with its required entry, since a request does not carry it; readOnly in an allOf member counts for the whole object. Each variant of a oneOf with a discriminator requires the property and takes the values that pick it.

type Object

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

Object is a JSON object whose keys keep the order they were first set in. Values are nil, bool, string, json.Number, []string, []any or *Object; anything else is written as null.

func (*Object) Len

func (o *Object) Len() int

Len is the number of keys set.

func (*Object) MarshalJSON

func (o *Object) MarshalJSON() ([]byte, error)

MarshalJSON writes the object compact, with HTML characters left as they are.

func (*Object) Set

func (o *Object) Set(key string, v any) *Object

Set sets key to v, keeping the position of a key that is set again.

Jump to

Keyboard shortcuts

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