golang-swagger

Generates and maintains OpenAPI/Swagger documentation for Go APIs using swaggo/swag annotations.

Updated Jun 15, 2026
One-click install
npx skills add https://github.com/2877389577/novels_ai_gen --skill golang-swagger-2877389577
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-swagger
Source: https://github.com/2877389577/novels_ai_gen/tree/main/.agents/skills/golang-swagger
Command: npx skills add https://github.com/2877389577/novels_ai_gen --skill golang-swagger-2877389577

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires github.com/swaggo/swag, and includes references (resource) components.

What problem does it solve? Go developers must manually write and maintain Swagger/OpenAPI annotations that stay in sync with their handlers and models; stale or incorrect annotations produce wrong API contracts and broken Swagger UIs. This Skill provides the annotation patterns, CLI workflows, and framework integrations needed to keep generated docs accurate. ## Core Features & Use Cases - Annotation authoring: Write @Summary, @Param, @Success, @Router, and @Security comments correctly, including generics, nested composition, and collection formats. - Framework integration: Wire the Swagger UI endpoint for Gin, Echo, Fiber, Chi, and net/http, including dynamic host/basepath overrides via docs.SwaggerInfo. - Struct tag enrichment: Use swaggertype, enums, example, and swaggerignore tags to control generated schemas without changing Go types. - Use Case: A team adds JWT-protected endpoints to a Gin service; the Skill annotates each handler with @Security Bearer, regenerates docs with swag init, and the Swagger UI shows the lock icon and correct schemas. ## Quick Start Ask the AI to add Swagger annotations to your Go handlers and wire up the Swagger UI endpoint for your framework.

Frequently Asked Questions about golang-swagger

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add Swagger documentation to a Go API?▼

Annotate handlers with swag comments like @Summary, @Param, @Success, and @Router, then run swag init to generate the docs folder. Import the docs package and register a Swagger UI route using your framework's swaggo integration package.

How do I set up Swagger UI with Gin in Go?▼

Import github.com/swaggo/gin-swagger and github.com/swaggo/files, add a blank import of your generated docs package, then register r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)). The UI is served at /swagger/index.html.

Why is my Swagger UI empty after running swag init?▼

The most common cause is a missing blank import of the generated docs package (_ "yourmodule/docs"), which registers the spec. Also verify general info annotations are in the file passed to swag init via -g, and re-run swag init after annotation changes.

How do I document JWT Bearer authentication in swaggo annotations?▼

Define the scheme once with @securityDefinitions.apikey Bearer, @in header, and @name Authorization in your main file. Then apply @Security Bearer to each protected endpoint so the Swagger UI shows the lock icon.

Does swaggo support generic response types in Go?▼

Yes, swag v2 supports generics in annotations, for example @Success 200 {object} api.Response[model.User]. You can also use nested composition like Envelope{data=model.User} to document wrapper structs without changing Go types.

How do I hide a struct field from Swagger docs but keep it in JSON?▼

Use the swaggerignore:"true" struct tag while keeping the normal json tag intact. Using json:"-" would remove the field from JSON serialization entirely, which breaks consumers that depend on it.