schema

package
v0.14.108 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package schema provides utilities for generating JSON schemas from Go types, enabling validation and documentation of tool and message parameters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromAny added in v0.10.55

func FromAny(t any) (*jsonschema.Schema, error)

func JSONSchema

func JSONSchema(t reflect.Type) *jsonschema.Schema

JSONSchema return the json schema of the configuration

func MustFromAny added in v0.10.55

func MustFromAny(t any) *jsonschema.Schema

FromAny creates a json schema from any type. It panics if the type is not valid.

For example:

map[string]any{
	"type": "object",
	"properties": map[string]any{
		"query": map[string]any{
			"type": "string",
		},
	},
}

func ToFunctionSchema

func ToFunctionSchema(tType reflect.Type, tSchema *jsonschema.Schema) *jsonschema.Schema

Types

type Faker

type Faker interface {
	Fake() any
}

Faker is a interface for generating structures with fake data. It is used for generating test data.

type ResponseFormat added in v0.10.55

type ResponseFormat struct {
	Type       string                    `json:"type"`
	JSONSchema *ResponseFormatJSONSchema `json:"json_schema,omitempty"`
}

ResponseFormat is the format of the response.

func NewResponseFormat added in v0.10.55

func NewResponseFormat(t reflect.Type, strict bool) (*ResponseFormat, error)

type ResponseFormatJSONSchema added in v0.10.55

type ResponseFormatJSONSchema struct {
	Name   string                            `json:"name"`
	Strict bool                              `json:"strict"`
	Schema *ResponseFormatJSONSchemaProperty `json:"schema"`
}

type ResponseFormatJSONSchemaProperty added in v0.10.55

type ResponseFormatJSONSchemaProperty struct {
	Type                 string                                       `json:"type"`
	Title                string                                       `json:"title,omitempty"`
	Description          string                                       `json:"description,omitempty"`
	Enum                 []any                                        `json:"enum,omitempty"`
	Default              any                                          `json:"default,omitempty"`
	Examples             []any                                        `json:"examples,omitempty"`
	Items                *ResponseFormatJSONSchemaProperty            `json:"items,omitempty"`
	Properties           map[string]*ResponseFormatJSONSchemaProperty `json:"properties,omitempty"`
	AdditionalProperties *bool                                        `json:"additionalProperties,omitempty"`
	Required             []string                                     `json:"required,omitempty"`
	Ref                  string                                       `json:"$ref,omitempty"`
}

type Schema

type Schema struct {
	RawSchema *jsonschema.Schema
	// Parameters represents the Function parameters definition
	Parameters *jsonschema.Schema
}

func New

func New(t reflect.Type) (*Schema, error)

New creates a new schema from the given type

func (*Schema) NameFromRef

func (s *Schema) NameFromRef() string

func (*Schema) String

func (s *Schema) String() string

Jump to

Keyboard shortcuts

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