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

Panic while using interface or []interface param type #1689

Open
guning opened this issue Oct 20, 2023 · 0 comments
Open

Panic while using interface or []interface param type #1689

guning opened this issue Oct 20, 2023 · 0 comments

Comments

@guning
Copy link

guning commented Oct 20, 2023

Describe the bug

Panic while using interface or []interface param type

To Reproduce

code:

type LogSearchRequest  struct {
	Size  int           `json:"size"`
	After []interface{} `json:"after"` // es cursor
        StartAt int64 `json:"start_at"`
        EndAt int64 `json:"end_at"`
}

// @Param request query LogSearchRequest true "query param"
func API()....

command: swag.exe init --pd

Expected behavior

...
2023/10/20 10:23:59 Generating syslogApi.LogSearchRequest
2023/10/20 10:23:59 Generating syslogApi.LogRequest
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x68 pc=0x13b1ba5]

goroutine 1 [running]:
github.com/swaggo/swag/v2.(*Operation).ParseParamComment(0xc036c0bd40, {0xc00062e46a, 0x3c}, 0x2?)
        D:/guning/goruntime/modcache/github.com/swaggo/swag/[email protected]/operation.go:324 +0x1da5
github.com/swaggo/swag/v2.(*Operation).ParseComment(0xc036c0bd40, {0xc00062e460?, 0x1?}, 0xc02ac71440?)
        D:/guning/goruntime/modcache/github.com/swaggo/swag/[email protected]/operation.go:143 +0x1c5
github.com/swaggo/swag/v2.(*Parser).ParseRouterAPIInfo(0xc000180000, 0xc000173e00)
        D:/guning/goruntime/modcache/github.com/swaggo/swag/[email protected]/parser.go:1005 +0x214
github.com/swaggo/swag/v2.(*PackagesDefinitions).RangeFiles(0xc000115140, 0xc02ac71568)
        D:/guning/goruntime/modcache/github.com/swaggo/swag/[email protected]/packages.go:107 +0x2ad
github.com/swaggo/swag/v2.(*Parser).ParseAPIMultiSearchDir(0xc000180000, {0xc000176b70?, 0x1?, 0x0?}, {0x159aa56?, 0x7?}, 0x221ca526558?)
        D:/guning/goruntime/modcache/github.com/swaggo/swag/[email protected]/parser.go:427 +0x1f6
github.com/swaggo/swag/v2/gen.(*Gen).Build(0xc000114e70, 0xc00010cdc0)
        D:/guning/goruntime/modcache/github.com/swaggo/swag/[email protected]/gen/gen.go:219 +0x79d
main.initAction(0xc0000ca9a0?)
        D:/guning/goruntime/modcache/github.com/swaggo/swag/[email protected]/cmd/swag/main.go:207 +0xb25
github.com/urfave/cli/v2.(*Command).Run(0xc0000ca9a0, 0xc000110980, {0xc00006a660, 0x6, 0x6})
        D:/guning/goruntime/modcache/github.com/urfave/cli/[email protected]/command.go:274 +0xa42
github.com/urfave/cli/v2.(*Command).Run(0xc0000cadc0, 0xc000110840, {0xc0000a4000, 0x7, 0x8})
        D:/guning/goruntime/modcache/github.com/urfave/cli/[email protected]/command.go:267 +0xc8a
github.com/urfave/cli/v2.(*App).RunContext(0xc0000003c0, {0x1681708?, 0xc000018190}, {0xc0000a4000, 0x7, 0x8})
        D:/guning/goruntime/modcache/github.com/urfave/cli/[email protected]/app.go:332 +0x605
github.com/urfave/cli/v2.(*App).Run(...)
        D:/guning/goruntime/modcache/github.com/urfave/cli/[email protected]/app.go:309
main.main()
        D:/guning/goruntime/modcache/github.com/swaggo/swag/[email protected]/cmd/swag/main.go:285 +0x5e6

Screenshots

--

Your swag version

2.0.0-rc3

Your go version

1.18.10

Desktop (please complete the following information):

  • OS: Windows11
  • Browser:--
  • Version:--

Additional context

I found that func getUnderlyingSchema returns nil when the underlay param type is "interface{}". Caller without nil checking will run into fatal panic.

https://github.com/swaggo/swag/blob/master/operation.go#L310
https://github.com/swaggo/swag/blob/master/operation.go#L330

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

1 participant