swaggo / swag

Automatically generate RESTful API documentation with Swagger 2.0 for Go.
MIT License
10.68k stars 1.2k forks source link

Got type definition cannot found after type definition #1869

Closed senayuki closed 2 months ago

senayuki commented 2 months ago

Describe the bug When using the swag init -g main.go command, the struct in the model package can be parsed normally, but once the 'parseDependency' is added, like swag init --parseDependency -g main.go,it immediately stops working. The struct located at github.com/xxx/internal/model.StructName, and ginHandler located at internal pkg Is it internal related to this? But adding parseInternal doesn't solve the problem, on the contrary, it works without adding any parse parameters.

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Your swag version e.g. 1.16.3

Your go version e.g. 1.22.5

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

senayuki commented 2 months ago

I eventually discovered that I did not implicitly import model pkg in the package, just like this _ "github.com/xxx/model"

This was my mistake, but I still don't understand why I just enabled parseDependency, which resulted in two different behaviors that were unexpected.

And I found that this project also has strange problems when parsing generics. I will get Cannot find type definition: response.PaginatorResponse[string], not response.PaginatorResponse, It seems that generics are treated as a whole.