Navigate:
~$SWAG0.1%

Swag: Go Swagger documentation generator

CLI tool that generates Swagger 2.0 API documentation from Go source code annotations.

LIVE RANKINGS • 12:18 PM • STEADY
OVERALL
#285
46
DEVELOPER TOOLS
#58
13
30 DAY RANKING TREND
ovr#285
·Devel#58
STARS
12.6K
FORKS
1.3K
7D STARS
+14
7D FORKS
+1
See Repo:
Share:

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.

Swag

1

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.

2

Framework Integration

Provides plugins for popular Go web frameworks like Gin, Echo, and Fiber. Integrates seamlessly with existing Go projects through generated docs packages.

3

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
}


vv2.0.0-rc5

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
vv1.16.6

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
vv1.16.5

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


[ EXPLORE MORE ]

Related Repositories

Discover similar tools and frameworks used by developers