Documentation
¶
Index ¶
- func GetSwaggerTag(field reflect.StructField) map[string]string
- type Generator
- func (g *Generator) AddSecurityDefinition(name string, definition interface{})
- func (g *Generator) GenerateSwagger() *Swagger
- func (g *Generator) GetSwagger() *Swagger
- func (g *Generator) RegisterRoute(method, path string, handler interface{}, options ...RouteOption)
- func (g *Generator) SetBasePath(basePath string)
- func (g *Generator) SetHost(host string)
- func (g *Generator) SetSchemes(schemes []string)
- func (g *Generator) SetupFiberSwagger(app *fiber.App, path string)
- func (g *Generator) SetupFiberSwaggerYAML(app *fiber.App, path string)
- func (g *Generator) SetupSwaggerUI(app *fiber.App, swaggerPath, uiPath string)
- func (g *Generator) ToJSON() ([]byte, error)
- func (g *Generator) ToYAML() ([]byte, error)
- type HandlerAnnotation
- type Header
- type Items
- type MiddlewareConfig
- type Operation
- type Parameter
- type Response
- type ResponseInfo
- type RouteInfo
- type RouteOption
- func WithBadRequestResponse(errorType interface{}, description string) RouteOption
- func WithConsumes(consumes []string) RouteOption
- func WithCreatedResponse(responseType interface{}, description string) RouteOption
- func WithDeprecated(deprecated bool) RouteOption
- func WithDescription(description string) RouteOption
- func WithErrorResponse(statusCode int, errorType interface{}, description string) RouteOption
- func WithForbiddenResponse(errorType interface{}, description string) RouteOption
- func WithInternalServerErrorResponse(errorType interface{}, description string) RouteOption
- func WithNoContentResponse(description string) RouteOption
- func WithNotFoundResponse(errorType interface{}, description string) RouteOption
- func WithProduces(produces []string) RouteOption
- func WithRequestType(t interface{}) RouteOption
- func WithResponse(statusCode int, responseType interface{}, description string) RouteOption
- func WithResponseHeaders(headers map[string]string) RouteOption
- func WithResponseType(t interface{}) RouteOption
- func WithSecurity(security map[string][]string) RouteOption
- func WithSuccessResponse(responseType interface{}, description string) RouteOption
- func WithSummary(summary string) RouteOption
- func WithTags(tags ...string) RouteOption
- func WithUnauthorizedResponse(errorType interface{}, description string) RouteOption
- type Schema
- type SecurityDefinition
- type Swagger
- type SwaggerInfo
- type SwaggerMiddleware
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetSwaggerTag ¶
func GetSwaggerTag(field reflect.StructField) map[string]string
GetSwaggerTag extracts swagger information from struct tags
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator handles the automatic generation of Swagger documentation
func NewGenerator ¶
func NewGenerator(info SwaggerInfo) *Generator
NewGenerator creates a new swagger generator
func (*Generator) AddSecurityDefinition ¶
AddSecurityDefinition adds a security definition
func (*Generator) GenerateSwagger ¶
GenerateSwagger creates the complete Swagger document
func (*Generator) GetSwagger ¶
GetSwagger returns the generated swagger document
func (*Generator) RegisterRoute ¶
func (g *Generator) RegisterRoute(method, path string, handler interface{}, options ...RouteOption)
RegisterRoute registers a route with swagger metadata
func (*Generator) SetBasePath ¶
SetBasePath sets the base path for all API endpoints
func (*Generator) SetSchemes ¶
SetSchemes sets the supported schemes (http, https)
func (*Generator) SetupFiberSwagger ¶
SetupFiberSwagger sets up swagger generation with Fiber app
func (*Generator) SetupFiberSwaggerYAML ¶
SetupFiberSwaggerYAML sets up YAML swagger generation with Fiber app
func (*Generator) SetupSwaggerUI ¶
SetupSwaggerUI sets up Swagger UI endpoint
type HandlerAnnotation ¶
HandlerAnnotation contains swagger annotations for handlers
type Header ¶
type Header struct {
Type string `json:"type"`
Format string `json:"format,omitempty"`
Description string `json:"description,omitempty"`
}
Header represents a response header
type MiddlewareConfig ¶
MiddlewareConfig configuration for the swagger middleware
type Operation ¶
type Operation struct {
Tags []string `json:"tags,omitempty"`
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
OperationID string `json:"operationId,omitempty"`
Consumes []string `json:"consumes,omitempty"`
Produces []string `json:"produces,omitempty"`
Parameters []Parameter `json:"parameters,omitempty"`
Responses map[string]Response `json:"responses"`
Security []map[string][]string `json:"security,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`
}
Operation represents a single API operation
type Parameter ¶
type Parameter struct {
Name string `json:"name"`
In string `json:"in"` // "query", "header", "path", "formData", "body"
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Schema *Schema `json:"schema,omitempty"`
Items *Items `json:"items,omitempty"`
CollectionFormat string `json:"collectionFormat,omitempty"`
Minimum *float64 `json:"minimum,omitempty"`
Maximum *float64 `json:"maximum,omitempty"`
Enum []string `json:"enum,omitempty"`
}
Parameter represents an operation parameter
type Response ¶
type Response struct {
Description string `json:"description"`
Schema *Schema `json:"schema,omitempty"`
Headers map[string]Header `json:"headers,omitempty"`
}
Response represents an operation response
type ResponseInfo ¶
type ResponseInfo struct {
StatusCode int
Description string
Type reflect.Type
Headers map[string]string
}
ResponseInfo represents a response for a specific status code
type RouteInfo ¶
type RouteInfo struct {
Method string
Path string
Handler interface{}
Tags []string
Summary string
Description string
RequestType reflect.Type
ResponseType reflect.Type
Responses []ResponseInfo // Multiple responses for different status codes
Security map[string][]string
Deprecated bool
Produces []string
Consumes []string
}
RouteInfo contains metadata about a route
type RouteOption ¶
type RouteOption func(*RouteInfo)
RouteOption is a function that configures route metadata
func WithBadRequestResponse ¶
func WithBadRequestResponse(errorType interface{}, description string) RouteOption
WithBadRequestResponse adds a bad request response (400)
func WithConsumes ¶
func WithConsumes(consumes []string) RouteOption
WithConsumes sets the content types the route consumes
func WithCreatedResponse ¶
func WithCreatedResponse(responseType interface{}, description string) RouteOption
WithCreatedResponse adds a created response (201)
func WithDeprecated ¶
func WithDeprecated(deprecated bool) RouteOption
WithDeprecated marks the route as deprecated
func WithDescription ¶
func WithDescription(description string) RouteOption
WithDescription sets the description for the route
func WithErrorResponse ¶
func WithErrorResponse(statusCode int, errorType interface{}, description string) RouteOption
WithErrorResponse adds a common error response
func WithForbiddenResponse ¶
func WithForbiddenResponse(errorType interface{}, description string) RouteOption
WithForbiddenResponse adds a forbidden response (403)
func WithInternalServerErrorResponse ¶
func WithInternalServerErrorResponse(errorType interface{}, description string) RouteOption
WithInternalServerErrorResponse adds an internal server error response (500)
func WithNoContentResponse ¶
func WithNoContentResponse(description string) RouteOption
WithNoContentResponse adds a no content response (204)
func WithNotFoundResponse ¶
func WithNotFoundResponse(errorType interface{}, description string) RouteOption
WithNotFoundResponse adds a not found response (404)
func WithProduces ¶
func WithProduces(produces []string) RouteOption
WithProduces sets the content types the route produces
func WithRequestType ¶
func WithRequestType(t interface{}) RouteOption
WithRequestType sets the request body type
func WithResponse ¶
func WithResponse(statusCode int, responseType interface{}, description string) RouteOption
WithResponse adds a response for a specific status code
func WithResponseHeaders ¶
func WithResponseHeaders(headers map[string]string) RouteOption
WithResponseHeaders adds headers to the last added response
func WithResponseType ¶
func WithResponseType(t interface{}) RouteOption
WithResponseType sets the response type
func WithSecurity ¶
func WithSecurity(security map[string][]string) RouteOption
WithSecurity adds security requirements to the route
func WithSuccessResponse ¶
func WithSuccessResponse(responseType interface{}, description string) RouteOption
WithSuccessResponse adds a success response (200)
func WithSummary ¶
func WithSummary(summary string) RouteOption
WithSummary sets the summary for the route
func WithUnauthorizedResponse ¶
func WithUnauthorizedResponse(errorType interface{}, description string) RouteOption
WithUnauthorizedResponse adds an unauthorized response (401)
type Schema ¶
type Schema struct {
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Description string `json:"description,omitempty"`
Required []string `json:"required,omitempty"`
Properties map[string]*Schema `json:"properties,omitempty"`
Items *Schema `json:"items,omitempty"`
Ref string `json:"$ref,omitempty"`
Example interface{} `json:"example,omitempty"`
AdditionalProperties *Schema `json:"additionalProperties,omitempty"`
Enum []interface{} `json:"enum,omitempty"`
}
Schema represents a data schema
func GetTypeSwagger ¶
GetTypeSwagger extracts swagger info from Go types
type SecurityDefinition ¶
type SecurityDefinition struct {
Type string `json:"type"`
In string `json:"in,omitempty"`
Name string `json:"name,omitempty"`
Scheme string `json:"scheme,omitempty"`
BearerFormat string `json:"bearerFormat,omitempty"`
}
SecurityDefinition represents a security definition
type Swagger ¶
type Swagger struct {
Swagger string `json:"swagger"`
Info SwaggerInfo `json:"info"`
Host string `json:"host,omitempty"`
BasePath string `json:"basePath,omitempty"`
Schemes []string `json:"schemes,omitempty"`
Consumes []string `json:"consumes,omitempty"`
Produces []string `json:"produces,omitempty"`
Paths map[string]map[string]Operation `json:"paths"`
Definitions map[string]*Schema `json:"definitions"`
Security []map[string][]string `json:"security,omitempty"`
SecurityDefinitions map[string]SecurityDefinition `json:"securityDefinitions,omitempty"`
}
Swagger represents the complete OpenAPI document
type SwaggerInfo ¶
type SwaggerInfo struct {
Title string `json:"title"`
Description string `json:"description"`
Version string `json:"version"`
Host string `json:"host,omitempty"`
BasePath string `json:"basePath,omitempty"`
}
SwaggerInfo contains the basic API information
type SwaggerMiddleware ¶
type SwaggerMiddleware struct {
// contains filtered or unexported fields
}
SwaggerMiddleware creates a middleware that generates and serves swagger docs
func NewMiddleware ¶
func NewMiddleware(info SwaggerInfo, config MiddlewareConfig) *SwaggerMiddleware
NewMiddleware creates a new swagger middleware
func (*SwaggerMiddleware) GetSwagger ¶
func (m *SwaggerMiddleware) GetSwagger() *Swagger
GetSwagger returns the generated swagger document
func (*SwaggerMiddleware) Handler ¶
func (m *SwaggerMiddleware) Handler() fiber.Handler
Handler returns the middleware handler that serves swagger documentation
func (*SwaggerMiddleware) Route ¶
func (m *SwaggerMiddleware) Route(method, path string, handler fiber.Handler, options ...RouteOption) fiber.Handler
Route registers a route with swagger documentation
func (*SwaggerMiddleware) ToJSON ¶
func (m *SwaggerMiddleware) ToJSON() ([]byte, error)
ToJSON returns the swagger document as JSON bytes