schema

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSON

type JSON struct {
	// Only relevant when defining a custom schema, i.e. not using schema.From
	Ref  string           `json:"$ref,omitempty"`  // #/$defs/... etc, overrides everything else
	Defs map[string]*JSON `json:"$defs,omitempty"` // for $ref

	// JSON Metadata
	Description string `json:"description,omitempty"`

	// Type System
	Type     JSONType `json:"type,omitempty"`
	Nullable bool     `json:"nullable,omitempty"`

	// Combinators
	Properties           map[string]*JSON `json:"properties,omitempty"`           // for Object
	AdditionalProperties *JSON            `json:"additionalProperties,omitempty"` // for Map[string]someting...
	Items                *JSON            `json:"items,omitempty"`                // for Array

	// Validation
	Enum     []interface{} `json:"enum,omitempty"`
	Required []string      `json:"required,omitempty"`

	/// Number Validation
	Maximum          *float64 `json:"maximum,omitempty"`
	Minimum          *float64 `json:"minimum,omitempty"`
	ExclusiveMaximum *float64 `json:"exclusiveMaximum,omitempty"`
	ExclusiveMinimum *float64 `json:"exclusiveMinimum,omitempty"`

	/// String Validation
	MaxLength *int    `json:"maxLength,omitempty"`
	MinLength *int    `json:"minLength,omitempty"`
	Pattern   *string `json:"pattern,omitempty"` // regular expression
	// Format is used to specify a format for the string, e.g. "date-time", "email", etc.
	Format *string `json:"format,omitempty"` // e.g. "date-time", "email", etc.

	// Array Validation
	MaxItems *int `json:"maxItems,omitempty"`
	MinItems *int `json:"minItems,omitempty"`
}

func From added in v0.6.0

func From(v interface{}) *JSON

From converts a struct to a JSON using reflection and struct tags

type JSONType added in v0.8.0

type JSONType string
const (
	Object  JSONType = "object"
	Array   JSONType = "array"
	String  JSONType = "string"
	Number  JSONType = "number"
	Integer JSONType = "integer"
	Boolean JSONType = "boolean"
)

Jump to

Keyboard shortcuts

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