swag icon indicating copy to clipboard operation
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

Open sarkis1231 opened this issue 1 year ago • 8 comments

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 Screenshot 2024-05-23 at 2 57 54 AM

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

sarkis1231 avatar May 22 '24 23:05 sarkis1231

so i added the -q flag to supress logs

pot-code avatar Jun 03 '24 08:06 pot-code

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.

bobsongplus avatar Jun 14 '24 07:06 bobsongplus

-q

swag init -g cmd/server.go --outputTypes go,yaml I have specified

sarkis1231 avatar Jun 19 '24 15:06 sarkis1231

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.

emulatorchen avatar Nov 04 '24 12:11 emulatorchen

still having the same issue.

abdurrahmanarikan avatar Mar 13 '25 20:03 abdurrahmanarikan

Someone found the solution?

SebastianRoberto avatar Mar 20 '25 11:03 SebastianRoberto

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'

amarps avatar Apr 11 '25 13:04 amarps

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",
	}

amarps avatar Apr 14 '25 15:04 amarps