Skip to content

Crash (segmentation violation) on Generic Struct of enum array #2080

@MrVermond

Description

@MrVermond

Describe the bug
When generating the api description the generator crashes with the following message

2025/10/07 07:47:06 Generating model.NickTest
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x8f8404]

goroutine 1 [running]:
github.com/swaggo/swag.(*tagBaseFieldParser).complementSchema(0xc00cb8dbe0, 0xc00bab80a8, {0xc00cb8dd20, 0x2, 0x22?})
        /go/pkg/mod/github.com/swaggo/[email protected]/field_parser.go:466 +0x1004
github.com/swaggo/swag.(*tagBaseFieldParser).ComplementSchema(0xc00cb8dbe0, 0xc00f952488)
        /go/pkg/mod/github.com/swaggo/[email protected]/field_parser.go:252 +0xf7
github.com/swaggo/swag.(*Parser).parseStructField(0xc00019b440, 0xc00014d9a0, 0xc00f845dc0)
        /go/pkg/mod/github.com/swaggo/[email protected]/parser.go:1652 +0x46e
github.com/swaggo/swag.(*Parser).parseStruct(0xc00019b440, 0xc00014d9a0, 0xc00f935e00)
        /go/pkg/mod/github.com/swaggo/[email protected]/parser.go:1554 +0xcd
github.com/swaggo/swag.(*Parser).parseTypeExpr(0xc00f92b861?, 0xad2932?, {0xbdbc00?, 0xc00f76daa0?}, 0x60?)
        /go/pkg/mod/github.com/swaggo/[email protected]/parser.go:1507 +0x267
github.com/swaggo/swag.(*Parser).ParseDefinition(0xc00019b440, 0xc00f8d3080)
        /go/pkg/mod/github.com/swaggo/[email protected]/parser.go:1356 +0x52d
github.com/swaggo/swag.(*Parser).getTypeSchema(0xc00019b440, {0xc000a7939a, 0x25}, 0xc0007add60, 0x1)
        /go/pkg/mod/github.com/swaggo/[email protected]/parser.go:1271 +0x686
github.com/swaggo/swag.parseObjectSchema(0xc00019b440, {0xc000a7939a, 0x25}, 0xc0007add60)
        /go/pkg/mod/github.com/swaggo/[email protected]/operation.go:886 +0x8bd
github.com/swaggo/swag.(*Operation).parseObjectSchema(...)
        /go/pkg/mod/github.com/swaggo/[email protected]/operation.go:842
github.com/swaggo/swag.(*Operation).parseAPIObjectSchema(0xc00f8ddb00, {0xc000a7938d, 0x32}, {0xc000a79392, 0x6}, {0xc000a7939a, 0x25}, 0xc0007add60)
        /go/pkg/mod/github.com/swaggo/[email protected]/operation.go:975 +0x3c6
github.com/swaggo/swag.(*Operation).ParseResponseComment(0xc00f8ddb00, {0xc000a7938d, 0x32}, 0xc0007add60)
        /go/pkg/mod/github.com/swaggo/[email protected]/operation.go:1007 +0x145
github.com/swaggo/swag.(*Operation).ParseComment(0xc00f8ddb00, {0xc000a79380?, 0x1?}, 0xc0007add60)
        /go/pkg/mod/github.com/swaggo/[email protected]/operation.go:149 +0x3a5
github.com/swaggo/swag.(*Parser).parseRouterAPIInfoComment(0xc00019b440, {0xc000999280, 0xc, 0x10}, 0xc000aa5380)
        /go/pkg/mod/github.com/swaggo/[email protected]/parser.go:1120 +0x129
github.com/swaggo/swag.(*Parser).ParseRouterAPIInfo(0xc00019b440, 0xc000aa5380)
        /go/pkg/mod/github.com/swaggo/[email protected]/parser.go:1106 +0xd1
github.com/swaggo/swag.(*PackagesDefinitions).RangeFiles(0xc0002925a0, 0xc00bab9778)
        /go/pkg/mod/github.com/swaggo/[email protected]/packages.go:107 +0x33c
github.com/swaggo/swag.(*Parser).ParseAPIMultiSearchDir(0xc00019b440, {0xc00028eac0, 0x1, 0x0?}, {0x7fff4b15b50e, 0x7}, 0x64)
        /go/pkg/mod/github.com/swaggo/[email protected]/parser.go:468 +0x62d
github.com/swaggo/swag/gen.(*Gen).Build(0xc0002923c0, 0xc0000f2900)
        /go/pkg/mod/github.com/swaggo/[email protected]/gen/gen.go:225 +0x7c6
main.initAction(0xc00028cc00)
        /go/pkg/mod/github.com/swaggo/[email protected]/cmd/swag/main.go:248 +0xa12
github.com/urfave/cli/v2.(*Command).Run(0xc00019afc0, 0xc00028c0c0)
        /go/pkg/mod/github.com/urfave/cli/[email protected]/command.go:163 +0x565
github.com/urfave/cli/v2.(*App).RunContext(0xc0000d5520, {0xbdcc08, 0x1076a00}, {0xc000022090, 0x9, 0x9})
        /go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:313 +0xae7
github.com/urfave/cli/v2.(*App).Run(...)
        /go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:224
main.main()
        /go/pkg/mod/github.com/swaggo/[email protected]/cmd/swag/main.go:339 +0x56f

To Reproduce
Steps to reproduce the behavior:

  1. Create the following objects
type NickTest string

const (
	NicksStable NickTest = "STABLE"
)

type NicksResponse[TData any] struct {
	Data TData  `json:"data"`
}

// ....
//	@Success		200	{object}	model.NicksResponse[[]model.NickTest]
func ...someGoFuncWhichDoesTheReturn
  1. Call generator with swag init -d ./ -g main.go --output ./docs --parseDependency

Expected behavior
No crash happens

Screenshots

Your swag version
e.g. 1.16.6

Your go version
e.g. 1.24.7

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser: [e.g. chrome, safari]
  • Version: [e.g. 22]

Additional context

Metadata

Metadata

Assignees

No one assigned

    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