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

Unable to generate Swagger docs due to type definition not found error #1696

Closed
nathannaveen opened this issue Nov 1, 2023 · 2 comments
Closed

Comments

@nathannaveen
Copy link

Hello,

I'm having trouble generating Swagger documentation for my Go project using Swaggo. I'm encountering an error that seems to be due to Swaggo not being able to find a type definition that is located in a different directory.

Here's the error message I'm getting:

Error parsing type definition 'main.Neighbors': hashEquals: cannot find type definition: model.NeighborsNeighborsHashEqual  
Error parsing type definition 'main.JsonResponse': neighborsData: Neighbors: hashEquals: cannot find type definition: model.NeighborsNeighborsHashEqual  
ParseComment error in file /Users/nathannaveen/go/src/github.com/nathannaveen/guac/cmd/rest/known.go :JsonResponse: neighborsData: Neighbors: hashEquals: cannot  
ParseComment error in file /Users/nathannaveen/go/src/github.com/nathannaveen/guac/cmd/rest/known.go :JsonResponse: neighborsData: Neighbors: hashEquals: cannot find type definition: model.NeighborsNeighborsHashEqual

The type model.NeighborsNeighborsHashEqual is defined in another directory (/Users/nathannaveen/go/src/github.com/nathannaveen/guac/pkg/assembler/clients/generated/operations.go), and I'm running swag init from /Users/nathannaveen/go/src/github.com/nathannaveen/guac/cmd/rest.

I've tried the following steps to resolve this issue:

  1. Checked my import statements to ensure the package containing model.NeighborsNeighborsHashEqual is correctly imported.
  2. Checked my GOPATH and GOROOT environment variables.
  3. Ensured my Go project is correctly organized according to Go's project layout conventions.
  4. Ran swag init from the root directory of my Go module.
  5. Used the --parseDependency flag when running swag init.
  6. Used the -d flag when running swag init to specify the directory where swaggo should search for types.
  7. Ensured the package is included in my go.mod file and ran go mod tidy.

Despite these steps, I'm still encountering the error. Any help would be greatly appreciated.

Thank you!

@ranefattesingh
Copy link

@nathannaveen could you try runninng this command swag init -g **/**/*.go from project root

@nathannaveen
Copy link
Author

@ranefattesingh That works, thank you!

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