-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Struct methods cause schema generation to fail #55
Comments
Iv'e done a little bit of looking into this and it seems to be a bug with NB: this is base on a little bit of scrolling through Github issues so I might have a few things wrong here but this is the issue as I understand it. When passing around a struct method under the hood the go compiler wraps it in a closure and that is what actually gets passed. The auto generated closure has a synthetic file and line metadata so what is being returned by Interestingly this actually used to work in <= 1.17.x Take the following example package main
import (
"fmt"
"reflect"
"runtime"
"github.com/davecgh/go-spew/spew"
)
type MyStruct struct{}
func (MyStruct) ValueRecv() {}
func (*MyStruct) PtrRecv() {}
func MyFunc() {}
func main() {
val := MyStruct{}
inspect(val.ValueRecv)
inspect((&val).PtrRecv)
inspect(MyFunc)
inspect(MyStruct.ValueRecv)
inspect((*MyStruct).ValueRecv)
}
func inspect(v interface{}) {
pc := reflect.ValueOf(v).Pointer()
spew.Dump(runtime.FuncForPC(pc).FileLine(pc))
spew.Dump(runtime.FuncForPC(pc).Name())
fmt.Println("-----")
} when ran in 1.22.2: :!go run /home/indeedhat/Documents/github/fuckery/funcforpc/main.go
(string) (len=15) "<autogenerated>"
(int) 1
(string) (len=26) "main.MyStruct.ValueRecv-fm"
-----
(string) (len=15) "<autogenerated>"
(int) 1
(string) (len=27) "main.(*MyStruct).PtrRecv-fm"
-----
(string) (len=58) "/home/indeedhat/Documents/github/fuckery/funcforpc/main.go"
(int) 17
(string) (len=11) "main.MyFunc"
-----
(string) (len=58) "/home/indeedhat/Documents/github/fuckery/funcforpc/main.go"
(int) 13
(string) (len=23) "main.MyStruct.ValueRecv"
-----
(string) (len=15) "<autogenerated>"
(int) 1
(string) (len=26) "main.(*MyStruct).ValueRecv"
----- and 1.17.13 :!go1.17.13 run /home/indeedhat/Documents/github/fuckery/funcforpc/main.go
(string) (len=58) "/home/indeedhat/Documents/github/fuckery/funcforpc/main.go"
(int) 13
(string) (len=26) "main.MyStruct.ValueRecv-fm"
-----
(string) (len=58) "/home/indeedhat/Documents/github/fuckery/funcforpc/main.go"
(int) 15
(string) (len=27) "main.(*MyStruct).PtrRecv-fm"
-----
(string) (len=58) "/home/indeedhat/Documents/github/fuckery/funcforpc/main.go"
(int) 17
(string) (len=11) "main.MyFunc"
-----
(string) (len=58) "/home/indeedhat/Documents/github/fuckery/funcforpc/main.go"
(int) 13
(string) (len=23) "main.MyStruct.ValueRecv"
-----
(string) (len=15) "<autogenerated>"
(int) 1
(string) (len=26) "main.(*MyStruct).ValueRecv"
----- There are a number of issues open and closed around this and related topics such as the -fm name suffix but I'm not hopeful for a fix any time soon. My current rabbit hole is trying to find out if I can use the name to get a reference back to the parent type but I'm not hopeful at this point. |
@indeedhat Thank you very much for looking into this issues, we've come to a similar conclusion (probably should have documented that, sorry). We're looking at moving away from using |
Issue Description
Gin handlers that are struct methods cause schema generation to fail.
Steps to Reproduce
main.go
with this content:go get .
main.go
:go run main.go
Expected Behaviour
Bellow is the expected output in
openapi.generated.yaml
from runningmain.go
.Actual Behaviour
No schema is generated and the bellow error is output in the logs:
Rel: can't make <autogenerated> relative to <path to backend>
Additional Information
The text was updated successfully, but these errors were encountered: