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

v3: panic (invalid memory address or nil pointer dereference) #1590

Closed
leonklingele opened this issue May 24, 2023 · 2 comments
Closed

v3: panic (invalid memory address or nil pointer dereference) #1590

leonklingele opened this issue May 24, 2023 · 2 comments
Labels

Comments

@leonklingele
Copy link

Describe the bug

I'm getting a panic on the latest v3 commit due o definition.Spec being nil here:

if definition.Spec.Description == "" {

To Reproduce

go install github.com/swaggo/swag/v2/cmd/swag@c7b796dcb851ffca7e16b18bc91aa3696f6dadf5

swag init --output spec --outputTypes go,yaml --parseDependency --parseDepth 1 --v3.1

Your swag version

c7b796d

Your go version

1.19.9

Desktop (please complete the following information):

NixOS 22.11

Additional context

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x230 pc=0x8d4755]

goroutine 1 [running]:
github.com/swaggo/swag/v2.(*Parser).ParseDefinitionV3(0xc000230000, 0xc001c6cf50)
/path/to/project/.gopath/pkg/mod/github.com/swaggo/swag/[email protected]/parserv3.go:666 +0x475
github.com/swaggo/swag/v2.(*Parser).getTypeSchemaV3(0xc000230000, {0xc000035d76, 0x19}, 0x0?, 0x0)
/path/to/project/.gopath/pkg/mod/github.com/swaggo/swag/[email protected]/parserv3.go:611 +0xaf9
github.com/swaggo/swag/v2.(*OperationV3).ParseParamComment(0xc00852a200, {0xc000035d6b, 0x38}, 0x2?)
/path/to/project/.gopath/pkg/mod/github.com/swaggo/swag/[email protected]/operationv3.go:338 +0xcc7
github.com/swaggo/swag/v2.(*OperationV3).ParseComment(0xc00852a200, {0xc000035d60?, 0x1?}, 0x9c2060?)
/path/to/project/.gopath/pkg/mod/github.com/swaggo/swag/[email protected]/operationv3.go:86 +0x1b1
github.com/swaggo/swag/v2.(*Parser).ParseRouterAPIInfoV3(0xc000230000, 0xc0002b4680)
/path/to/project/.gopath/pkg/mod/github.com/swaggo/swag/[email protected]/parserv3.go:456 +0x213
github.com/swaggo/swag/v2.(*PackagesDefinitions).RangeFiles(0xc0001c88d0, 0xc008fbf568)
/path/to/project/.gopath/pkg/mod/github.com/swaggo/swag/[email protected]/packages.go:107 +0x2ac
github.com/swaggo/swag/v2.(*Parser).ParseAPIMultiSearchDir(0xc000230000, {0xc0002288e0?, 0x1?, 0x0?}, {0xa9b050?, 0x7?}, 0xc00022c700?)
/path/to/project/.gopath/pkg/mod/github.com/swaggo/swag/[email protected]/parser.go:422 +0x1ae
github.com/swaggo/swag/v2/gen.(*Gen).Build(0xc0001c8600, 0xc0001c0c80)
/path/to/project/.gopath/pkg/mod/github.com/swaggo/swag/[email protected]/gen/gen.go:219 +0x7bd
main.initAction(0xc00017cb00?)
/path/to/project/.gopath/pkg/mod/github.com/swaggo/swag/[email protected]/cmd/swag/main.go:207 +0xb25
github.com/urfave/cli/v2.(*Command).Run(0xc00017cb00, 0xc0001c4700, {0xc00015c2d0, 0x9, 0x9})
/path/to/project/.gopath/pkg/mod/github.com/urfave/cli/[email protected]/command.go:274 +0xa42
github.com/urfave/cli/v2.(*Command).Run(0xc00017cf20, 0xc0001c45c0, {0xc000130000, 0xa, 0xa})
/path/to/project/.gopath/pkg/mod/github.com/urfave/cli/[email protected]/command.go:267 +0xc97
github.com/urfave/cli/v2.(*App).RunContext(0xc0001aa1e0, {0xb867f0?, 0xc00012a030}, {0xc000130000, 0xa, 0xa})
/path/to/project/.gopath/pkg/mod/github.com/urfave/cli/[email protected]/app.go:332 +0x616
github.com/urfave/cli/v2.(*App).Run(...)
/path/to/project/.gopath/pkg/mod/github.com/urfave/cli/[email protected]/app.go:309
main.main()
/path/to/project/.gopath/pkg/mod/github.com/swaggo/swag/[email protected]/cmd/swag/main.go:285 +0x636
make: *** [Makefile:61: autogen] Error 2
@Nerzal Nerzal added the bug label May 24, 2023
@leonklingele
Copy link
Author

leonklingele commented Jul 15, 2023

Tracked this down to being an issue with referencing objects as type-aliases in the Success or Param directive:

// @Param data body io.UserUpdateRequest true "The updated user model"

This throws the panic:

type UserUpdateRequest = UserCreateRequest

while this doesn't:

type UserUpdateRequest UserCreateRequest

@artem328
Copy link

Hi there, I have created a pull request with the fix

@ubogdan ubogdan closed this as completed Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants