schema

package
v0.0.0-...-cd2c16d Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package schema converts Go types (go/types) into an OpenAPI/JSON-Schema intermediate representation. The representation is version-neutral; the openapi package renders it for a concrete OpenAPI version.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConstValue

func ConstValue(v constant.Value) any

ConstValue converts a go/constant value into a Go scalar for enum lists.

func Key

func Key(s *Schema) string

Key returns a stable structural key used to deduplicate schemas (e.g. when collecting the distinct response shapes for a status code).

func SortedEnum

func SortedEnum(vals []any) []any

SortedEnum returns enum values in a stable order for deterministic output.

Types

type Property

type Property struct {
	Name   string
	Schema *Schema
}

Property is one object field, preserving declaration order.

type Registry

type Registry struct {
	Components map[string]*Schema
	Order      []string // component names in insertion order

	// Enums maps a type id ("pkgpath.Name") to its enumerated constant values.
	Enums map[string][]any
	// contains filtered or unexported fields
}

Registry collects named component schemas and converts types on demand.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns an empty registry.

func (*Registry) Of

func (r *Registry) Of(t types.Type) *Schema

Of converts a Go type into a Schema, registering named struct types as reusable components and returning a $ref to them.

type Schema

type Schema struct {
	Ref string

	Type   string // "string", "integer", "number", "boolean", "object", "array", ""
	Format string

	Items                *Schema
	Properties           []*Property
	Required             []string
	AdditionalProperties *Schema // nil + AdditionalAny=false => not set
	AdditionalAny        bool    // additionalProperties: true (free-form object)

	Enum []any

	Nullable    bool
	Description string

	OneOf []*Schema
}

Schema is a version-neutral schema node. Either Ref is set (a reference to a named component) or the inline fields describe the type.

Jump to

Keyboard shortcuts

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