swag
swag copied to clipboard
warning: failed to get package name in dir: ./, error: execute go list command, exit status 1, stdout:, stderr:no Go files in
Getting this warning "warning: failed to get package name in dir: ./, error: execute go list command, exit status 1, stdout:, stderr:no Go files in go-lang/swagger-chi". But my folder structure looks good and the command is correct I have tried to downgrade go version to 1.22.0 the warning disappeared
Expected behavior I expect to not see the warning
Screenshots
Your swag version e.g. 1.16.3
Your go version e.g. 1.22.1
Desktop (please complete the following information):
- OS: iOS
- Browser: [e.g. chrome, safari]
- Version: Sonoma 14.5
so i added the -q flag to supress logs
If you don't specify the directory, swag will search the current directory. I think the behavior is correct and the message is a warning that doesn't affect swag generation.
-q
swag init -g cmd/server.go --outputTypes go,yaml I have specified
I am having similar issue that I put my go files under src folder. I will need to switch workdir to src in order to get it work in dockerbuild.
Scripts:
swag init -g src/main.go
Environments:
- docker image: golang:1.23.2
- macOS Sonoma 14.7 with golang 1.23.2
In docker build, -q still returns failed code that cause build failed.
still having the same issue.
Someone found the solution?
still happening even after i put the currentdir as searchdir
currentDir, err := os.Getwd()
if err != nil {
log.Fatalf("Failed to get current directory: %v", err)
}
fmt.Printf("Current directory: %s\n", currentDir)
// Generate the docs similar to `swag init` command
config := &gen.Config{
SearchDir: currentDir,
OutputDir: genDir,
PropNamingStrategy: "camelcase",
OutputTypes: []string{"json"},
ParseDependency: 3,
MarkdownFilesDir: fmt.Sprint(genDir, "/docs"),
}
log
2025/04/11 20:31:29 Failed to generate docs: execute go list command, exit status 1, stdout:, stderr:go: go.mod file not found in current directory or any parent directory; see 'go help modules'
managed to solve it on my sid
adding --dir and specifying the path to folder containing binary in my case
swag init --dir ./cmd
and if you are generating it by code in gen.Config You need to specify the main.go file
// Generate the docs similar to `swag init` command
config := &gen.Config{
SearchDir: currentDir,
OutputDir: genDir,
PropNamingStrategy: "camelcase",
OutputTypes: []string{"json"},
ParseDependency: 3,
PackageName: "docs",
ParseDepth: 3,
ParseGoList: false,
MainAPIFile: "cmd/main.go",
}