[Go 1.27] Support generic methods (methods declaring their own type parameters)
Summary
Go 1.27 (released Aug 2026) adds generic methods: a method declaration may now declare its own type parameters. swag fails to parse any scanned file containing such a declaration, even when the method is unrelated to Swagger annotations.
Environment
- Go:
go1.27.0(modulego.moddeclaresgo 1.27) - swag:
v2.0.0 - Command:
swag init -d internal/api,internal/pkg/render -g routes.go --parseInternal --v3.1 -ot yaml
Minimal reproduction
package render
// Renderer wraps an http.ResponseWriter.
type Renderer struct{ w http.ResponseWriter }
// Success is a generic method — legal only since Go 1.27.
func (r Renderer) Success[T any](msg string, data T) {
// ...
}Running swag init fails while parsing the package:
failed to parse file internal/pkg/render/render.go,
error: internal/pkg/render/render.go:61:26: method must have no type parameters (and 3 more errors)Expected behavior
Projects building with Go 1.27 should be parseable by swag. At minimum:
- Methods declaring their own type parameters should not be treated as a parse/type error.
- Ideally, response types referenced by annotations (e.g.
render.Response[T]) keep working even when the same package also contains generic methods.
Context
From the Go 1.27 release notes:
Go 1.27 now supports generic methods: a method declaration may declare its own type parameters. […] Note that methods of interfaces may not declare type parameters nor can interface methods be implemented by generic methods.
The standard library already uses this: math/rand/v2 gained the generic method (*Rand) N[Int intType](Int) Int. So new code adopting Go 1.27 will increasingly trip over this parser limitation.
Suggested fix
The rejection seems to come from the bundled type checker (pre-1.27 go/types semantics: “method must have no type parameters”). Upgrading the vendored parser / golang.org/x/tools dependency to a version built against the Go 1.27 language version should resolve it.
Happy to provide more details or test a preview build. Thanks!
Source: swaggo/swag