swaggo / swag

Automatically generate RESTful API documentation with Swagger 2.0 for Go.
MIT License
10.7k stars 1.2k forks source link

Error while generating models #1639

Open asadrajput2 opened 1 year ago

asadrajput2 commented 1 year ago

Describe the bug I am getting nil pointer dereference error on running swag init -g ./cmd/main.go -v3.1. Only getting this error on v2. It is working fine for swagger 2.0 (swag init -g ./cmd/main.go)

Expected behavior Docs files should be generated without any errors

Your swag version v2.0.0

Your go version 1.20.4

Desktop (please complete the following information):

Additional context This is the error I get (with some lines before for context):

023/08/02 19:20:10 Generating models.Org
2023/08/02 19:20:10 Generating common.CodeResponse
found schema with no Type, returning any
2023/08/02 19:20:10 Generating models.ContactUs
2023/08/02 19:20:10 Generating models.Apps
2023/08/02 19:20:10 Generating models.Model
2023/08/02 19:20:10 Generating models.Keys
2023/08/02 19:20:10 Generating models.AppDetails
2023/08/02 19:20:10 Generating models.Url
2023/08/02 19:20:10 Generating models.Profile
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x8ea138]

goroutine 1 [running]:
github.com/swaggo/swag/v2.(*Parser).GetSchemaTypePathV3(0xc0001f6000, 0xc0001f0500, 0x2)
    /home/username/go/pkg/mod/github.com/swaggo/swag/v2@v2.0.0-rc3/parserv3.go:997 +0x118
github.com/swaggo/swag/v2.(*tagBaseFieldParserV3).ComplementSchema(0xc0004bdd80, 0xc0002d56c0?)
    /home/username/go/pkg/mod/github.com/swaggo/swag/v2@v2.0.0-rc3/field_parserv3.go:125 +0xb8
github.com/swaggo/swag/v2.(*Parser).parseStructFieldV3(0xc0001f6000, 0xc000473e90?, 0xc0002d56c0)
    /home/username/go/pkg/mod/github.com/swaggo/swag/v2@v2.0.0-rc3/parserv3.go:921 +0x3ec
github.com/swaggo/swag/v2.(*Parser).parseStructV3(0x0?, 0x31?, 0xc0002f0450)
    /home/username/go/pkg/mod/github.com/swaggo/swag/v2@v2.0.0-rc3/parserv3.go:817 +0xf6
github.com/swaggo/swag/v2.(*Parser).parseTypeExprV3(0xc000188280?, 0xabe831?, {0xb972a0?, 0xc0002ec480?}, 0x0?)
    /home/username/go/pkg/mod/github.com/swaggo/swag/v2@v2.0.0-rc3/parserv3.go:740 +0xc7
github.com/swaggo/swag/v2.(*Parser).ParseDefinitionV3(0xc0001f6000, 0xc000933680)
    /home/username/go/pkg/mod/github.com/swaggo/swag/v2@v2.0.0-rc3/parserv3.go:660 +0x44b
github.com/swaggo/swag/v2.(*Parser).getTypeSchemaV3(0xc0001f6000, {0xc000612483, 0x11}, 0xc0006361c1?, 0x0)
    /home/username/go/pkg/mod/github.com/swaggo/swag/v2@v2.0.0-rc3/parserv3.go:611 +0xa19
github.com/swaggo/swag/v2.(*OperationV3).ParseParamComment(0xc00096b800, {0xc00061246c, 0x42}, 0x2?)
    /home/username/go/pkg/mod/github.com/swaggo/swag/v2@v2.0.0-rc3/operationv3.go:338 +0x787
github.com/swaggo/swag/v2.(*OperationV3).ParseComment(0xc00096b800, {0xc000612460?, 0x1?}, 0xa0cce0?)
    /home/username/go/pkg/mod/github.com/swaggo/swag/v2@v2.0.0-rc3/operationv3.go:86 +0x1a5
github.com/swaggo/swag/v2.(*Parser).ParseRouterAPIInfoV3(0xc0001f6000, 0xc0003fa980)
    /home/username/go/pkg/mod/github.com/swaggo/swag/v2@v2.0.0-rc3/parserv3.go:456 +0x1ee
github.com/swaggo/swag/v2.(*PackagesDefinitions).RangeFiles(0xc0001da540, 0xc00059d548)
    /home/username/go/pkg/mod/github.com/swaggo/swag/v2@v2.0.0-rc3/packages.go:107 +0x2b3
github.com/swaggo/swag/v2.(*Parser).ParseAPIMultiSearchDir(0xc0001f6000, {0xc0001f0be0, 0x1, 0x0?}, {0x7ffd9e995319, 0xd}, 0x1000000a9bbe0?)
    /home/username/go/pkg/mod/github.com/swaggo/swag/v2@v2.0.0-rc3/parser.go:422 +0x3ce
github.com/swaggo/swag/v2/gen.(*Gen).Build(0xc0001da270, 0xc000186b40)
    /home/username/go/pkg/mod/github.com/swaggo/swag/v2@v2.0.0-rc3/gen/gen.go:219 +0x87d
main.initAction(0xc00015a420?)
    /home/username/go/pkg/mod/github.com/swaggo/swag/v2@v2.0.0-rc3/cmd/swag/main.go:207 +0xb25
github.com/urfave/cli/v2.(*Command).Run(0xc00015a420, 0xc00018a480, {0xc00018a4c0, 0x4, 0x4})
    /home/username/go/pkg/mod/github.com/urfave/cli/v2@v2.25.1/command.go:274 +0x9eb
github.com/urfave/cli/v2.(*Command).Run(0xc00015a840, 0xc00018a300, {0xc0000240a0, 0x5, 0x5})
    /home/username/go/pkg/mod/github.com/urfave/cli/v2@v2.25.1/command.go:267 +0xc4d
github.com/urfave/cli/v2.(*App).RunContext(0xc00016c1e0, {0xb97a28?, 0xc000026088}, {0xc0000240a0, 0x5, 0x5})
    /home/username/go/pkg/mod/github.com/urfave/cli/v2@v2.25.1/app.go:332 +0x616
github.com/urfave/cli/v2.(*App).Run(...)
    /home/username/go/pkg/mod/github.com/urfave/cli/v2@v2.25.1/app.go:309
main.main()
    /home/username/go/pkg/mod/github.com/swaggo/swag/v2@v2.0.0-rc3/cmd/swag/main.go:285 +0x636

I have gone through issue #1590 and I don't have any object referenced as type aliases

tony-spark commented 1 year ago

Have the same issue

dan-r95 commented 1 year ago

same issue.