huma
huma copied to clipboard
Different behaviour of enum when using it as a value in the body and when using it as a query parameter
Hi, I am defining my enum the following way:
// ENUM(val1, val2, val3).
type BankAccountType uint8
I use go-enum to generate the boilerplate code e.g.
const (
BankAccountTypeVal1 BankAccountType = iota
BankAccountTypeVal2
BankAccountTypeVal3
)
and I have it as a value in the body of a POST request:
type Request struct {
Body CreateReqBody
}
type CreateReqBody struct {
...
Type BankAccountType `json:"bank_account_type"`
...
}
and I have a GET request where I want to use it as a query parameter:
type Request struct {
BankAccountType BankAccountType `query:"bank_account_type"`
...
}
When I run a POST request with a body like
{"bank_account_type": "val1"}
everything works as expected and the correct value of the enum is binded to BankAccountTypeVal1
however my GET request which is like
{
Message: "invalid integer",
Location: "query.bank_account_type",
Value: <string>"val1",
},
Why is the different behaviour? How can I make it work?