Thanks to visit codestin.com
Credit goes to github.com

Skip to content

goctll api swagger panic with nil pointer when there is wrong field tag in api file #4936

@wantWhatBike

Description

@wantWhatBike

Describe the bug
A clear and concise description of what the bug is.
goctll api swagger panic with nil pointer when api tag is wrong
To Reproduce
Steps to reproduce the behavior, if applicable:
write a api file with wrong field tag, such as:
endLine int form:"endLine",optional,default=100"

  1. The code is

type FileContentRequest {
clientId string form:"clientId" // 用户机器ID
codebasePath string form:"codebasePath" // 项目绝对路径
filePath string form:"filePath" // 文件相对路径
startLine int form:"startLine,optional,default=1" // 开始行(默认1)
endLine int form:"endLine",optional,default=100" // 结束行(默认100,-1=全部)
}

`form:"endLine",optional,default=100"`    this  is  wrong  tag,   when  correct  it,   cmd  run ok.
2. The error is

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x139e697]

goroutine 1 [running]:
github.com/zeromicro/go-zero/tools/goctl/api/spec.(*Tags).Get(...)
D:/programs/gopath/pkg/mod/github.com/zeromicro/go-zero/tools/[email protected]/api/spec/tags.go:52
github.com/zeromicro/go-zero/tools/goctl/api/swagger.isRequired({0x50?, 0xa7?, {0x9?, 0x26833a0?}}, 0x0)
D:/programs/gopath/pkg/mod/github.com/zeromicro/go-zero/tools/[email protected]/api/swagger/swagger.go:221 +0x17
github.com/zeromicro/go-zero/tools/goctl/api/swagger.rangeMemberAndDo({0x0?, 0x0?, {0x0?, 0x0?}}, {0x2683370?, 0xc0004bb360?}, 0xc0004bb3a0)
D:/programs/gopath/pkg/mod/github.com/zeromicro/go-zero/tools/[email protected]/api/swagger/swagger.go:215 +0xd2
github.com/zeromicro/go-zero/tools/goctl/api/swagger.parametersFromType({0xf8?, 0xb5?, {0x0?, 0x4?}}, {0xc00027fb40, 0x3}, {0x2683370, 0xc000312b40})
D:/programs/gopath/pkg/mod/github.com/zeromicro/go-zero/tools/[email protected]/api/swagger/parameter.go:43 +0x268
github.com/zeromicro/go-zero/tools/goctl/api/swagger.spec2Path({, , {, }}, {{}, {, _, _}}, {{0x0}, {0xc00027fb40, ...}, ...})
D:/programs/gopath/pkg/mod/github.com/zeromicro/go-zero/tools/[email protected]/api/swagger/path.go:90 +0x44c
github.com/zeromicro/go-zero/tools/goctl/api/swagger.spec2Paths({0x10?, 0x62?, {0x0?, 0x8?}}, {{0xc000296200, 0xf}, {0xc00039a180, 0x3, 0x4}})
D:/programs/gopath/pkg/mod/github.com/zeromicro/go-zero/tools/[email protected]/api/swagger/path.go:24 +0x39d
github.com/zeromicro/go-zero/tools/goctl/api/swagger.spec2Swagger(0xc0000dc690)
D:/programs/gopath/pkg/mod/github.com/zeromicro/go-zero/tools/[email protected]/api/swagger/swagger.go:32 +0x3da
github.com/zeromicro/go-zero/tools/goctl/api/swagger.Command(0xc000396100?, {0x23fbcd2?, 0x4?, 0x23fbbd6?})
D:/programs/gopath/pkg/mod/github.com/zeromicro/go-zero/tools/[email protected]/api/swagger/command.go:49 +0xb9
github.com/spf13/cobra.(*Command).execute(0xc000394908, {0xc0000b4180, 0x6, 0x6})
D:/programs/gopath/pkg/mod/github.com/spf13/[email protected]/command.go:1015 +0xaaa
github.com/spf13/cobra.(*Command).ExecuteC(0xc0002dc908)
D:/programs/gopath/pkg/mod/github.com/spf13/[email protected]/command.go:1148 +0x46f
github.com/spf13/cobra.(*Command).Execute(...)
D:/programs/gopath/pkg/mod/github.com/spf13/[email protected]/command.go:1071
github.com/zeromicro/go-zero/tools/goctl/cmd.Execute()
D:/programs/gopath/pkg/mod/github.com/zeromicro/go-zero/tools/[email protected]/cmd/root.go:47 +0x6c
main.main()
D:/programs/gopath/pkg/mod/github.com/zeromicro/go-zero/tools/[email protected]/goctl.go:12 +0x48


**Expected behavior**
A clear and concise description of what you expected to happen.
run ok    or   tell me   what's wrong.
**Screenshots**
If applicable, add screenshots to help explain your problem.

**Environments (please complete the following information):**
- OS: window
- go-zero 1.8.3
- goctl version 1.8.3

**More description**
Add any other context about the problem here.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions