openapi

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package openapi builds tool schemas from a dereferenced OpenAPI document.

Parse accepts JSON and supports OpenAPI 3.0 nullable fields. Schema accessors return independent clones. Parse returns ErrParse for invalid JSON. Accessors panic with ErrUndefined for unknown document elements.

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 Int64StringSchema added in v0.7.0

func Int64StringSchema(description string) *jsonschema.Schema

Int64StringSchema returns a decimal-string schema with description.

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".

func StringifyIntParam added in v0.7.0

func StringifyIntParam(s *jsonschema.Schema, name string) *jsonschema.Schema

StringifyIntParam rewrites a property as Int64String and preserves its text.

Types

type Int64String added in v0.7.0

type Int64String int64

Int64String encodes an int64 as a decimal string without precision loss.

func (Int64String) Int64 added in v0.7.0

func (v Int64String) Int64() int64

Int64 returns the underlying value for passing to int64-typed APIs.

func (Int64String) MarshalJSON added in v0.7.0

func (v Int64String) MarshalJSON() ([]byte, error)

MarshalJSON emits the value as a quoted decimal string.

func (*Int64String) UnmarshalJSON added in v0.7.0

func (v *Int64String) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts only a quoted decimal int64.

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 returns the JSON body schema and panics if it does not exist.

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 returns an object component and panics if it 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 returns all or selected parameters and rejects unknown names.

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