openapi3

package
v0.0.0-...-9a508a9 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

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 NewParameter() param.Parameter

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.

func SetDefaultResponse

func SetDefaultResponse[T any](spec *OpenAPI, code int, contentType ...string)

Types

type AddSpecToRouterOpts

type AddSpecToRouterOpts struct {
	DefaultContentType string
	ValidateRequests   bool
	// Strict determines whether or not an error is thrown
	// if required properties are not set on OpenAPI resources.
	Strict bool
}

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 Context struct {
	OpenAPI   *OpenAPI
	Validator *jsonschema.Validator
	Namer     param.Namer
	Parser    param.Parser
}

func ContextFromCtx

func ContextFromCtx(ctx route.Context) (Context, error)

type Info

type Info = openapi.Info

type JSON

type JSON[T any] struct {
	routey.JSON[T]
}

func (*JSON[T]) Extract

func (q *JSON[T]) Extract(r *http.Request, info *route.Info) error

type MediaType

type MediaType struct {
	openapi.MediaType
}

func NewMediaType

func NewMediaType() MediaType

func (*MediaType) SetSchema

func (m *MediaType) SetSchema(schema jsonschema.Schema)

func (*MediaType) SetSchemaRef

func (m *MediaType) SetSchemaRef(ref string)

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 New

func New() *OpenAPI

func NewRouter

func NewRouter() (*routey.Router, *OpenAPI)

func (OpenAPI) GetComponents

func (o OpenAPI) GetComponents() Components

func (OpenAPI) GetDefaultResponse

func (o OpenAPI) GetDefaultResponse(code int) (Response, bool)

func (OpenAPI) GetPath

func (o OpenAPI) GetPath(name string) (PathItem, bool)

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

func (o OpenAPI) SetDefaultResponse(code int, resp Response)

func (OpenAPI) SetPath

func (o OpenAPI) SetPath(name string, pathItem PathItem)

SetPath overrides any existing paths if they exist, if not it creates the pathItem.

type Operation

type Operation struct {
	*openapi.Operation

	Ignore bool `json:"-"`
}

func NewOperation

func NewOperation() Operation

func OperationFromCtx

func OperationFromCtx(ctx route.Context) *Operation

func (*Operation) AddParameter

func (o *Operation) AddParameter(param param.Parameter)

func (*Operation) AddResponse

func (o *Operation) AddResponse(code int, schema Response)

func (*Operation) GetParameter

func (o *Operation) GetParameter(name, in string) (param.Parameter, bool)

func (*Operation) HasParameter

func (o *Operation) HasParameter(param param.Parameter) bool

func (*Operation) SetDefaultResponse

func (o *Operation) SetDefaultResponse(resp Response)

func (*Operation) SetRequestBody

func (o *Operation) SetRequestBody(body RequestBody)

type Parameter

type Parameter = param.Parameter

type PathItem

type PathItem struct {
	*openapi.PathItem
}

func NewPathItem

func NewPathItem() PathItem

func (PathItem) GetOperation

func (p PathItem) GetOperation(method string) (Operation, bool)

func (PathItem) GetOperations

func (p PathItem) GetOperations() []PathOperation

func (PathItem) SetOperation

func (p PathItem) SetOperation(method string, operation Operation)

type PathOperation

type PathOperation struct {
	Operation Operation
	Method    string
}

type Query

type Query[T any] struct {
	routey.Query[T]
}

func (*Query[T]) CanParse

func (q *Query[T]) CanParse(
	parser param.Parser,
	source reflect.StructField,
	value any,
) error

func (*Query[T]) Extract

func (q *Query[T]) Extract(r *http.Request, info *route.Info, opts param.Opts) error

type RequestBody

type RequestBody struct {
	openapi.RequestBody
}

func (*RequestBody) SetContent

func (r *RequestBody) SetContent(typ string, mediaType MediaType)

type Response

type Response struct {
	openapi.Response
}

func (*Response) SetContent

func (r *Response) SetContent(typ string, mediaType MediaType)

type Schema

type Schema struct {
	*openapi.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.

type Tag

type Tag struct {
	*openapi.Extendable[openapi.Tag]
}

func NewTag

func NewTag() Tag

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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