swaggo / gin-swagger

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

Swagger comments in Go files are not recursively parsed by Swaggo #274

Open itoqsky opened 1 year ago

itoqsky commented 1 year ago

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.

commands 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 produces the same result

Files that contain swaggo comments are internal/transport/http/v1/auth.go, internal/transport/http/v1/trip.go, and cmd/app/main.go Structure

Screenshot 2023-06-27 at 16 15 50

Results

Screenshot 2023-06-27 at 16 15 24

Comments in one of the files other than cmd/app/main.go

Screenshot 2023-06-27 at 16 16 10

swag version e.g. 1.8.12

go version e.g. 1.20.2

OS OSX

fuddin95 commented 7 months ago

Hi, were you able to find any solution

scottmangiapane commented 6 months ago

I̶'̶m̶ ̶a̶l̶s̶o̶ ̶s̶t̶u̶c̶k̶ ̶o̶n̶ ̶t̶h̶i̶s̶.̶ ̶H̶a̶v̶e̶n̶'̶t̶ ̶f̶o̶u̶n̶d̶ ̶a̶ ̶s̶o̶l̶u̶t̶i̶o̶n̶ ̶y̶e̶t̶.̶.̶.̶ ̶I̶ ̶h̶a̶v̶e̶ ̶a̶ ̶s̶m̶a̶l̶l̶ ̶A̶P̶I̶ ̶t̶h̶o̶u̶g̶h̶ ̶s̶o̶ ̶I̶ ̶m̶i̶g̶h̶t̶ ̶j̶u̶s̶t̶ ̶h̶a̶n̶d̶ ̶w̶r̶i̶t̶e̶ ̶m̶y̶ ̶s̶p̶e̶c̶.̶

edit: just solved it. Posted in more detail here... Turns out you can't have a blank line between your annotations and the function declaration.