openapi

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package openapi assembles per-tool JSON Schemas from a dereferenced OpenAPI 3.1 document.

Input is the JSON of a dereferenced document (every $ref inlined, components.schemas retained). Parse decodes it once (returning ErrParse on bad JSON; it normalizes OpenAPI 3.0 nullable: true to a null-permitting type). The returned *Schemas then composes self-contained schemas: ParamsSchema / ParamSchema (optionally a named subset), BodySchema (application/json request body), Ref (named component), OutputObject / OutputItems / OutputValue (response wrappers), and Summary. Returned schemas are deep-cloned, so callers and the SDK may mutate them freely.

Only Parse returns an error. The composition methods instead panic (wrapping ErrUndefined) on an unknown name/path/operation/parameter — these are static, programmer-level mistakes, surfaced loudly rather than threaded through every call site.

Index

Constants

This section is empty.

Variables

View Source
var ErrParse = errors.New("openapi parse")

ErrParse is wrapped with the decode error when Parse cannot decode the doc.

View Source
var ErrUndefined = errors.New("openapi undefined")

ErrUndefined is wrapped in the panic value for an unknown name/path/op/param.

Functions

func Object

func Object(
	properties map[string]*jsonschema.Schema,
	required []string,
) *jsonschema.Schema

Object assembles an object schema from properties and required field names.

func OutputValue

func OutputValue(jsonType string) *jsonschema.Schema

OutputValue builds a scalar-response output schema, wrapped under "value".

Types

type Schemas

type Schemas struct {
	// contains filtered or unexported fields
}

Schemas assembles per-tool JSON Schemas from a parsed OpenAPI document.

func Parse

func Parse(doc []byte) (*Schemas, error)

Parse decodes a dereferenced OpenAPI doc; wraps ErrParse on invalid JSON.

func (*Schemas) BodySchema

func (s *Schemas) BodySchema(method, path string) *jsonschema.Schema

BodySchema clones an op's application/json request-body schema; panics if the op is unknown or has no application/json request body.

func (*Schemas) OutputItems

func (s *Schemas) OutputItems(name string) *jsonschema.Schema

OutputItems builds a slice-response output schema, wrapped under "items".

func (*Schemas) OutputObject

func (s *Schemas) OutputObject(name string) *jsonschema.Schema

OutputObject builds an object-response output schema from the named component; panics if name is unknown or the component is not an object.

func (*Schemas) ParamSchema

func (s *Schemas) ParamSchema(method, path, name string) *jsonschema.Schema

ParamSchema returns a single parameter's schema; panics if not found.

func (*Schemas) ParamsSchema

func (s *Schemas) ParamsSchema(
	method, path string,
	names ...string,
) *jsonschema.Schema

ParamsSchema builds an input schema from an op's params (all, or a named subset); panics if the op is unknown or a requested name is not a param.

func (*Schemas) Ref

func (s *Schemas) Ref(name string) *jsonschema.Schema

Ref returns a deep clone of the component named by name; panics if unknown.

func (*Schemas) Summary

func (s *Schemas) Summary(method, path string) string

Summary returns an operation's one-line summary; panics if the op is unknown.

Jump to

Keyboard shortcuts

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