oapi-codegen
oapi-codegen copied to clipboard
Gin strict handler uses Bind which causes the request to abort without error
Gin Bind
(MustBind
under the hood) aborts the request immediately and sends a 400 error as plain text to the client.
if err := ctx.Bind(&body); err != nil {
ctx.Error(err)
return
}
This prevents any custom error handler from setting the proper content-type headers.
My suggestion would be to use ShouldBind
instead and set the response status code for backward compatibility:
if err := ctx.ShouldBind(&body); err != nil {
ctx.Status(http.StatusBadRequest)
ctx.Error(err)
return
}