schema

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package schema provides JSON Schema generation from Go types.

Index

Constants

This section is empty.

Variables

View Source
var Reflector = &jsonschema.Reflector{
	DoNotReference: true,
}

Reflector is configured for LLM tool/response schemas. DoNotReference inlines all definitions to avoid $ref.

Functions

func Generate

func Generate[T any]() (json.RawMessage, error)

Generate creates a JSON Schema from a Go type. The type should be a struct with json and jsonschema tags.

Example:

type Book struct {
    Title  string `json:"title" jsonschema:"required,description=The book title"`
    Author string `json:"author" jsonschema:"required"`
    Year   int    `json:"year,omitempty"`
}

schema, err := schema.Generate[Book]()

func GenerateFromValue

func GenerateFromValue(v any) (json.RawMessage, error)

GenerateFromValue creates a JSON Schema from a value. This is useful when you have a value instead of a type.

func MustGenerate

func MustGenerate[T any]() json.RawMessage

MustGenerate is like Generate but panics on error. Useful for package-level schema definitions.

Types

This section is empty.

Jump to

Keyboard shortcuts

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