gin-swagger icon indicating copy to clipboard operation
gin-swagger copied to clipboard

swag init can't generate api info in swagger.json

Open gjxgjxgjxgjx opened this issue 1 year ago • 1 comments

when i run 'swag init', no api info has been generated in swagger.json

swag.exe version v1.16.3 go version go1.22.1 windows/amd64 i use the examples provided on the official website and filled in the correct package name.

package main

import (
	"net/http"

	docs "oj/docs"

	"github.com/gin-gonic/gin"
	swaggerfiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
)

// @BasePath /api/v1

// PingExample godoc
// @Summary ping example
// @Schemes
// @Description do ping
// @Tags example
// @Accept json
// @Produce json
// @Success 200 {string} Helloworld
// @Router /example/helloworld [get]
func Helloworld(g *gin.Context) {
	g.JSON(http.StatusOK, "helloworld")
}

func main() {
	r := gin.Default()
	docs.SwaggerInfo.BasePath = "/api/v1"
	v1 := r.Group("/api/v1")
	{
		eg := v1.Group("/example")
		{
			eg.GET("/helloworld", Helloworld)
		}
	}
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
	r.Run(":8080")

}

image

gjxgjxgjxgjx avatar Apr 03 '24 16:04 gjxgjxgjxgjx

I am also in the same situation, and it can detect annotation information on the main function, but it cannot scan API information with added annotations. Have you resolved it now?

backunderstar avatar Jul 06 '24 00:07 backunderstar