🌐
GitHub
github.com › swaggo › gin-swagger
GitHub - swaggo/gin-swagger: gin middleware to automatically generate RESTful API documentation with Swagger 2.0. · GitHub
gin middleware to automatically generate RESTful API documentation with Swagger 2.0. - swaggo/gin-swagger
Starred by 4.2K users
Forked by 294 users
Languages   Go
Discussions

go - How to configure swagger UI so it doesn't need the URL? - Stack Overflow
I am using http://github.com/swaggo/gin-swagger to auto-generate the swagger and also create the UI as below. Everything works fine when I am running the server on my machine but when I run the ser... More on stackoverflow.com
🌐 stackoverflow.com
How to handle generic type by gin-swagger
Unfortunately I don't have a solution to your problem. It looks like in theory it should work. You can try opening a bug on one of the two repos (or both) and seeing where that goes. I also wanted to point out that OpenAPI-via-comments is kind of brittle and error-prone. If possible I would suggest using something like Huma (disclaimer: I'm the author) instead, which has great support for generics. Here's a quick example in just a few lines that runs in the playground and dumps the generated OpenAPI 3.1: https://go.dev/play/p/vemu7wOFuns There you have two responses: Response[int] and Response[string] which wind up getting generated like this: ResponseIntBody: additionalProperties: false properties: field: format: int64 type: integer required: - field type: object ResponseStringBody: additionalProperties: false properties: field: type: string required: - field type: object I figured this might be useful for you or people searching similar things in the future. More on reddit.com
🌐 r/golang
6
3
April 16, 2024
Go + gRPC + GORM + SQLite + GIN + Swagger
gRPC has support for HTTP transcoding so actually you don't need to use gin for the HTTP server (it will save you more time if you add new APIs in the future) More on reddit.com
🌐 r/golang
74
93
November 26, 2023
Go swaggerfiles
Sorry I got excited. The solution is: on imports use: "github.com/swago/files" instead. Now you can use router.Get("/swagger/*any", ginSwagger.WrapperHandler(swagFiles.Handler, url)). If you do go mod tidy , that should clear the error More on reddit.com
🌐 r/golang
6
0
March 12, 2024
🌐
Stack Overflow
stackoverflow.com › questions › 42766501 › how-to-create-swagger-json-in-go-gin-gonic
How to create swagger.json in go gin-gonic - Stack Overflow
go generate cat swagger.json { "swagger": "2.0", "paths": {}, "definitions": {} } If this is not an option, should I look into a different framework for the same? ... Gin uses goswagger as a base.
🌐
Go Packages
pkg.go.dev › github.com › swaggo › gin-swagger
ginSwagger package - github.com/swaggo/gin-swagger - Go Packages
September 2, 2025 - CustomWrapHandler wraps `http.Handler` into `gin.HandlerFunc`. ... DeepLinking set the swagger deep linking configuration.
🌐
GitHub
github.com › swaggo › gin-swagger › releases
Releases · swaggo/gin-swagger
September 2, 2025 - gin middleware to automatically generate RESTful API documentation with Swagger 2.0. - Releases · swaggo/gin-swagger
Author   swaggo
🌐
Vercel
azar-writes-blogs.vercel.app › post › Simplifying-Documentation:-Generate-Swagger-for-Your-Go-Gin-Server-Automatically-with-Swag-831649429ff24428bfaf3f59eb1ad83e
Generate Swagger for Your Go-Gin Server Automatically ...
April 22, 2024 - Swag: Swag is a Go library that automatically generates Swagger documentation for Go-based web servers. It parses Go files containing certain comments and converts them into a Swagger JSON file, which can then be used to generate API documentation. Now that we have a basic understanding, let's ...
🌐
WesionaryTEAM
articles.wesionary.team › modern-api-documentation-with-swagger-in-go-gin-2aee10cb7bb9
Modern API Documentation with Swagger in Go GIN | by Mukesh Kumar Chaudhary | wesionaryTEAM
December 31, 2024 - Check out this example https://codepen.io/scalarorg/pen/VwOXqam --> <script id="api-reference" type="application/json" data-url="%s" ></script> <script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script> </body> </html> `, scheme+ctx.Request.Host+"/swagger") ctx.String(http.StatusOK, content) }) }go ... func main() { r := gin.Default() ...
Find elsewhere
🌐
Liu Houliang
liuhouliang.com › en › post › gin-swagger
Multiple API Docs with Gin-Swagger
gin-swagger is a handy tool for generating API documentation. With the Gin framework, you can simply add annotations to your API code and run swag init to create documentation. However, gin-swagger uses Swagger 2.0, which doesn’t support project switching. This became a challenge when I needed ...
🌐
Medium
medium.com › @zhengfke › go-go-swagger-generation-and-convert-to-openapi-3-0-3-5f5f8840f7d5
【Go】Go Swagger generation and convert to OpenApi 3.0.3 | by ZhengXiaoMin | Medium
May 29, 2024 - 【Go】Go Swagger generation and convert to OpenApi 3.0.3 This document describes the process of generating a swagger.json file using the gin framework and gin-swagger, along with potential …
🌐
Go Packages
pkg.go.dev › github.com › amalmsc › gin-swagger
ginSwagger package - github.com/amalmsc/gin-swagger - Go Packages
github.com/amalmsc/gin-swagger · Open Source Insights · gin middleware to automatically generate RESTful API documentation with Swagger 2.0. Add comments to your API source code, See Declarative Comments Format. Download Swag for Go by using: $ go get -u github.com/swaggo/swag/cmd/swag ·
🌐
Medium
medium.com › @kumar16.pawan › integrating-swagger-with-gin-framework-in-go-f8d4883f4833
Integrating Swagger with Gin Framework in Go. | by Pawan Kumar | Medium
October 5, 2022 - gin-swagger uses gin middleware to automatically generate RESTful API documentation with Swagger 2.0
🌐
GitHub
github.com › long2ice › swagin
GitHub - long2ice/swagin: Swagger + Gin = SwaGin, a web framework based on Gin and Swagger
SwaGin is a web framework based on Gin and Swagger, which wraps Gin and provides built-in swagger api docs and request model validation.
Starred by 70 users
Forked by 18 users
Languages   Go 94.0% | HTML 3.6% | Dockerfile 2.4% | Go 94.0% | HTML 3.6% | Dockerfile 2.4%
🌐
DEV Community
dev.to › santosh › how-to-integrate-swagger-ui-in-go-backend-gin-edition-2cbd
How to Integrate Swagger UI in Go Backend - Gin Edition - DEV Community
May 30, 2022 - That is how we create a path route in Gin. API documentation is an essential part of API documentation. Instead of documenting the endpoints anywhere else, we can document the routes right in the code. That way we only have 1 single source of truth. No need to maintain code and documentation separately. In turn, we get always up-to-date documentation. Every backend server has some sort of support for Swagger UI.
🌐
Stack Overflow
stackoverflow.com › questions › 66563866 › how-to-configure-swagger-ui-so-it-doesnt-need-the-url
go - How to configure swagger UI so it doesn't need the URL? - Stack Overflow
I am using http://github.com/swaggo/gin-swagger to auto-generate the swagger and also create the UI as below. Everything works fine when I am running the server on my machine but when I run the ser...
🌐
GitHub
github.com › swaggo › swag
GitHub - swaggo/swag: Automatically generate RESTful API documentation with Swagger 2.0 for Go. · GitHub
swag fmt -h NAME: swag fmt - format swag comments USAGE: swag fmt [command options] [arguments...] OPTIONS: --dir value, -d value Directories you want to parse,comma separated and general-info file must be in the first one (default: "./") --exclude value Exclude directories and files when searching, comma separated --generalInfo value, -g value Go file path in which 'swagger general API Info' is written (default: "main.go") --help, -h show help (default: false) ... Find the example source code here. ... import "github.com/swaggo/gin-swagger" // gin-swagger middleware import "github.com/swaggo/files" // swagger embed files
Starred by 12.7K users
Forked by 1.4K users
Languages   Go
🌐
Medium
medium.com › @feldyjudahk › how-to-create-a-dynamic-swagger-ui-for-golang-api-with-gin-5b85eaa248b3
How to Create a Dynamic Swagger UI for Golang API (with Gin) | by Feldy Judah Kambey | Medium
June 9, 2025 - Swagger UI (now part of OpenAPI) provides an interactive way to explore and test your API endpoints. In this article, we’ll walk you through how to generate and serve a dynamic Swagger UI for your Golang (Go) API using swaggo/swag ... go install github.com/swaggo/swag/cmd/swag@latest go get -u github.com/swaggo/gin-swagger go get -u github.com/swaggo/files
🌐
DEV Community
dev.to › getpieces › how-to-build-and-document-a-go-rest-api-with-gin-and-go-swagger-jgb
How to Build and Document a Go REST API with Gin and Go-Swagger - DEV Community
March 11, 2024 - In this blog post, we will go over what an API is, how to build a basic Go REST API using the Gin framework, and how to document the API using the go-swagger package.
🌐
Devtrovert
blog.devtrovert.com › p › swagger-in-go-why-its-the-genius
Swagger in Go: A Pragmatic Guide - by Phuong Le
January 19, 2024 - To kick things off, we need to set up Swagger. I’ll be using the Echo framework as a primary example. Still, the steps are quite similar if you’re working with other frameworks like Gin, Buffalo, net/http, Gorilla/mux, Fiber, etc.
🌐
Reddit
reddit.com › r/golang › how to handle generic type by gin-swagger
r/golang on Reddit: How to handle generic type by gin-swagger
April 16, 2024 -

Hi Friends
I am using gin-swagger to write comments in Go code and automatically generate Open API/Swagger documentation for the REST service exposed externally through these comments.
gin-swagger is just a top-level shell, and the actual work is done by another framework called swag, https://github.com/swaggo/swag/tree/master
A type is defined as follows:
```go
package middleware
type Response struct {
...other fields omitted...
data any
}
```
Add the following comments for the HTTP method in the Controller:
```go
// @Success 200 {object} middleware.Response
// @Success 500 {object} middleware.Response
```
After executing the `swag init`, the OpenAPI was correctly generated, although the result was not what I expected.
To get the expected result, I added a generic type argument to the Response struct:
```go
type Response[T any] struct {
...other fields omitted...
data T
}
```
Then I modified the comments in the HTTP function of the Controller:
```go
// @Success 200 {object} middleware.Response[int]
// @Success 500 {object} middleware.Response[string]
```
After executing the command again to regenerating the OpenAPI, an error occurred: "cannot find type definition".
The swag documentation clearly states that it supports Go generics, and the documentation for this feature can be found [here](https://github.com/swaggo/swag/tree/master?tab=readme-ov-file#how-to-use-generics)
As you can see, the framework explicitly states that it supports this feature, and the usage shown in its documentation is completely consistent with mine.
Finally, when searching for this issue, several issues occurred during the period when Go added generics, and the problems were caused by the users using versions of the frameworks that were too old. However, my version is the latest v1.16.3, which is far beyond the required version for this feature, yet the problem still persists.
Has anyone encountered this issue before?