What I do
Add Swagger annotations to HTTP handlers.
When to use me
Creating or modifying API endpoints.
Annotations
go
// @Summary Short description
// @Description Detailed description
// @Tags todos
// @Accept json
// @Produce json
// @Param id path string true "Todo ID"
// @Param todo body createInput true "Todo data"
// @Success 200 {object} todoOutput
// @Success 201 {object} todoOutput
// @Failure 400 {object} ErrorResponse
// @Failure 404 {object} ErrorResponse
// @Router /todos [get|post|put|delete]
Rules
- •Add above the Handle method
- •Use correct HTTP method in @Router
- •Define response types (use existing todoOutput or create new)
- •Regenerate docs:
make swagger(preferred) orswag init -g cmd/api/main.go -o docs/