Closed tortuoise closed 6 years ago
Will be good to have somebody replicate this problem or point out any errors in my example setup.
yeah I can reproduce the error, it's becuase there is no producer registered. The following version of your code works properly:
package main
import (
"fmt"
"playground/client"
"playground/client/todos"
"playground/models"
"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
)
func main() {
cfg := client.DefaultTransportConfig()
cfg.Host = "localhost:40083"
cfg.Schemes = []string{"http"}
t1 := client.NewHTTPClient(strfmt.Default)
tr := httptransport.New(cfg.Host, cfg.BasePath, cfg.Schemes)
tr.Consumers["application/io.swagger.examples.todo-list.v1+json"] = runtime.JSONConsumer()
tr.Producers["application/io.swagger.examples.todo-list.v1+json"] = runtime.JSONProducer()
t1.SetTransport(tr)
hand := runtime.ClientAuthInfoWriterFunc(func(r runtime.ClientRequest, _ strfmt.Registry) error {
return r.SetHeaderParam("x-todolist-token", "asdf")
})
x := "Do this and that"
a1 := todos.NewAddOneParams()
a1 = a1.WithBody(&models.Item{Description: &x})
added, err := t1.Todos.AddOne(a1, hand)
if err != nil {
fmt.Println("Error: ", err)
}
if added != nil {
fmt.Printf("%#v\n", added.Payload)
fmt.Println(added.Error())
} else {
fmt.Println("Added nil")
}
}
Thanks very much! I was close to giving up on client gen.
Will it be useful to add a map access check to go-openapi/runtime/client/runtime.go before the call to buildHTTP?
if _, ok := r.Producers[cmt]; !ok { return nil, fmt.Errorf("%v", "Producer not registered") }
sounds like a good idea, are you offering a PR?
Done.
Problem statement
Fatal error: malloc deadlock using generated server and client
Swagger specification
Steps to reproduce
Generate todos server and client and then create new package main with this:
Run server and run client snippet above. Error results.
Just passing nil to AddOne which calls NewAddOneParams() without a body works without error.
Stack trace:
Environment
swagger version: x.x.x
go version: 1.10 OS: Ubuntu 16.04..3 LTS