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 ¶
- Variables
- func Object(properties map[string]*jsonschema.Schema, required []string) *jsonschema.Schema
- func OutputValue(jsonType string) *jsonschema.Schema
- type Schemas
- func (s *Schemas) BodySchema(method, path string) *jsonschema.Schema
- func (s *Schemas) OutputItems(name string) *jsonschema.Schema
- func (s *Schemas) OutputObject(name string) *jsonschema.Schema
- func (s *Schemas) ParamSchema(method, path, name string) *jsonschema.Schema
- func (s *Schemas) ParamsSchema(method, path string, names ...string) *jsonschema.Schema
- func (s *Schemas) Ref(name string) *jsonschema.Schema
- func (s *Schemas) Summary(method, path string) string
Constants ¶
This section is empty.
Variables ¶
var ErrParse = errors.New("openapi parse")
ErrParse is wrapped with the decode error when Parse cannot decode the doc.
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 (*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.