Open itoqsky opened 1 year ago
Hello, I have the same issue issue, with same kind of directory structure! :)
After a few more tries, I finally made it work this way:
swag init --parseInternal --dir cmd/api/,internal/app/ --output internal/app/docs/
It generates a warning but I got my JSON/yaml file at the end!
I hope it helps you!
I've been banging my head against the wall for so long and just figured it out 🤦♂️
swag init
was all I needed, no extra params, even though my annotations were in the controllers
directory:
My problem was that I had a blank line between my annotations and the function declaration. AKA this...
// @Summary sign up
...
// @Router /auth/sign-up [post]
func PostSignUp(c *gin.Context) {
c.IndentedJSON(http.StatusBadRequest, gin.H{"code": "NOT_IMPLEMENTED", "message": "Not implemented"})
}
Needed to be this:
// @Summary sign up
...
// @Router /auth/sign-up [post]
func PostSignUp(c *gin.Context) {
c.IndentedJSON(http.StatusBadRequest, gin.H{"code": "NOT_IMPLEMENTED", "message": "Not implemented"})
}
Issue Description Swaggo fails to recursively parse Swagger comments in Go files when using the
swag init
command with multiple directories and the--parseDependency
and--parseInternal
flags. Only the comments in the main file specified with the-g
flag are parsed, while the comments in other files within the specified directories are not considered.docs
directory is included in router(internal/transport/htpp/handler.go) and in cmd/app/main.gocommands I have run:
swag init -d cmd/app/ -g main.go --parseDependency --parseInternal
swag init -d cmd/app/,internal/transport/http/v1 -g main.go --parseDependency --parseInternal
All the commands above produce the same result
Result in the swagger.yml
Command Respond
Structure
Files that contain swaggo comments are
internal/transport/http/v1/auth.go
,internal/transport/http/v1/trip.go
, and cmd/app/main.goComments in one of the files other than cmd/app/main.go
Your swag version e.g. 1.8.12
Your go version e.g. 1.20.2
OS OSX