Open norbertstrzelecki opened 7 months ago
I've run into that too. Here's a workaround until fizz
and tonic
get updated.
So, the binding error happens because tonic
tries to use JSON unmarshal when it sees a handler with a request object. To get around it, you gotta set up a custom binding hook:
type Evaluation struct {
UserID string `query:"userId" validate:"required" description:"Id of user"`
}
// implement Binder for your request struct
func (e *Evaluation) ShouldBind() bool {
return false
}
type Binder interface {
ShouldBind() bool
}
func CustomBindHook(c *gin.Context, in any) error {
if binder, ok := in.(Binder); ok {
if !binder.ShouldBind() {
return nil
}
}
return tonic.DefaultBindingHook(c, in)
}
// add following code somewhere when setup route
tonic.SetBindHook(CustomBindHook)
Next, since you cannot set custom content types in fizz
right now, you'll need to tweak the OpenAPI schema object directly. Because it's a bit of a hassle, I won't be writing the code here.
While sending an audio file within the request body, I'm receiving the following error:
As I understand, the audio file is parsed as a
string
and not the binary file -- the "R" is from string "RIFF" file header. The question is whether I could bind it as anaudio/wav
type as described below?The request looks like this:
So I send
userId
as a param and binary audio file in the body asaudio/wav
content type.Code-wise, the handler functions look like this:
and the structs:
BTW While generating OpenAPI YAML, the part I'm interested in looks like this:
and I need this: