Support for application/x-www-form-urlencoded? #426
-
I'm trying to create an endpoint that can accept both I've created a body struct that I try to reuse using reflection like so: type GetTokenInputBody struct {
ClientId string `form:"client_id" json:"client_id" example:"bob"`
ClientSecret string `form:"client_secret" json:"client_secret" example:"vErYSeCrEt"`
GrantType string `form:"grant_type" json:"grant_type" example:"client_credentials"`
}
type GetTokenInput struct {
Body GetTokenInputBody
}
...
huma.Register(
api,
huma.Operation{
OperationID: "auth-get-token",
Method: http.MethodPost,
Path: "/auth/token",
Summary: "Get Token",
Description: "Authenticate clients",
Tags: []string{"Auth"},
RequestBody: &huma.RequestBody{
Description: "Get Token",
Content: map[string]*huma.MediaType{
"application/json": {
Schema: api.OpenAPI().Components.Schemas.Schema(
reflect.TypeOf(GetTokenInputBody{}), true, "",
),
},
"application/x-www-form-urlencoded": {
Schema: api.OpenAPI().Components.Schemas.Schema(
reflect.TypeOf(GetTokenInputBody{}), true, "",
),
},
},
},
},
GetToken,
) My OpenAPI docs are correct and I see both content types, but when I try to call the endpoint I get the following error: {
"$schema": "https://127.0.0.1:3000/schemas/ErrorModel.json",
"title": "Unsupported Media Type",
"status": 415,
"detail": "validation failed",
"errors": [
{
"message": "unknown content type: application/x-www-form-urlencoded",
"location": "body",
"value": "aHR0cHM6Ly8xMjcuMC4wLjE6MzAwMC9zY2hlbWFzL0Vycm9yTW9kZWwuanNvbmVudF9jcmVkZW50aWFscw=="
}
]
} What am I missing? |
Beta Was this translation helpful? Give feedback.
Answered by
davidolrik
Apr 30, 2024
Replies: 1 comment
-
I just found #285 (comment), so I guess patches welcome =) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
davidolrik
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just found #285 (comment), so I guess patches welcome =)