Documentation
¶
Index ¶
- func APIKeyAuth(name, in string) *openapi3.SecurityScheme
- func BasicAuth() *openapi3.SecurityScheme
- func BearerAuth() *openapi3.SecurityScheme
- func CustomAuth(scheme *openapi3.SecurityScheme) *openapi3.SecurityScheme
- func OIDCAuth(url string) *openapi3.SecurityScheme
- type Model
- type Option
- type Rest
- func (r *Rest) AddSecurityScheme(name string, scheme *openapi3.SecurityScheme) *Rest
- func (r *Rest) Delete(path string) *Route
- func (r *Rest) Get(path string) *Route
- func (r *Rest) Head(path string) *Route
- func (r *Rest) JSON() ([]byte, error)
- func (r *Rest) OpenAPI() (*openapi3.T, error)
- func (r *Rest) Options(path string) *Route
- func (r *Rest) Patch(path string) *Route
- func (r *Rest) Post(path string) *Route
- func (r *Rest) Put(path string) *Route
- func (r *Rest) Routes() []*Route
- func (r *Rest) SetDefaultSecurity(names ...string) *Rest
- func (r *Rest) WriteFile(path string) error
- func (r *Rest) YAML() ([]byte, error)
- type Route
- func (r *Route) HasDescription(s string) *Route
- func (r *Route) HasOperationId(s string) *Route
- func (r *Route) HasRequestModel(m Model) *Route
- func (r *Route) HasResponseModel(status int, m Model) *Route
- func (r *Route) HasSummary(s string) *Route
- func (r *Route) HasTags(tags ...string) *Route
- func (r *Route) IsDeprecated() *Route
- func (r *Route) RequireScopes(name string, scopes ...string) *Route
- func (r *Route) RequireSecurity(names ...string) *Route
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func APIKeyAuth ¶
func APIKeyAuth(name, in string) *openapi3.SecurityScheme
APIKeyAuth is an API key carried in "header", "query" or "cookie".
func BearerAuth ¶
func BearerAuth() *openapi3.SecurityScheme
BearerAuth is an HTTP bearer scheme carrying a JWT.
func CustomAuth ¶
func CustomAuth(scheme *openapi3.SecurityScheme) *openapi3.SecurityScheme
CustomAuth passes a scheme through untouched, for anything the helpers above do not cover (OAuth2 flows, for instance).
func OIDCAuth ¶
func OIDCAuth(url string) *openapi3.SecurityScheme
OIDCAuth is an OpenID Connect scheme discovered at the given URL.
Types ¶
type Model ¶
Model is a type-erased handle to a Go type used as a request or response payload. It carries no value, only the reflect.Type, so it is cheap to pass around and safe to reuse across routes.
type Option ¶
type Option func(*Rest)
Option configures a Rest instance at construction.
func WithDescription ¶
WithDescription sets the document description.
type Rest ¶
type Rest struct {
// contains filtered or unexported fields
}
Rest collects routes and renders them as an OpenAPI 3 document. It does not serve HTTP; it only describes it.
func New ¶
New creates a Rest instance. Title and version fall back to defaults, since OpenAPI requires both to be non-empty.
func (*Rest) AddSecurityScheme ¶
func (r *Rest) AddSecurityScheme(name string, scheme *openapi3.SecurityScheme) *Rest
AddSecurityScheme registers a scheme under a name that routes reference with Route.HasSecurity. It ends up in components.securitySchemes.
func (*Rest) OpenAPI ¶
OpenAPI renders the registered routes as an OpenAPI 3 document. The document is validated before it is returned, so mistakes surface here rather than in a consumer's UI.
func (*Rest) SetDefaultSecurity ¶
SetDefaultSecurity names the schemes that a bare Route.RequireSecurity() applies. Listing several means any one of them is sufficient.
It does not secure anything on its own: routes opt in. That is deliberate — a document-level `security` key would apply to every operation, and a route could then only be made public by explicitly overriding it back to empty.
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
Route is a single operation: one HTTP method at one path. Every method returns the Route so calls can be chained.
func (*Route) HasDescription ¶
HasDescription sets the operation's long description.
func (*Route) HasOperationId ¶
HasOperationId sets the operation's unique id.
func (*Route) HasRequestModel ¶
HasRequestModel sets the request payload. Fields tagged `json` become the request body; fields tagged `query`, `param` or `header` become parameters. A field may carry several of these tags, and untagged fields are ignored.
A field is required unless its type is nillable — a pointer, slice, map or interface can be absent, anything else cannot. Add `,optional` or `,required` to the tag where the type alone gets it wrong (`,omitempty` also means optional). Path parameters are always required.
func (*Route) HasResponseModel ¶
HasResponseModel sets the payload returned for the given status code.
func (*Route) HasSummary ¶
HasSummary sets the operation's short summary.
func (*Route) IsDeprecated ¶
IsDeprecated marks the operation as deprecated.
func (*Route) RequireScopes ¶
RequireScopes requires the named scheme with a set of scopes, for OAuth2 and OpenID Connect. Like RequireSecurity, repeating it records alternatives.
func (*Route) RequireSecurity ¶
RequireSecurity requires authentication for this route.
Called with no arguments it applies whatever Rest.SetDefaultSecurity named; with arguments it overrides that default for this route alone. Listing several schemes means any one of them is sufficient.
route.RequireSecurity() // the document default
route.RequireSecurity("apiKey") // this route uses an API key instead
Security is opt-in: a route that never calls this is public.