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 ¶
- Variables
- func Int64StringSchema(description string) *jsonschema.Schema
- func Object(properties map[string]*jsonschema.Schema, required []string) *jsonschema.Schema
- func OutputValue(jsonType string) *jsonschema.Schema
- func StringifyIntParam(s *jsonschema.Schema, name string) *jsonschema.Schema
- type Int64String
- 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 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 (*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.