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 PrintCommandSchema ¶
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.