openapi

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeRequest

func DecodeRequest(r *http.Request, decoder Decoder, body any, args ...any) error

func EncodeResponse

func EncodeResponse[T Success](w http.ResponseWriter, encoder Encoder, value any, status *T)

func GetEncDec

func GetEncDec(w http.ResponseWriter, r *http.Request) (Encoder, Decoder)

func GetStatus

func GetStatus[T Success](object *T) int

Types

type Accepted

type Accepted struct {
	Header http.Header
}

func (Accepted) HttpStatus

func (Accepted) HttpStatus() int

type Context

type Context struct {
	Request *http.Request
}

func (Context) Deadline

func (c Context) Deadline() (deadline time.Time, ok bool)

func (Context) Done

func (c Context) Done() <-chan struct{}

Done implements context.Context.

func (Context) Err

func (c Context) Err() error

Err implements context.Context.

func (Context) Value

func (c Context) Value(key any) any

Value implements context.Context.

type Created

type Created struct {
	Header http.Header
}

func (Created) HttpStatus

func (Created) HttpStatus() int

type Decoder

type Decoder interface {
	Decode(v any) error
}

type Encoder

type Encoder interface {
	Encode(v any) error
}

type HandleFunc1

type HandleFunc1[H any, S Success] func(ctx Context, in H) (*S, error)

func (HandleFunc1[H, S]) ServeHTTP

func (f HandleFunc1[H, S]) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HandleFunc2

type HandleFunc2[H, B any, S Success] func(ctx Context, in Request[H, B]) (*S, error)

func (HandleFunc2[H, B, S]) ServeHTTP

func (f HandleFunc2[H, B, S]) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HandleFunc3

type HandleFunc3[H, B, R any, S Success] func(ctx Context, in Request[H, B], out *R) (*S, error)

func (HandleFunc3[H, B, R, S]) ServeHTTP

func (f HandleFunc3[H, B, R, S]) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HandleFunc4

type HandleFunc4[H, V any, S Success] func(ctx Context, in H, out *V) (*S, error)

func (HandleFunc4[H, V, R]) ServeHTTP

func (f HandleFunc4[H, V, R]) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HandleFunc5

type HandleFunc5[H, B any] func(ctx Context, in Request[H, B]) (*NoContent, error)

func (HandleFunc5[H, B]) ServeHTTP

func (f HandleFunc5[H, B]) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HttpResponse

type HttpResponse interface {
	HttpResponse() errors.HttpResponse
}

type HttpStatus

type HttpStatus interface {
	HttpStatus() int
}

type NoContent

type NoContent struct {
	Header http.Header
}

func (NoContent) HttpStatus

func (NoContent) HttpStatus() int

type OK

type OK struct {
	Header http.Header
}

func (OK) HttpStatus

func (OK) HttpStatus() int

type Operation

type Operation struct {
	http.Handler

	ID          string
	Summary     string
	Description string
	Tags        []string

	Header    any
	Request   any
	Responses map[int]any

	Errors   []error
	Security []string
	// contains filtered or unexported fields
}

func DeleteHandler

func DeleteHandler[T any, S Success](
	handler HandleFunc1[T, S],
	id string,
	summary string,
	tags []string,
) *Operation

func GetHandler

func GetHandler[H, V any, S Success](
	handler HandleFunc4[H, V, S],
	id string,
	summary string,
	tags []string,
) *Operation

func Handle

func Handle(
	handler http.Handler,
	options ...OperationFunc,
) *Operation

func Handlers

func Handlers(operation *Operation, fn ...func(http.Handler) http.Handler) *Operation

func NewOp1

func NewOp1[H any, S Success](
	handler HandleFunc1[H, S],
	options ...OperationFunc,
) *Operation

func NewOp2

func NewOp2[H, B any, S Success](
	handler HandleFunc2[H, B, S],
	options ...OperationFunc,
) *Operation

func NewOp3

func NewOp3[H, B, R any, S Success](
	handler HandleFunc3[H, B, R, S],
	options ...OperationFunc,
) *Operation

NewOp3 define new operation with H path, query and header fields B request Body R response Body S if no err return from handler then return success

func NewOp4

func NewOp4[H, R any, S Success](
	handler HandleFunc4[H, R, S],
	options ...OperationFunc,
) *Operation

NewOp4 define new operation with H path, query and header fields R response Body S if no err return from handler then return success This usable in GET requests.

func NewOp5

func NewOp5[H, B any](
	handler HandleFunc5[H, B],
	options ...OperationFunc,
) *Operation

NewOp5 define new operation with H path, query and header fields R response Body S if no err return from handler then return success This usable in GET requests.

func PutHandler

func PutHandler[H, B, V any, S Success](
	handler HandleFunc3[H, B, V, S],
	id string,
	summary string,
	tags []string,
) *Operation

func Security

func Security(operation *Operation, s ...string) *Operation

func (*Operation) OperationContext

func (o *Operation) OperationContext(
	reflector *openapi3.Reflector,
	method string,
	route string,
) (openapi.OperationContext, error)

type OperationFunc

type OperationFunc func(*Operation)

func WithDescription

func WithDescription(description string) OperationFunc

func WithErrors

func WithErrors(errors ...error) OperationFunc

func WithHandlers

func WithHandlers(handlers ...func(http.Handler) http.Handler) OperationFunc

func WithHeader

func WithHeader(object any) OperationFunc

func WithID

func WithID(id string) OperationFunc

func WithRequest

func WithRequest(object any) OperationFunc

func WithResponse

func WithResponse(status int, object any) OperationFunc

func WithSecurity

func WithSecurity(methods ...string) OperationFunc

func WithSummary

func WithSummary(summary string) OperationFunc

func WithTags

func WithTags(tags ...string) OperationFunc

type Request

type Request[T any, V any] struct {
	Header T
	Body   V
}

type Success

type Success interface {
	OK | Created | Accepted | NoContent
}

Jump to

Keyboard shortcuts

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