'How to format bad request error when whole request could not be parsed because of invalid enum?
My request has enum property (enum FrontendId { Frontend1, Frontend2 }) and when invalid value is passed in that property I get following 400 response (for example if I pass {"frontendId": "invalid"}):
{
"request": [
"The request field is required."
],
"$.frontendId": [
"The JSON value could not be converted to Api.Models.ClientApi.LoginStart.LoginStartRequest. Path: $.frontendId | LineNumber: 1 | BytePositionInLine: 27."
]
}
But when I add custom Fluent validator for request to just for example whitlist some enum values and pass valid enum value in request then I get 400 response in normal format (for example if I pass {"frontendId": "Frontend2"}, which is not whitelisted):
{
"FrontendId": [
"The specified condition was not met for 'Frontend Id'."
]
}
In other words - when request can not be parsed because of invalid enum value then strange response is returned with request and $.frontendId keys. How I can fix this to not include "request" and have "FrontendId" instead of "$.frontendId"?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
