swaggo / gin-swagger

gin middleware to automatically generate RESTful API documentation with Swagger 2.0.
MIT License
3.66k stars 266 forks source link

support for 'main' package outside of project root #268

Open igorfraa opened 1 year ago

igorfraa commented 1 year ago

Hello,

Our go code style guide suggests to have package main main.go not in the project root, namely in './main/' subdir.

When run swagger init from project root, I get the following:

2023/05/25 13:01:15 warning: failed to get package name in dir: ./, error: execute go list command, exit status 1, stdout:, stderr:no Go files in /Users/igorfraa/<...>/go-template/
2023/05/25 13:01:16 cannot parse source files Users/igorfraa/<...>/go-template/main.go: open Users/igorfraa/<...>/go-template/main.go: no such file or directory

Once package docs got generated inside 'package main', I moved that package dir to the project root and next swag fmt goes without any issue.

I wonder if there a predefined way to set a path to the main package?