Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gjxgjxgjxgjx opened this issue Apr 3, 2024 · 1 comment
Open

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

gjxgjxgjxgjx opened this issue Apr 3, 2024 · 1 comment

Comments

@gjxgjxgjxgjx
Copy link

gjxgjxgjxgjx commented Apr 3, 2024

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

@backunderstar
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants