swaggo / swag

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

cannot find type definition in import module #1879

Closed huyinghuan closed 1 week ago

huyinghuan commented 1 week ago

Describe the bug

i define struct in dir schemas like this:

image

if remove the red frame code: image

it can pares success, but in the swagger.json is

image

this is different with other schemas:

image

when i try to add import _ "github.com/xxxxxx/xxxxxx/apps/modules/voteprogram/schemas"

it will report error : :cannot find type definition: schemas.VoteProgram,

I have many schemas in other module,them can parse to swagger success, I don't know what caused this error, is there any way to avoid it, thank you.

To Reproduce

Expected behavior

find the define and in swagger.json should be "$ref": "#/definitions/github_com_XXXXX_xxxx-xxx_apps_modules_voteprogram_schemas.VoteProgram"

Screenshots

Your swag version

1.16.3 , i build from master

Your go version

go1.22.5

Desktop (please complete the following information):

centos stream 8

Additional context Add any other context about the problem here.

huyinghuan commented 1 week ago

and some struct define cannot found too. like api.VoteProgramForm ,
image image

and i try copy modules/voteprogram/internal/api to modules/voteprogram/api i got runtime error :

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

goroutine 1 [running]:
github.com/swaggo/swag.(*PackagesDefinitions).FindTypeSpec(0xc0001c18c0, {0xc0007f379a, 0x4}, 0xc0008da280)
        /home/xxxx/workspace/swag/packages.go:599 +0x5ce
github.com/swaggo/swag.(*Parser).getTypeSchema(0xc000025320, {0xc0007f379a, 0x4}, 0xc0008da280, 0x0)
        /home/xxxx/workspace/swag/parser.go:1186 +0x592
github.com/swaggo/swag.(*Operation).ParseParamComment(0xc021f298c0, {0xc0007f378a, 0x2e}, 0xc0008da280)
        /home/xxxx/workspace/swag/operation.go:272 +0x765
github.com/swaggo/swag.(*Operation).ParseComment(0xc021f298c0, {0xc0007f3780?, 0x1?}, 0xc0008da280)
        /home/xxxx/workspace/swag/operation.go:145 +0x198
github.com/swaggo/swag.(*Parser).parseRouterAPIInfoComment(0xc000025320, {0xc0008d6e80, 0xd, 0x10}, 0xc00091ea00)
        /home/xxxx/workspace/swag/parser.go:1064 +0x145
github.com/swaggo/swag.(*Parser).ParseRouterAPIInfo(0xc000025320, 0xc00091ea00)
        /home/xxxx/workspace/swag/parser.go:1050 +0xba
github.com/swaggo/swag.(*PackagesDefinitions).RangeFiles(0xc0001c18c0, 0xc018a9f798)
        /home/xxxx/workspace/swag/packages.go:107 +0x33e
github.com/swaggo/swag.(*Parser).ParseAPIMultiSearchDir(0xc000025320, {0xc0001d3650, 0x1, 0x0?}, {0x7ffecb407d4d, 0x12}, 0x3e8)
        /home/xxxx/workspace/swag/parser.go:457 +0x645
github.com/swaggo/swag/gen.(*Gen).Build(0xc0001c16e0, 0xc000002180)
        /home/xxxx/workspace/swag/gen/gen.go:221 +0x89a
main.initAction(0xc0001f4800)
        /home/xxxx/workspace/swag/cmd/swag/main.go:243 +0x9e5
github.com/urfave/cli/v2.(*Command).Run(0xc000024ea0, 0xc00004bcc0)
        /home/xxxx/go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/command.go:163 +0x583
github.com/urfave/cli/v2.(*App).RunContext(0xc0000dd520, {0xacec18, 0xeabbe0}, {0xc000024120, 0x12, 0x12})
        /home/xxxx/go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/app.go:313 +0xae5
github.com/urfave/cli/v2.(*App).Run(...)
        /home/xxxx/go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/app.go:224
main.main()
        /home/xxxx/workspace/swag/cmd/swag/main.go:333 +0x56f
huyinghuan commented 1 week ago

I am so foolish, in the router i dont have inject to main router like this:

import (voteProgramRouter "github.com/xxxx/xxx/apps/modules/voteprogram/router")
....
app := iris.New()
app.PartyFunc("/vote-program", voteProgramRouter.Inject)