Documentation
¶
Index ¶
- Constants
- Variables
- func NewExtendable[T any](t *T) *openapi.Extendable[T]
- func NewParameter() param.Parameter
- func RegisterType[T any](spec *OpenAPI, schema jsonschema.Schema, opts ...jsonschema.Option) error
- func SchemaFromOp(op Operation, contentType string) (jsonschema.Schema, error)
- func SetDefaultResponse[T any](spec *OpenAPI, code int, contentType ...string)
- type AddSpecToRouterOpts
- type ComponentSchema
- type Components
- type Context
- type Info
- type JSON
- type MediaType
- type OpenAPI
- func (o OpenAPI) GetComponents() Components
- func (o OpenAPI) GetDefaultResponse(code int) (Response, bool)
- func (o OpenAPI) GetPath(name string) (PathItem, bool)
- func (o OpenAPI) GetSchemaOrRef(obj any, opts SchemaRefOptions) (*openapi.RefOrSpec[openapi.Schema], error)
- func (o OpenAPI) SetDefaultResponse(code int, resp Response)
- func (o OpenAPI) SetPath(name string, pathItem PathItem)
- type Operation
- func (o *Operation) AddParameter(param param.Parameter)
- func (o *Operation) AddResponse(code int, schema Response)
- func (o *Operation) GetParameter(name, in string) (param.Parameter, bool)
- func (o *Operation) HasParameter(param param.Parameter) bool
- func (o *Operation) SetDefaultResponse(resp Response)
- func (o *Operation) SetRequestBody(body RequestBody)
- type Parameter
- type PathItem
- type PathOperation
- type Query
- type RequestBody
- type Response
- type Schema
- type SchemaRefOptions
- type Tag
Constants ¶
View Source
const JSONContentType = "application/json"
Variables ¶
View Source
var ( ErrNoOperationID = errors.New("operation id required") ErrDuplicateOperationID = errors.New("operation id already exists") )
View Source
var ErrAlreadyExists = errors.New("already exists in the schema")
View Source
var ErrNoContext = errors.New("openapi3.Context not found in OptionsContext")
View Source
var ErrRequestBodyMissingSchema = errors.New("no schema or ref on request body")
Functions ¶
func NewExtendable ¶
func NewExtendable[T any](t *T) *openapi.Extendable[T]
func NewParameter ¶
func RegisterType ¶
func RegisterType[T any](spec *OpenAPI, schema jsonschema.Schema, opts ...jsonschema.Option) error
RegisterType set the types schema in the spec. If the schema allows references, it will be added to the specs components.
func SchemaFromOp ¶
func SchemaFromOp(op Operation, contentType string) (jsonschema.Schema, error)
SchemaFromOp takes an operation and returns a json schema that can be used to validate a request.
Types ¶
type AddSpecToRouterOpts ¶
type ComponentSchema ¶
type ComponentSchema struct {
jsonschema.Schema
Name string
}
type Components ¶
type Components struct {
*openapi.Components
}
func (Components) AddResponse ¶
func (c Components) AddResponse(name string, resp Response)
func (Components) AddSchema ¶
func (c Components) AddSchema(name string, schema jsonschema.Schema) error
func (Components) GetResponse ¶
func (c Components) GetResponse(name string) (Response, bool)
func (Components) GetSchemaByName ¶
func (c Components) GetSchemaByName(name string) (Schema, bool)
type Context ¶
type MediaType ¶
func NewMediaType ¶
func NewMediaType() MediaType
func (*MediaType) SetSchema ¶
func (m *MediaType) SetSchema(schema jsonschema.Schema)
func (*MediaType) SetSchemaRef ¶
type OpenAPI ¶
type OpenAPI struct {
*openapi.OpenAPI
Schemer jsonschema.Schemer `json:"-"`
DefaultContentType string `json:"-"`
Strict bool `json:"-"`
}
func AddSpecToRouter ¶
func AddSpecToRouter(r *routey.Router, opts AddSpecToRouterOpts) *OpenAPI
func (OpenAPI) GetComponents ¶
func (o OpenAPI) GetComponents() Components
func (OpenAPI) GetSchemaOrRef ¶
func (o OpenAPI) GetSchemaOrRef( obj any, opts SchemaRefOptions, ) (*openapi.RefOrSpec[openapi.Schema], error)
GetSchemaOrRef creates and adds returns a schema or a ref to the created schema. If a ref is returned then the schema will be added to the specs components.
func (OpenAPI) SetDefaultResponse ¶
type Operation ¶
func NewOperation ¶
func NewOperation() Operation
func OperationFromCtx ¶
func (*Operation) AddParameter ¶
func (*Operation) AddResponse ¶
func (*Operation) GetParameter ¶
func (*Operation) SetDefaultResponse ¶
func (*Operation) SetRequestBody ¶
func (o *Operation) SetRequestBody(body RequestBody)
type PathItem ¶
func NewPathItem ¶
func NewPathItem() PathItem
func (PathItem) GetOperations ¶
func (p PathItem) GetOperations() []PathOperation
func (PathItem) SetOperation ¶
type PathOperation ¶
type RequestBody ¶
type RequestBody struct {
openapi.RequestBody
}
func (*RequestBody) SetContent ¶
func (r *RequestBody) SetContent(typ string, mediaType MediaType)
type Response ¶
func (*Response) SetContent ¶
type Schema ¶
func (Schema) JSONSchema ¶
func (s Schema) JSONSchema() jsonschema.Schema
type SchemaRefOptions ¶
type SchemaRefOptions struct {
// ForceNoRef prevents creating a reference even if the schema would normally be referenced
ForceNoRef bool
// IgnoreAddSchemaErrors continues processing even if AddSchema fails
IgnoreAddSchemaErrors bool
}
SchemaRefOptions configures how schema references are handled.
Click to show internal directories.
Click to hide internal directories.