Navigate:
~$SWAG0.1%

Swag: Go Swagger documentation generator

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

LIVE RANKINGS • 03:11 AM • STEADY
OVERALL
#291
31
DEVELOPER TOOLS
#55
1
30 DAY RANKING TREND
ovr#291
·Devel#55
STARS
12.6K
FORKS
1.3K
7D STARS
+19
7D FORKS
+3
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

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

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

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


[ EXPLORE MORE ]

Related Repositories

Discover similar tools and frameworks used by developers