Documentation
¶
Index ¶
- func Inject(opts []openapi.HandlerOption, def RouteDef) []openapi.HandlerOption
- func Key(method, path string) string
- type Builder
- type EchoGroup
- func (g *EchoGroup) DELETE(path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
- func (g *EchoGroup) GET(path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
- func (g *EchoGroup) Handle(method, path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
- func (g *EchoGroup) PATCH(path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
- func (g *EchoGroup) POST(path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
- func (g *EchoGroup) PUT(path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
- type EchoRouter
- func (r *EchoRouter) DELETE(path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
- func (r *EchoRouter) GET(path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
- func (r *EchoRouter) Group(prefix string, opts ...echoadapter.HandlerOption) *EchoGroup
- func (r *EchoRouter) Handle(method, path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
- func (r *EchoRouter) PATCH(path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
- func (r *EchoRouter) POST(path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
- func (r *EchoRouter) PUT(path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
- func (r *EchoRouter) Routes() []openapi.RouteMeta
- type FiberGroup
- func (g *FiberGroup) DELETE(path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
- func (g *FiberGroup) GET(path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
- func (g *FiberGroup) Handle(method, path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
- func (g *FiberGroup) PATCH(path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
- func (g *FiberGroup) POST(path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
- func (g *FiberGroup) PUT(path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
- type FiberRouter
- func (r *FiberRouter) DELETE(path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
- func (r *FiberRouter) GET(path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
- func (r *FiberRouter) Group(prefix string, opts ...fiberadapter.HandlerOption) *FiberGroup
- func (r *FiberRouter) Handle(method, path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
- func (r *FiberRouter) PATCH(path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
- func (r *FiberRouter) POST(path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
- func (r *FiberRouter) PUT(path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
- func (r *FiberRouter) Routes() []openapi.RouteMeta
- type GinGroup
- func (g *GinGroup) DELETE(path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
- func (g *GinGroup) GET(path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
- func (g *GinGroup) Handle(method, path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
- func (g *GinGroup) PATCH(path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
- func (g *GinGroup) POST(path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
- func (g *GinGroup) PUT(path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
- type GinRouter
- func (r *GinRouter) DELETE(path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
- func (r *GinRouter) GET(path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
- func (r *GinRouter) Group(prefix string, opts ...ginadapter.HandlerOption) *GinGroup
- func (r *GinRouter) Handle(method, path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
- func (r *GinRouter) PATCH(path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
- func (r *GinRouter) POST(path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
- func (r *GinRouter) PUT(path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
- func (r *GinRouter) Routes() []openapi.RouteMeta
- type RouteBuilder
- func (r *RouteBuilder) Created() *RouteBuilder
- func (r *RouteBuilder) Done() *RouteBuilder
- func (r *RouteBuilder) Headers(params ...openapi.HeaderParam) *RouteBuilder
- func (r *RouteBuilder) MultipartUpload(fileField string, fields ...openapi.MultipartField) *RouteBuilder
- func (r *RouteBuilder) NoContent() *RouteBuilder
- func (r *RouteBuilder) OK() *RouteBuilder
- func (r *RouteBuilder) Query(params ...openapi.QueryParam) *RouteBuilder
- func (r *RouteBuilder) Req(schema any) *RouteBuilder
- func (r *RouteBuilder) Res(schema any) *RouteBuilder
- func (r *RouteBuilder) Responses(specs ...openapi.ResponseSpec) *RouteBuilder
- func (r *RouteBuilder) Security(sec *openapi3.SecurityRequirement) *RouteBuilder
- func (r *RouteBuilder) Status(status int) *RouteBuilder
- func (r *RouteBuilder) Tags(tags ...string) *RouteBuilder
- type RouteDef
- type Router
- func (r *Router) DELETE(path string, h http.HandlerFunc, opts ...openapi.HandlerOption)
- func (r *Router) GET(path string, h http.HandlerFunc, opts ...openapi.HandlerOption)
- func (r *Router) Group(prefix string, opts ...openapi.HandlerOption) *openapi.Group
- func (r *Router) Handle(method, path string, h http.HandlerFunc, opts ...openapi.HandlerOption)
- func (r *Router) PATCH(path string, h http.HandlerFunc, opts ...openapi.HandlerOption)
- func (r *Router) POST(path string, h http.HandlerFunc, opts ...openapi.HandlerOption)
- func (r *Router) PUT(path string, h http.HandlerFunc, opts ...openapi.HandlerOption)
- func (r *Router) Routes() []openapi.RouteMeta
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- type Spec
- type SpecBuilder
- func (s *SpecBuilder) DELETE(p string) *RouteBuilder
- func (s *SpecBuilder) GET(p string) *RouteBuilder
- func (s *SpecBuilder) PATCH(p string) *RouteBuilder
- func (s *SpecBuilder) POST(p string) *RouteBuilder
- func (s *SpecBuilder) PUT(p string) *RouteBuilder
- func (s *SpecBuilder) WithTags(tags ...string) *SpecBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Inject ¶
func Inject(opts []openapi.HandlerOption, def RouteDef) []openapi.HandlerOption
Inject converts a RouteDef into route options.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder helps you build a Spec without manually typing keys like "GET /users/:id".
Example:
spec := oas.NewSpec().
Group("/", func(s *oas.SpecBuilder) {
s.GET("/users").Tags("Users").Res([]User{}).OK()
s.POST("/users").Tags("Users").Req(CreateUser{}).Res(struct{}{}).Status(http.StatusCreated)
})
Spec()
NOTE: This builder does not try to infer schemas from handlers. You still declare Req/Res schema samples here.
func (*Builder) Group ¶
func (b *Builder) Group(prefix string, fn func(s *SpecBuilder)) *Builder
Group helps apply a path prefix to multiple routes.
type EchoGroup ¶
type EchoGroup struct {
// contains filtered or unexported fields
}
func (*EchoGroup) DELETE ¶
func (g *EchoGroup) DELETE(path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
func (*EchoGroup) GET ¶
func (g *EchoGroup) GET(path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
func (*EchoGroup) Handle ¶
func (g *EchoGroup) Handle(method, path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
func (*EchoGroup) PATCH ¶
func (g *EchoGroup) PATCH(path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
func (*EchoGroup) POST ¶
func (g *EchoGroup) POST(path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
func (*EchoGroup) PUT ¶
func (g *EchoGroup) PUT(path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
type EchoRouter ¶
type EchoRouter struct {
Base *echoadapter.Router
Spec Spec
}
EchoRouter wraps the echo adapter Router and injects options from Spec automatically.
func NewEchoRouter ¶
func NewEchoRouter(base *echoadapter.Router, spec Spec) *EchoRouter
func (*EchoRouter) DELETE ¶
func (r *EchoRouter) DELETE(path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
func (*EchoRouter) GET ¶
func (r *EchoRouter) GET(path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
func (*EchoRouter) Group ¶
func (r *EchoRouter) Group(prefix string, opts ...echoadapter.HandlerOption) *EchoGroup
func (*EchoRouter) Handle ¶
func (r *EchoRouter) Handle(method, path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
func (*EchoRouter) PATCH ¶
func (r *EchoRouter) PATCH(path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
func (*EchoRouter) POST ¶
func (r *EchoRouter) POST(path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
func (*EchoRouter) PUT ¶
func (r *EchoRouter) PUT(path string, h echolib.HandlerFunc, opts ...echoadapter.HandlerOption)
func (*EchoRouter) Routes ¶
func (r *EchoRouter) Routes() []openapi.RouteMeta
type FiberGroup ¶
type FiberGroup struct {
// contains filtered or unexported fields
}
func (*FiberGroup) DELETE ¶
func (g *FiberGroup) DELETE(path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
func (*FiberGroup) GET ¶
func (g *FiberGroup) GET(path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
func (*FiberGroup) Handle ¶
func (g *FiberGroup) Handle(method, path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
func (*FiberGroup) PATCH ¶
func (g *FiberGroup) PATCH(path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
func (*FiberGroup) POST ¶
func (g *FiberGroup) POST(path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
func (*FiberGroup) PUT ¶
func (g *FiberGroup) PUT(path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
type FiberRouter ¶
type FiberRouter struct {
Base *fiberadapter.Router
Spec Spec
}
FiberRouter wraps the fiber adapter Router and injects options from Spec automatically.
func NewFiberRouter ¶
func NewFiberRouter(base *fiberadapter.Router, spec Spec) *FiberRouter
func (*FiberRouter) DELETE ¶
func (r *FiberRouter) DELETE(path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
func (*FiberRouter) GET ¶
func (r *FiberRouter) GET(path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
func (*FiberRouter) Group ¶
func (r *FiberRouter) Group(prefix string, opts ...fiberadapter.HandlerOption) *FiberGroup
func (*FiberRouter) Handle ¶
func (r *FiberRouter) Handle(method, path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
func (*FiberRouter) PATCH ¶
func (r *FiberRouter) PATCH(path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
func (*FiberRouter) POST ¶
func (r *FiberRouter) POST(path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
func (*FiberRouter) PUT ¶
func (r *FiberRouter) PUT(path string, h fiberlib.Handler, opts ...fiberadapter.HandlerOption)
func (*FiberRouter) Routes ¶
func (r *FiberRouter) Routes() []openapi.RouteMeta
type GinGroup ¶
type GinGroup struct {
// contains filtered or unexported fields
}
GinGroup provides grouping with prefix + shared options, while preserving Spec injection.
func (*GinGroup) DELETE ¶
func (g *GinGroup) DELETE(path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
func (*GinGroup) GET ¶
func (g *GinGroup) GET(path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
func (*GinGroup) Handle ¶
func (g *GinGroup) Handle(method, path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
func (*GinGroup) PATCH ¶
func (g *GinGroup) PATCH(path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
func (*GinGroup) POST ¶
func (g *GinGroup) POST(path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
func (*GinGroup) PUT ¶
func (g *GinGroup) PUT(path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
type GinRouter ¶
type GinRouter struct {
Base *ginadapter.Router
Spec Spec
}
GinRouter wraps the gin adapter Router and injects options from Spec automatically.
func NewGinRouter ¶
func NewGinRouter(base *ginadapter.Router, spec Spec) *GinRouter
func (*GinRouter) DELETE ¶
func (r *GinRouter) DELETE(path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
func (*GinRouter) GET ¶
func (r *GinRouter) GET(path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
func (*GinRouter) Group ¶
func (r *GinRouter) Group(prefix string, opts ...ginadapter.HandlerOption) *GinGroup
func (*GinRouter) Handle ¶
func (r *GinRouter) Handle(method, path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
func (*GinRouter) PATCH ¶
func (r *GinRouter) PATCH(path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
func (*GinRouter) POST ¶
func (r *GinRouter) POST(path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
func (*GinRouter) PUT ¶
func (r *GinRouter) PUT(path string, h ginlib.HandlerFunc, opts ...ginadapter.HandlerOption)
type RouteBuilder ¶
type RouteBuilder struct {
// contains filtered or unexported fields
}
RouteBuilder builds a single route definition.
func (*RouteBuilder) Created ¶
func (r *RouteBuilder) Created() *RouteBuilder
Created is shorthand for Status(http.StatusCreated).
func (*RouteBuilder) Done ¶
func (r *RouteBuilder) Done() *RouteBuilder
Done commits the current definition without changing status. Use this if you only want tags/security/query and no schema.
func (*RouteBuilder) Headers ¶
func (r *RouteBuilder) Headers(params ...openapi.HeaderParam) *RouteBuilder
func (*RouteBuilder) MultipartUpload ¶
func (r *RouteBuilder) MultipartUpload(fileField string, fields ...openapi.MultipartField) *RouteBuilder
MultipartUpload declares a multipart/form-data request body with a required file field.
Example:
s.POST("/users/upload").MultipartUpload("file", openapi.MultipartField{Name: "note", Type: openapi.ParamString}).Res(map[string]string{}).OK()
Under the hood this uses openapi.MultipartFile marker so the OpenAPI builder can render multipart/form-data with binary file part.
func (*RouteBuilder) NoContent ¶
func (r *RouteBuilder) NoContent() *RouteBuilder
NoContent is shorthand for Status(http.StatusNoContent).
func (*RouteBuilder) OK ¶
func (r *RouteBuilder) OK() *RouteBuilder
OK is shorthand for Status(http.StatusOK).
func (*RouteBuilder) Query ¶
func (r *RouteBuilder) Query(params ...openapi.QueryParam) *RouteBuilder
func (*RouteBuilder) Req ¶
func (r *RouteBuilder) Req(schema any) *RouteBuilder
func (*RouteBuilder) Res ¶
func (r *RouteBuilder) Res(schema any) *RouteBuilder
func (*RouteBuilder) Responses ¶
func (r *RouteBuilder) Responses(specs ...openapi.ResponseSpec) *RouteBuilder
Responses appends additional response specs (like 400/500 error shape).
func (*RouteBuilder) Security ¶
func (r *RouteBuilder) Security(sec *openapi3.SecurityRequirement) *RouteBuilder
func (*RouteBuilder) Status ¶
func (r *RouteBuilder) Status(status int) *RouteBuilder
func (*RouteBuilder) Tags ¶
func (r *RouteBuilder) Tags(tags ...string) *RouteBuilder
type RouteDef ¶
type RouteDef struct {
Tags []string
Security *openapi3.SecurityRequirement
QueryParams []openapi.QueryParam
HeaderParams []openapi.HeaderParam
ReqSchema any
ResSchema any
Status int
// Optional extra responses (errors, alternate status codes)
Responses []openapi.ResponseSpec
}
RouteDef is a config-only description of an endpoint.
This is the "SpringBoot-like" mode: keep handlers/routes clean, put OpenAPI request/response schema + tags/security/query definition in one config place.
Note: request/response schema inference is not possible from plain Go handlers, so you still need to declare them here (or omit them).
If ReqSchema/ResSchema is nil, schema isn't declared.
type Router ¶
Router wraps an openapi.Router and injects options from Spec automatically. Your route registrations can stay as plain GET/POST/... without JSONRoute/With... per route.
func (*Router) DELETE ¶
func (r *Router) DELETE(path string, h http.HandlerFunc, opts ...openapi.HandlerOption)
func (*Router) GET ¶
func (r *Router) GET(path string, h http.HandlerFunc, opts ...openapi.HandlerOption)
func (*Router) Handle ¶
func (r *Router) Handle(method, path string, h http.HandlerFunc, opts ...openapi.HandlerOption)
func (*Router) PATCH ¶
func (r *Router) PATCH(path string, h http.HandlerFunc, opts ...openapi.HandlerOption)
func (*Router) POST ¶
func (r *Router) POST(path string, h http.HandlerFunc, opts ...openapi.HandlerOption)
func (*Router) PUT ¶
func (r *Router) PUT(path string, h http.HandlerFunc, opts ...openapi.HandlerOption)
type SpecBuilder ¶
type SpecBuilder struct {
// contains filtered or unexported fields
}
SpecBuilder is a scoped builder that can apply a prefix.
func (*SpecBuilder) DELETE ¶
func (s *SpecBuilder) DELETE(p string) *RouteBuilder
func (*SpecBuilder) GET ¶
func (s *SpecBuilder) GET(p string) *RouteBuilder
func (*SpecBuilder) PATCH ¶
func (s *SpecBuilder) PATCH(p string) *RouteBuilder
func (*SpecBuilder) POST ¶
func (s *SpecBuilder) POST(p string) *RouteBuilder
func (*SpecBuilder) PUT ¶
func (s *SpecBuilder) PUT(p string) *RouteBuilder
func (*SpecBuilder) WithTags ¶
func (s *SpecBuilder) WithTags(tags ...string) *SpecBuilder
WithTags sets default tags for all routes built from this builder.