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
}v2.0.0-rc5
- –feat: remove json-iterator and pkg/errors dependencies by @devhaozi in
- –fix: Issue #1980 by @Mozuha in
- –fix: enum generation in v3.1 by @dmouraneto in
- –refactor: simplify checking of FieldParser interface implementation by @nikpivkin in
- –refactor: remove unused parseValidTags method by @nikpivkin in
v1.16.6
- –fix: prevent nil pointer dereference in getFuncDoc when parsing depen… by @gatorjuice in
- –fix: router with tilde #2004 by @subwiz in
- –Feature: allow enum ordered const name override (2nd PR for this) by @drewsilcock in
- –Use the structs name without the @name comment by @skast96 in
- –feat: allow description line continuation by @berk-karaal in
v1.16.5
- –Added support for @tag.x- attributes for tags (#1784) by @Ponywka in
- –feat: Add x-enum-descriptions to generated Swagger documentation for Enum by @wakamenod in
- –fix: use '&&' for security pair(AND) by @kkkiio in
- –feat: ParseComment error to contain the comment by @stokito in
- –support generate var-declared function doc by @book987 in
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-cli
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.