Swag: Go Swagger documentation generator
CLI tool that generates Swagger 2.0 API documentation from Go source code annotations.
Learn more about Swag
Swag is a documentation generator that converts Go code annotations into Swagger 2.0 specification files. It works by parsing specially formatted comments in Go source code and extracting API information such as endpoints, request/response schemas, and authentication requirements. The tool generates multiple output formats including Go files, JSON, and YAML specifications that can be consumed by Swagger UI and other OpenAPI tools. It supports various Go web frameworks through dedicated plugins and provides extensive configuration options for customizing the documentation generation process.
Annotation-Based Generation
Generates documentation directly from structured comments in Go source code, eliminating the need for separate specification files. Supports comprehensive API annotations including parameters, responses, security, and model definitions.
Framework Integration
Provides plugins for popular Go web frameworks like Gin, Echo, and Fiber. Integrates seamlessly with existing Go projects through generated docs packages.
Flexible Output Options
Supports multiple output formats including Go source files, JSON, and YAML specifications. Offers extensive CLI configuration for parsing strategies, dependency handling, and custom type overrides.
package main
import (
"github.com/gin-gonic/gin"
_ "example-module-name/docs" // Import generated docs
)
// @title Swagger Example API
// @version 1.0
// @description This is a sample server celler server.
// @host localhost:8080
// @BasePath /api/v1
func main() {
r := gin.Default()
// Register your routes here
r.GET("/users/:id", getUser)
r.Run(":8080")
}
// GetUser godoc
// @Summary Get user by ID
// @Description Get user information by user ID
// @Tags users
// @Accept json
// @Produce json
// @Param id path int true "User ID"
// @Success 200 {object} User
// @Failure 404 {object} ErrorResponse
// @Router /users/{id} [get]
func getUser(c *gin.Context) {
// Implementation here
}Removes dependencies and fixes enum generation with code refactoring improvements.
- –feat: remove json-iterator and pkg/errors dependencies
- –fix: enum generation in v3.1
- –refactor: simplify checking of FieldParser interface implementation
- –refactor: remove unused parseValidTags method
Fixes nil pointer dereference and router issues while adding enum and description features.
- –fix: prevent nil pointer dereference in getFuncDoc when parsing dependencies
- –fix: router with tilde
- –Feature: allow enum ordered const name override
- –Use the structs name without the @name comment
- –feat: allow description line continuation
Added support for tag extensions and enum descriptions with security and comment parsing improvements.
- –Added support for @tag.x- attributes for tags
- –feat: Add x-enum-descriptions to generated Swagger documentation for Enum
- –fix: use '&&' for security pair (AND)
- –feat: ParseComment error to contain the comment
- –support generate var-declared function doc
Top in Developer Tools
Related Repositories
Discover similar tools and frameworks used by developers
Bun
Fast JavaScript runtime with built-in bundler and package manager.
WinGet
Multi-interface Windows package manager for Store and community repositories.
Hugo
Fast static site generator written in Go with built-in asset processing and multiple content formats.
Create React App
Zero-configuration React scaffolding tool with preconfigured toolchain.
HTTPX
Fast HTTP probing with response metadata extraction.