schema

package
v1.15.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 9 Imported by: 1 module, 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 schema builds JSON Schema documents from Go types for CLI output and the hosted MCP server.

Generated OpenAPI models need rules reflect does not know about. time.Time is a date-time string. Pointers and OpenAPI NullableT wrappers are JSON Schema null unions (draft 2020-12 has no nullable keyword). anyOf wrappers are flattened so Go variant names never appear as properties. Enum types publish the Allowed*EnumValues lists registered in enums.go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Print

func Print(v any) error

Print outputs the JSON Schema for the given type.

func PrintCommandSchema

func PrintCommandSchema(command, description string, v any) error

PrintCommandSchema outputs schema with command metadata.

Types

type CommandSchema

type CommandSchema struct {
	Command     string      `json:"command"`
	Description string      `json:"description"`
	Output      *JSONSchema `json:"output"`
}

CommandSchema holds schema information for a CLI command.

type JSONSchema

type JSONSchema struct {
	Schema      string                 `json:"$schema,omitempty"`
	Type        any                    `json:"type,omitempty"`
	Description string                 `json:"description,omitempty"`
	Properties  map[string]*JSONSchema `json:"properties,omitempty"`
	Items       *JSONSchema            `json:"items,omitempty"`
	Required    []string               `json:"required,omitempty"`
	Enum        []string               `json:"enum,omitempty"`
	OneOf       []*JSONSchema          `json:"oneOf,omitempty"`
	AnyOf       []*JSONSchema          `json:"anyOf,omitempty"`
	Format      string                 `json:"format,omitempty"`
	// Ref points at a $defs entry. Large enums are hoisted so a schema that
	// uses the same enum many times does not repeat the value list.
	Ref string `json:"$ref,omitempty"`
	// Defs holds hoisted schemas for this document. Only the root sets it.
	Defs map[string]*JSONSchema `json:"$defs,omitempty"`
	// AdditionalProperties is a pointer so false is emitted. nil means the
	// keyword is omitted, which JSON Schema treats as allowing extra fields.
	AdditionalProperties *bool `json:"additionalProperties,omitempty"`
}

JSONSchema is one JSON Schema node (draft 2020-12).

Type is a JSON string ("object") or a list of strings (["string","null"]) for a nullable primitive. Nullable objects, arrays, enums, and unions use AnyOf with a {"type":"null"} branch. Both forms are valid JSON Schema; the old "nullable" keyword is not.

func Generate

func Generate(v any) *JSONSchema

Generate creates a JSON Schema from a Go type. Values that implement schemaProvider supply the schema themselves.

Directories

Path Synopsis
Command genenums writes enums.go from the generated client's Allowed*EnumValues slices.
Command genenums writes enums.go from the generated client's Allowed*EnumValues slices.

Jump to

Keyboard shortcuts

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