
Golang Swagger
Generate and expose live Swagger UI for Go Gin APIs using swag annotations without breaking on dynamic map responses.
Overview
golang-swagger is an agent skill for the Build phase that documents Go Gin APIs with swag and serves a working Swagger UI at /swagger/index.html.
Install
npx skills add https://github.com/samber/cc-skills-golang --skill golang-swaggerWhat is this skill?
- Wires Gin with blank import of generated docs plus gin-swagger and swaggo/files so UI is not empty
- Covers swag annotation patterns when map[string]bool and other dynamic types break schema generation
- Includes eval scenarios for post–swag init wiring vs re-running swag init unnecessarily
- Targets github.com/swaggo/swag and gin-swagger route registration with WrapHandler on /swagger/*any
- Eval scenarios include post–swag init Gin wiring without re-running swag init
Adoption & trust: 1.9k installs on skills.sh; 2k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You generated docs/ with swag init but Gin serves an empty Swagger UI or fails when endpoints return maps and other types swag cannot schema automatically.
Who is it for?
Indie builders on Gin who want interactive API docs during development and agent-assisted handler work.
Skip if: Teams on non-Go stacks, hand-maintained OpenAPI-only workflows with no swag, or projects that intentionally hide internal APIs from Swagger.
When should I use this skill?
You are documenting or exposing Swagger for a Go Gin API with swag, especially after docs/ exists or dynamic map responses break generation.
What do I get? / Deliverables
Your Gin server imports the generated docs module correctly, registers swagger routes, and uses annotation patterns so the UI shows accurate request and response schemas.
- Gin main wiring for Swagger UI
- Correct swag comments for non-trivial response types
Recommended Skills
Journey fit
OpenAPI docs are produced while the HTTP service is being built, before external consumers or launch polish depend on accurate schemas. The skill centers on swag init output, annotation fixes, and serving /swagger/index.html—documentation work tied to the API surface, not generic frontend layout.
How it compares
Use for swag-annotated Go services instead of pasting OpenAPI YAML without codegen tied to your handlers.
Common Questions / FAQ
Who is golang-swagger for?
Solo and small-team Go developers using Gin and swag who need Swagger UI wired correctly and annotations that survive real response types.
When should I use golang-swagger?
During Build when you run or plan swag init, register Swagger routes on Gin, or fix broken schemas for map-heavy JSON like feature flags.
Is golang-swagger safe to install?
Review the Security Audits panel on this Prism page and inspect the skill package in your repo before granting shell access to run swag or edit main.go.
SKILL.md
READMESKILL.md - Golang Swagger
{ "skill_name": "golang-swagger", "evals": [ { "id": 1, "prompt": "I've already run `swag init` and the docs/ folder was generated. Now wire up the Swagger UI in my Gin server so the docs actually show up at /swagger/index.html. Here's my main.go:\n\n```go\npackage main\n\nimport \"github.com/gin-gonic/gin\"\n\nfunc main() {\n r := gin.Default() \n r.GET(\"/api/users\", getUsers)\n r.Run(\":8080\")\n}\n```", "expected_output": "Adds the blank import `_ \"yourmodule/docs\"` AND wires the ginSwagger endpoint. The blank import is the trap — without it the UI loads empty even if the route is registered.", "assertions": [ "Adds a blank import of the docs package (e.g., `_ \"<module>/docs\"`)", "Imports github.com/swaggo/gin-swagger", "Imports github.com/swaggo/files", "Registers a GET route matching /swagger/*any using ginSwagger.WrapHandler", "Does not suggest running swag init again (it was already done)" ] }, { "id": 2, "prompt": "Our GET /settings endpoint returns a dynamic set of feature flags as a map: `map[string]bool`. Document this endpoint for Swagger so the response schema is visible in the UI.", "expected_output": "Defines a named struct for the response or uses swaggertype annotation — swag cannot generate a schema for map[string]bool directly. The trap is using `{object} map[string]bool` in @Success which fails generation.", "assertions": [ "Does NOT use `{object} map[string]bool` directly in @Success", "Defines a named struct for the response OR acknowledges a swaggertype workaround is needed", "@Success annotation uses a named type (not a raw map literal)", "@Router annotation is present with [get] method", "@Produce annotation specifies json" ] }, { "id": 3, "prompt": "Document this Go struct for Swagger. We need the docs to look correct:\n\n```go\ntype AuditRecord struct {\n CreatedAt time.Time\n UpdatedAt time.Time\n Payload []byte\n}\n```", "expected_output": "Uses swaggertype tag to override time.Time (which becomes an object by default) and []byte (which becomes a base64 string). Without the skill the model leaves the types as-is, producing wrong schemas.", "assertions": [ "Adds swaggertype tag to CreatedAt field (e.g., `swaggertype:\"string\"` with format:\"date-time\" or `swaggertype:\"primitive,integer\"`)", "Adds swaggertype tag to UpdatedAt field with the same treatment", "Adds swaggertype:\"string\" and format:\"base64\" to the Payload []byte field", "Preserves the json tags (does not remove them)", "Does not leave time.Time fields without any swaggertype override" ] }, { "id": 4, "prompt": "Set up the Swagger UI for a Chi HTTP router. The BasePath must be set dynamically from an `API_BASE_PATH` environment variable because we deploy behind different path prefixes in staging and production.", "expected_output": "Uses github.com/swaggo/http-swagger for Chi AND sets docs.SwaggerInfo.BasePath from os.Getenv. The trap is not knowing the http-swagger package for Chi and not knowing about the runtime docs.SwaggerInfo override.", "assertions": [ "Imports github.com/swaggo/http-swagger", "Uses r.Get (chi method) to register the swagger route with a wildcard pattern", "Sets docs.SwaggerInfo.BasePath using os.Getenv(\"API_BASE_PATH\") or equivalent", "Imports the docs package (blank `_ \"<module>/docs\"` or named `docs \"<module>/docs\"`)", "Does not suggest rebuilding or running swag init per environment" ] }, { "id": 5, "prompt": "This endpoint requires BOTH an API key AND basic authentication — not one or the other. Both must be present. Show me the @Security annotation for this.", "expected_output": "Uses the && syntax on a single @Security line. Two separat