Documentation
¶
Overview ¶
Package openapi provides full OpenAPI 3.0 specification generation from Nimbus router routes. It introspects route metadata, reflects on Go types to build JSON Schema, and produces a complete OpenAPI document.
Index ¶
- type Components
- type Contact
- type FlowConfig
- type Generator
- type GeneratorConfig
- type Info
- type License
- type MediaType
- type OAuthFlow
- type Operation
- type Parameter
- type PathItem
- type Plugin
- type PluginConfig
- type PluginHandler
- type RequestBody
- type Response
- type Schema
- type SecurityScheme
- type Server
- type Spec
- type Tag
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Components ¶
type Components struct {
Schemas map[string]*Schema `json:"schemas,omitempty"`
SecuritySchemes map[string]*SecurityScheme `json:"securitySchemes,omitempty"`
}
Components holds reusable objects.
type Contact ¶
type Contact struct {
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
Email string `json:"email,omitempty"`
}
Contact information for the API.
type FlowConfig ¶
type FlowConfig struct {
AuthorizationURL string `json:"authorizationUrl,omitempty"`
TokenURL string `json:"tokenUrl,omitempty"`
RefreshURL string `json:"refreshUrl,omitempty"`
Scopes map[string]string `json:"scopes"`
}
FlowConfig holds OAuth2 flow details.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator builds an OpenAPI 3.0 spec from registered routes.
func NewGenerator ¶
func NewGenerator(cfg GeneratorConfig) *Generator
NewGenerator creates a new OpenAPI spec generator.
type GeneratorConfig ¶
type GeneratorConfig struct {
Title string
Description string
Version string
Servers []Server
Contact *Contact
License *License
// SecuritySchemes to include in components.
SecuritySchemes map[string]*SecurityScheme
// GlobalSecurity applied to all operations by default.
GlobalSecurity []map[string][]string
// ExcludePatterns defines path prefixes to skip (e.g. "/_").
ExcludePatterns []string
// TagDescriptions allows adding descriptions to tags.
TagDescriptions map[string]string
// BasePath prefix stripped from paths.
BasePath string
}
GeneratorConfig configures the OpenAPI spec generator.
type Info ¶
type Info struct {
Title string `json:"title"`
Description string `json:"description,omitempty"`
Version string `json:"version"`
TermsOfService string `json:"termsOfService,omitempty"`
Contact *Contact `json:"contact,omitempty"`
License *License `json:"license,omitempty"`
}
Info provides metadata about the API.
type MediaType ¶
type MediaType struct {
Schema *Schema `json:"schema,omitempty"`
}
MediaType provides schema and examples for the media type.
type OAuthFlow ¶
type OAuthFlow struct {
Implicit *FlowConfig `json:"implicit,omitempty"`
Password *FlowConfig `json:"password,omitempty"`
ClientCredentials *FlowConfig `json:"clientCredentials,omitempty"`
AuthorizationCode *FlowConfig `json:"authorizationCode,omitempty"`
}
OAuthFlow describes OAuth2 flow configuration.
type Operation ¶
type Operation struct {
OperationID string `json:"operationId,omitempty"`
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
Tags []string `json:"tags,omitempty"`
Parameters []Parameter `json:"parameters,omitempty"`
RequestBody *RequestBody `json:"requestBody,omitempty"`
Responses map[string]*Response `json:"responses"`
Security []map[string][]string `json:"security,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`
}
Operation describes a single API operation on a path.
type Parameter ¶
type Parameter struct {
Name string `json:"name"`
In string `json:"in"` // query, header, path, cookie
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
Schema *Schema `json:"schema,omitempty"`
}
Parameter describes a single operation parameter.
type PathItem ¶
type PathItem struct {
Get *Operation `json:"get,omitempty"`
Post *Operation `json:"post,omitempty"`
Put *Operation `json:"put,omitempty"`
Patch *Operation `json:"patch,omitempty"`
Delete *Operation `json:"delete,omitempty"`
Head *Operation `json:"head,omitempty"`
Options *Operation `json:"options,omitempty"`
}
PathItem holds operations on a single path.
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin serves OpenAPI/Swagger documentation as a Nimbus plugin.
func NewPlugin ¶
func NewPlugin(cfg ...PluginConfig) *Plugin
NewPlugin creates a new OpenAPI documentation plugin.
func (*Plugin) Boot ¶
Boot generates the OpenAPI spec and registers doc routes. This accepts the nimbus.App but we keep it interface-based to avoid import cycle.
func (*Plugin) InvalidateCache ¶
func (p *Plugin) InvalidateCache()
InvalidateCache clears the cached spec so it's regenerated on next request.
func (*Plugin) RegisterRoutes ¶
RegisterRoutes mounts the documentation endpoints on the router.
type PluginConfig ¶
type PluginConfig struct {
// Path prefix for the docs UI (default: "/_docs").
Path string
// Generator config for OpenAPI spec generation.
Generator GeneratorConfig
// Enabled controls whether docs are served (default true).
Enabled bool
// CustomCSS is injected into the Swagger UI page.
CustomCSS string
// HideModels hides the Models section in Swagger UI.
HideModels bool
// DeepLinking enables deep linking to operations.
DeepLinking bool
// TryItOutEnabled enables the "Try it out" feature by default.
TryItOutEnabled bool
}
PluginConfig configures the OpenAPI documentation plugin.
type PluginHandler ¶
type PluginHandler struct {
// contains filtered or unexported fields
}
PluginHandler wraps the plugin as an http.Handler for mounting.
func NewPluginHandler ¶
func NewPluginHandler(p *Plugin) *PluginHandler
NewPluginHandler creates an http.Handler that serves docs at the given prefix.
func (*PluginHandler) ServeHTTP ¶
func (h *PluginHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type RequestBody ¶
type RequestBody struct {
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
Content map[string]MediaType `json:"content"`
}
RequestBody describes a request body.
type Response ¶
type Response struct {
Description string `json:"description"`
Content map[string]MediaType `json:"content,omitempty"`
}
Response describes a single response from an API Operation.
type Schema ¶
type Schema struct {
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Description string `json:"description,omitempty"`
Properties map[string]*Schema `json:"properties,omitempty"`
Items *Schema `json:"items,omitempty"`
Required []string `json:"required,omitempty"`
Ref string `json:"$ref,omitempty"`
Enum []any `json:"enum,omitempty"`
Example any `json:"example,omitempty"`
Nullable bool `json:"nullable,omitempty"`
OneOf []*Schema `json:"oneOf,omitempty"`
AllOf []*Schema `json:"allOf,omitempty"`
AnyOf []*Schema `json:"anyOf,omitempty"`
Default any `json:"default,omitempty"`
Minimum *float64 `json:"minimum,omitempty"`
Maximum *float64 `json:"maximum,omitempty"`
MinLength *int `json:"minLength,omitempty"`
MaxLength *int `json:"maxLength,omitempty"`
Pattern string `json:"pattern,omitempty"`
}
Schema represents a JSON Schema object.
type SecurityScheme ¶
type SecurityScheme struct {
Type string `json:"type"` // apiKey, http, oauth2, openIdConnect
Description string `json:"description,omitempty"`
Name string `json:"name,omitempty"` // for apiKey
In string `json:"in,omitempty"` // header, query, cookie
Scheme string `json:"scheme,omitempty"`
BearerFormat string `json:"bearerFormat,omitempty"`
Flows *OAuthFlow `json:"flows,omitempty"`
}
SecurityScheme defines a security scheme.
type Spec ¶
type Spec struct {
OpenAPI string `json:"openapi"`
Info Info `json:"info"`
Servers []Server `json:"servers,omitempty"`
Paths map[string]*PathItem `json:"paths"`
Components *Components `json:"components,omitempty"`
Tags []Tag `json:"tags,omitempty"`
Security []map[string][]string `json:"security,omitempty"`
}
Spec is the root OpenAPI 3.0 document.