data

package
v1.2.9 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SchemaTypeBool is a bool schema type.
	SchemaTypeBool = "boolean"
	// SchemaTypeString is a string schema type.
	SchemaTypeString = "string"
	//SchemaTypeNumber is a number schema type.
	SchemaTypeNumber = "number"
	// SchemaTypeObject is an object schema type.
	SchemaTypeObject = "object"
	// SchemaTypeArray is an array schema type.
	SchemaTypeArray = "array"
	// SchemaTypeInteger is an integer schema type.
	SchemaTypeInteger = "integer"

	// SchemaFormatFloat is a float schema type.
	SchemaFormatFloat = "float"
	// SchemaFormatDouble is a double schema type.
	SchemaFormatDouble = "double"
	// SchemaFormatInt32 is a int32 schema type.
	SchemaFormatInt32 = "int32"
	// SchemaFormatInt64 is a int64 schema type.
	SchemaFormatInt64 = "int64"
)

Variables

View Source
var ErrUnsupportedType = errors.New("unsupported type")

ErrUnsupportedType is returned when the type is not supported

Functions

This section is empty.

Types

type Schema

type Schema struct {
	Id               string             `json:"id,omitempty" yaml:"id,omitempty"`
	Ref              string             `json:"$ref,omitempty" yaml:"$ref,omitempty"`
	Schema           string             `json:"-" yaml:"-"`
	Description      string             `json:"description,omitempty" yaml:"description,omitempty"`
	Type             string             `json:"type,omitempty" yaml:"type,omitempty"`
	Nullable         bool               `json:"nullable,omitempty" yaml:"nullable,omitempty"`
	Format           *string            `json:"format,omitempty" yaml:"format,omitempty"`
	Title            string             `json:"title,omitempty" yaml:"title,omitempty"`
	Default          any                `json:"default,omitempty" yaml:"default,omitempty"`
	Maximum          *float64           `json:"maximum,omitempty" yaml:"maximum,omitempty"`
	ExclusiveMaximum *float64           `json:"exclusiveMaximum,omitempty" yaml:"exclusiveMaximum,omitempty"`
	Minimum          *float64           `json:"minimum,omitempty" yaml:"minimum,omitempty"`
	ExclusiveMinimum *float64           `json:"exclusiveMinimum,omitempty" yaml:"exclusiveMinimum,omitempty"`
	MaxLength        *int               `json:"maxLength,omitempty" yaml:"maxLength,omitempty"`
	MinLength        *int               `json:"minLength,omitempty" yaml:"minLength,omitempty"`
	Pattern          *string            `json:"pattern,omitempty" yaml:"pattern,omitempty"`
	MaxItems         *int               `json:"maxItems,omitempty" yaml:"maxItems,omitempty"`
	MinItems         *int               `json:"minItems,omitempty" yaml:"minItems,omitempty"`
	UniqueItems      bool               `json:"uniqueItems,omitempty" yaml:"uniqueItems,omitempty"`
	MultipleOf       *float64           `json:"multipleOf,omitempty" yaml:"multipleOf,omitempty"`
	Enum             []any              `json:"enum,omitempty" yaml:"enum,omitempty"`
	MaxProperties    *int               `json:"maxProperties,omitempty" yaml:"maxProperties,omitempty"`
	MinProperties    *int               `json:"minProperties,omitempty" yaml:"minProperties,omitempty"`
	Required         []string           `json:"required,omitempty" yaml:"required,omitempty"`
	Items            *Schema            `json:"items,omitempty" yaml:"items,omitempty"`
	AllOf            []*Schema          `json:"allOf,omitempty" yaml:"allOf,omitempty"`
	OneOf            []*Schema          `json:"oneOf,omitempty" yaml:"oneOf,omitempty"`
	AnyOf            []*Schema          `json:"anyOf,omitempty" yaml:"anyOf,omitempty"`
	Not              *Schema            `json:"not,omitempty" yaml:"not,omitempty"`
	Properties       map[string]*Schema `json:"properties,omitempty" yaml:"properties,omitempty"`
	AdditionalItems  *Schema            `json:"additionalItems,omitempty" yaml:"additionalItems,omitempty"`
	Xml              *Xml               `json:"xml,omitempty" yaml:"xml,omitempty"`
	ReadOnly         bool               `json:"readOnly,omitempty" yaml:"readOnly,omitempty"`
	WriteOnly        bool               `json:"writeOnly,omitempty" yaml:"writeOnly,omitempty"`
	Example          any                `json:"example,omitempty" yaml:"example,omitempty"`
	Examples         []any              `json:"examples,omitempty" yaml:"examples,omitempty"`
	Deprecated       bool               `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
}

Schema used to define structure of the data This is a subset of OpenAPI 3.0 schema

func GenerateSchema added in v1.2.8

func GenerateSchema(t reflect.Type) (schema *Schema, err error)

GenerateSchema converts a Go type to a JSON Schema.

This function uses reflection to analyze Go types and produce corresponding JSON Schema representations. It supports various Go types including structs, slices, maps, primitive types, and pointers.

For structs, it creates an object schema with properties corresponding to the struct fields. JSON field names are extracted from json tags if present. Unexported fields are skipped.

For slices, it creates an array schema with the element type defined in the Items field.

For maps, it creates an object schema with the value type defined in AdditionalItems.

The function handles pointers by resolving to their base types.

Parameters:

  • t: The reflect.Type to convert to a JSON Schema

Returns:

  • schema: A pointer to the generated Schema
  • err: An error if the type is unsupported or if a nested type cannot be processed

type Xml

type Xml struct {
	Name      *string `json:"name,omitempty" yaml:"name,omitempty"`
	Namespace *string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
	Prefix    *string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
	Attribute *bool   `json:"attribute,omitempty" yaml:"attribute,omitempty"`
	Wrapped   *bool   `json:"wrapped,omitempty" yaml:"wrapped,omitempty"`
}

Jump to

Keyboard shortcuts

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