Back to Skills

golang-swagger

Golang OpenAPI/Swagger documentation with swaggo/swag — annotation comments (@Summary, @Param, @Success, @Router, @Security), swag init code generation, framework integrations (gin, echo, fiber, chi, net/http), security definitions (Bearer/JWT, OAuth2, API key), and struct tags (swaggertype, enums, example, swaggerignore). Apply when adding or maintaining Swagger/OpenAPI docs in a Go project, or when the codebase imports github.com/swaggo/swag, github.com/swaggo/gin-swagger, github.com/swaggo/ec

2,164stars137forksUpdated 6/16/2026

Security Assessment

Low Risk(80/100)

Detected risks:

Sensitive File Access([references/swag-cli.md] .Env)
Security Score80/100

About golang-swagger

The golang-swagger skill provides comprehensive support for integrating OpenAPI/Swagger documentation into Go projects using the swaggo/swag toolchain. It enables developers to generate interactive API documentation directly from annotated Go source code, eliminating the need to manually maintain separate specification files. By adding structured comment annotations above handler functions, the skill automatically produces swagger.json and swagger.yaml files that power a fully functional Swagger UI, making API exploration and testing seamless for both developers and API consumers.

This skill covers the complete workflow from initial setup to advanced configurations. It supports all major Go web frameworks including Gin, Echo, Fiber, Chi, and net/http, providing framework-specific integration patterns. The skill handles annotation syntax for endpoints (@Summary, @Param, @Success, @Router), request/response schemas with struct tags, security definitions (Bearer/JWT, OAuth2, API keys), and code generation commands. It also includes best practices for organizing annotations, formatting them with swag fmt, and dynamically configuring API hosts and base paths for multi-environment deployments.

Target users include backend engineers building RESTful APIs in Go, DevOps teams maintaining API gateways, and technical writers responsible for API documentation. The skill is particularly valuable when onboarding new projects that need documentation from scratch, auditing existing codebases for annotation completeness, or ensuring security schemes are properly documented. It treats API documentation as a contract, emphasizing accuracy and completeness to prevent integration issues and establish the Swagger UI as the authoritative reference for API consumers.

FAQ

What Go web frameworks are supported?

The skill supports Gin, Echo, Fiber, Chi, and net/http with framework-specific integration patterns for mounting the Swagger UI endpoint.

Do I need to install additional tools?

Yes, you need the swag CLI tool installed via 'go install github.com/swaggo/swag/cmd/swag@latest' to generate documentation from annotations.

How do I handle different environments with different API hosts?

Use a named import for the docs package and override docs.SwaggerInfo.Host and docs.SwaggerInfo.BasePath at runtime based on environment variables.

Can I format my Swagger annotations automatically?

Yes, run 'swag fmt' to automatically format annotation comments similar to how 'go fmt' formats Go code.

Where should I place the general API information annotations?

Place them in main.go or specify a different file using the '-g' flag with swag init, such as 'swag init -g cmd/api/main.go'.

All Files

3 files
SKILL.md8.7 KB
View
evals/evals.json10.5 KB
View
references/swag-cli.md4.5 KB
View

Install golang-swagger

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill