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

Swag ignores package path if it starts with vendor #1880

Open
syed-shah-zepto opened this issue Sep 3, 2024 · 4 comments
Open

Swag ignores package path if it starts with vendor #1880

syed-shah-zepto opened this issue Sep 3, 2024 · 4 comments

Comments

@syed-shah-zepto
Copy link

Describe the bug
I was running swag in my package -> vendor-service. But due to a vendor prefix check, all the files are being ignored and swagger docs are not generated.

To Reproduce
Steps to reproduce the behavior:

  1. Create a package with starts with "vendor"
  2. Add an API and swagger annotation to that API
  3. Run swag init
  4. Check docs/swagger.json does not have the swagger documentation data

Expected behavior
Swagger documentation should get generated similar to packages that don't start with "vendor"

Your swag version
v1.16.3

Your go version
1.21.6

@syed-shah-zepto
Copy link
Author

As info.PackagePath will always have the prefix of the package where swag was run, do we need this check?
If we do can we restrict it to vendor/ paths?

Would be happy to raise a PR to get this fixed.

@sdghchj
Copy link
Member

sdghchj commented Sep 23, 2024

swag init --parseVendor

@syed-shah-zepto
Copy link
Author

syed-shah-zepto commented Sep 23, 2024

@sdghchj I had tried this config but it didn't help with my issue. From what I could tell, the parseVendor config is used only in the getAllGoFileInfo function for this check:

			if !parseVendor && f.Name() == "vendor" || // ignore "vendor"
				f.Name() == "docs" || // exclude docs
				len(f.Name()) > 1 && f.Name()[0] == '.' && f.Name() != ".." { // exclude all hidden folder
				return filepath.SkipDir
			}

But if the file name starts with "vendor" like in my case ("vendor-service"), the skip dir doesn't happen with or without the parseVendor config. In my case, issue is in the parser.packages.RangeFiles function which runs after the getAllGoFileInfo fn, where check is on the package path name and file gets skipped if package path starts with "vendor", and it doesn't use the parseVendor config to skip this check:

for _, info := range pkgDefs.files {
		// ignore package path prefix with 'vendor' or $GOROOT,
		// because the router info of api will not be included these files.
		if strings.HasPrefix(info.PackagePath, "vendor") || strings.HasPrefix(info.Path, runtime.GOROOT()) {
			continue
		}
		sortedFiles = append(sortedFiles, info)
	}

@syed-shah-zepto
Copy link
Author

syed-shah-zepto commented Oct 17, 2024

Hi @sdghchj, just following up on this issue. Let me know if there's anything else needed from my side. Thanks for your time!

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