API Reference
jsonschema
Section titled “jsonschema”import "github.com/tylergannon/go-gen-jsonschema"- type DataType
- type EnumMode
- type EnumType
- type InterfaceMarker
- type JSONSchema
- type JSONUnionType
- type ObjectSchema
- type ParentSchema
- type SchemaFunction
- type SchemaMarker
- func NewJSONSchemaBuilder[T any](SchemaFunction) SchemaMarker
- func NewJSONSchemaBuilderFor(_ any, _ SchemaFunction, _ …SchemaMethodOption) SchemaMarker
- func NewJSONSchemaFunc[T any](f SchemaMethod[T], _ …SchemaMethodOption) SchemaMarker
- func NewJSONSchemaMethod[T any](SchemaMethod[T], …SchemaMethodOption) SchemaMarker
- type SchemaMethod
- type SchemaMethodOption
- func WithDiscriminator[T any](field T, name string) SchemaMethodOption
- func WithEnum[T any](field T) SchemaMethodOption
- func WithEnumMode(mode EnumMode) SchemaMethodOption
- func WithEnumName[T any](value T, name string) SchemaMethodOption
- func WithFunction[T any](val T, f func(T) json.Marshaler) SchemaMethodOption
- func WithInterface[T any](field T) SchemaMethodOption
- func WithInterfaceImpls[T any](field T, impls …any) SchemaMethodOption
- func WithRenderProviders() SchemaMethodOption
- func WithStructAccessorMethod[T, U any](val T, f func(U) json.Marshaler) SchemaMethodOption
- func WithStructFunctionMethod[T, U any](val U, f func(T, U) json.Marshaler) SchemaMethodOption
- type SchemaMethodOptionObj
- type SchemaNode
- func ArraySchema(items SchemaNode, description string) SchemaNode
- func BoolSchema(description string) SchemaNode
- func ConstSchema[T ~int | ~string](val T, description string) SchemaNode
- func EnumSchema[T ~int | ~string](description string, vals …T) SchemaNode
- func IntSchema(description string) SchemaNode
- func RefSchemaEl(ref string) SchemaNode
- func StringSchema(description string) SchemaNode
- func UnionSchemaEl(alts …SchemaNode) SchemaNode
- type SchemaProperty
- type Tool
type DataType
Section titled “type DataType”type DataType stringconst ( Object DataType = "object" Number DataType = "number" Integer DataType = "integer" String DataType = "string" Array DataType = "array" Null DataType = "null" Boolean DataType = "boolean")type EnumMode
Section titled “type EnumMode”Enum options (v1) - stubs for scanning/type-checking; parsed by scanner
type EnumMode intconst ( EnumStrings EnumMode = iota + 1)type EnumType
Section titled “type EnumType”type EnumType struct{}func NewEnumType
Section titled “func NewEnumType”func NewEnumType[T ~string]() EnumTypeNewEnumType denotes that the type argument should be an enum. If called in the same package where the type is declared, then it applies globally. In all cases, the const values MUST be declared in the same package as the call to NewEnumType.
For now, only string types are supported.
type InterfaceMarker
Section titled “type InterfaceMarker”type InterfaceMarker struct{}func NewInterfaceImpl
Section titled “func NewInterfaceImpl”func NewInterfaceImpl[T any](...T) InterfaceMarkerNewInterfaceImpl marks the arguments as possible implementations for the interface type given in the type argument.
- If called in the same package as the interface itself, then all global instances can be replaced.
- If called somewhere else, only applies to the local package.
type JSONSchema
Section titled “type JSONSchema”JSONSchema is a struct for describing a JSON Schema. It is fairly limited, and you may have better luck using a third-party library. This is a copy from go-openai’s “jsonschema.Definition{}” struct, with the difference being that this one holds references to json.Marshaler, rather than to itself.
type JSONSchema struct { // Type specifies the data type of the schema. Type DataType `json:"type" yaml:"type"` // Description is the description of the schema. Description string `json:"description,omitempty" yaml:"description,omitempty"` // Enum is used to restrict a value to a fixed set of values. It must be an // array with at least one element, where each element is unique. You will // probably only use this with strings. Enum []any `json:"enum,omitempty" yaml:"enum,omitempty"` // Properties describes the properties of an object, if the schema type is // Object. Properties map[string]SchemaNode `json:"properties,omitempty" yaml:"properties,omitempty"` // Required specifies which properties are required, if the schema type is // Object. Required []string `json:"required,omitempty" yaml:"required,omitempty"` // Items specifies which data type an array contains, if the schema type is // Array. Items SchemaNode `json:"items,omitempty" yaml:"items,omitempty"` // AdditionalProperties is used to control the handling of properties in an // object that are not explicitly defined in the properties section of the // schema. example: additionalProperties: true additionalProperties: false // additionalProperties: jsonschema.Definition{Type: jsonschema.String} AdditionalProperties any `json:"additionalProperties,omitempty" yaml:"additionalProperties,omitempty"` Definitions map[string]SchemaNode `json:"$defs,omitzero" yaml:"$defs,omitempty"` Const any `json:"const,omitempty"` // Provide a const value // Strict will make all properties required and additionalProperties: false if // not already set. pplies only if Type = "object". Strict bool `json:"-" yaml:"-"`}func (JSONSchema) MarshalJSON
Section titled “func (JSONSchema) MarshalJSON”func (s JSONSchema) MarshalJSON() ([]byte, error)type JSONUnionType
Section titled “type JSONUnionType”type JSONUnionType []*JSONSchemafunc (JSONUnionType) MarshalJSON
Section titled “func (JSONUnionType) MarshalJSON”func (j JSONUnionType) MarshalJSON() ([]byte, error)MarshalJSON implements json.Marshaler.
type ObjectSchema
Section titled “type ObjectSchema”type ObjectSchema struct { Properties []SchemaProperty Strict bool Required []string Description string AdditionalProperties any}func (*ObjectSchema) AddProperty
Section titled “func (*ObjectSchema) AddProperty”func (s *ObjectSchema) AddProperty(key string, value SchemaNode)func (*ObjectSchema) AddRequiredProperty
Section titled “func (*ObjectSchema) AddRequiredProperty”func (s *ObjectSchema) AddRequiredProperty(key string, value SchemaNode)func (ObjectSchema) MarshalJSON
Section titled “func (ObjectSchema) MarshalJSON”func (s ObjectSchema) MarshalJSON() ([]byte, error)type ParentSchema
Section titled “type ParentSchema”type ParentSchema struct { *ObjectSchema Definitions []SchemaProperty // The key name for the definitions map. Defaults to "definitions" DefinitionsKeyName string `json:"-"` Title string `json:"title,omitzero"`}func (*ParentSchema) AddDefinition
Section titled “func (*ParentSchema) AddDefinition”func (s *ParentSchema) AddDefinition(key string, value SchemaNode)func (ParentSchema) MarshalJSON
Section titled “func (ParentSchema) MarshalJSON”func (s ParentSchema) MarshalJSON() ([]byte, error)type SchemaFunction
Section titled “type SchemaFunction”type SchemaFunction func() json.RawMessagetype SchemaMarker
Section titled “type SchemaMarker”type SchemaMarker struct{}func NewJSONSchemaBuilder
Section titled “func NewJSONSchemaBuilder”func NewJSONSchemaBuilder[T any](SchemaFunction) SchemaMarkerNewJSONSchemaBuilder registers a function as being a stub that should be implemented with a proper json schema and, as needed, unmarshaler functionality.
func NewJSONSchemaBuilderFor
Section titled “func NewJSONSchemaBuilderFor”func NewJSONSchemaBuilderFor(_ any, _ SchemaFunction, _ ...SchemaMethodOption) SchemaMarkerNewJSONSchemaBuilderFor registers a zero-arg builder function for the given example instance value (e.g., TypeName{}), allowing type inference without generics.
func NewJSONSchemaFunc
Section titled “func NewJSONSchemaFunc”func NewJSONSchemaFunc[T any](f SchemaMethod[T], _ ...SchemaMethodOption) SchemaMarkerNewJSONSchemaFunc registers a free function that takes the receiver as its sole parameter as a schema entrypoint. It is equivalent to NewJSONSchemaMethod.
func NewJSONSchemaMethod
Section titled “func NewJSONSchemaMethod”func NewJSONSchemaMethod[T any](SchemaMethod[T], ...SchemaMethodOption) SchemaMarkerNewJSONSchemaMethod registers a struct method as a stub that will be implemented with a proper json schema and, as needed, unmarshaler functionality.
type SchemaMethod
Section titled “type SchemaMethod”type SchemaMethod[T any] func(T) json.RawMessagetype SchemaMethodOption
Section titled “type SchemaMethodOption”type SchemaMethodOption interface { // contains filtered or unexported methods}func WithDiscriminator
Section titled “func WithDiscriminator”func WithDiscriminator[T any](field T, name string) SchemaMethodOptionfunc WithEnum
Section titled “func WithEnum”func WithEnum[T any](field T) SchemaMethodOptionfunc WithEnumMode
Section titled “func WithEnumMode”func WithEnumMode(mode EnumMode) SchemaMethodOptionfunc WithEnumName
Section titled “func WithEnumName”func WithEnumName[T any](value T, name string) SchemaMethodOptionfunc WithFunction
Section titled “func WithFunction”func WithFunction[T any](val T, f func(T) json.Marshaler) SchemaMethodOptionfunc WithInterface
Section titled “func WithInterface”func WithInterface[T any](field T) SchemaMethodOptionInterface options (v1) - stubs for scanning/type-checking; parsed by scanner
func WithInterfaceImpls
Section titled “func WithInterfaceImpls”func WithInterfaceImpls[T any](field T, impls ...any) SchemaMethodOptionfunc WithRenderProviders
Section titled “func WithRenderProviders”func WithRenderProviders() SchemaMethodOptionWithRenderProviders requests generation of RenderedSchema() and provider execution at runtime.
func WithStructAccessorMethod
Section titled “func WithStructAccessorMethod”func WithStructAccessorMethod[T, U any](val T, f func(U) json.Marshaler) SchemaMethodOptionfunc WithStructFunctionMethod
Section titled “func WithStructFunctionMethod”func WithStructFunctionMethod[T, U any](val U, f func(T, U) json.Marshaler) SchemaMethodOptiontype SchemaMethodOptionObj
Section titled “type SchemaMethodOptionObj”type SchemaMethodOptionObj struct{}type SchemaNode
Section titled “type SchemaNode”type SchemaNode = json.Marshalerfunc ArraySchema
Section titled “func ArraySchema”func ArraySchema(items SchemaNode, description string) SchemaNodefunc BoolSchema
Section titled “func BoolSchema”func BoolSchema(description string) SchemaNodefunc ConstSchema
Section titled “func ConstSchema”func ConstSchema[T ~int | ~string](val T, description string) SchemaNodefunc EnumSchema
Section titled “func EnumSchema”func EnumSchema[T ~int | ~string](description string, vals ...T) SchemaNodefunc IntSchema
Section titled “func IntSchema”func IntSchema(description string) SchemaNodefunc RefSchemaEl
Section titled “func RefSchemaEl”func RefSchemaEl(ref string) SchemaNodeA ref into definitions
func StringSchema
Section titled “func StringSchema”func StringSchema(description string) SchemaNodefunc UnionSchemaEl
Section titled “func UnionSchemaEl”func UnionSchemaEl(alts ...SchemaNode) SchemaNodeAn anyOf element
type SchemaProperty
Section titled “type SchemaProperty”type SchemaProperty struct { Key string Value SchemaNode}type Tool
Section titled “type Tool”type Tool interface { Name() string Description() string Parameters() json.RawMessage Execute(ctx context.Context, params json.RawMessage) (json.RawMessage, error)}func BuildTool
Section titled “func BuildTool”func BuildTool(fn any) ToolGenerated by gomarkdoc