tsoa
tsoa copied to clipboard
`fields` stringify'd in some Validation responses
Quick question...
(cc: @WoH as the original author)
I was trying out some of the Validation work, and I was wondering...
In the following examples, is there a reason it's JSON.stringify
'ing the field errors to the message instead of setting it as a property?
Examples:
https://github.com/lukeautry/tsoa/blob/641f12c32440b1b146c59ba7fc74f7f54cf1d383/packages/runtime/src/routeGeneration/templateHelpers.ts#L483 https://github.com/lukeautry/tsoa/blob/641f12c32440b1b146c59ba7fc74f7f54cf1d383/packages/runtime/src/routeGeneration/templateHelpers.ts#L515 https://github.com/lukeautry/tsoa/blob/641f12c32440b1b146c59ba7fc74f7f54cf1d383/packages/runtime/src/routeGeneration/templateHelpers.ts#L559 https://github.com/lukeautry/tsoa/blob/641f12c32440b1b146c59ba7fc74f7f54cf1d383/packages/runtime/src/routeGeneration/templateHelpers.ts#L548
Then when I catch the ValidateError
, err.fields
has the following structure
"login": {
"message": "Could not match the union against any of the items. Issues: [{\"login.provider\":{\"message\":\"'provider' is required\"},\"login.email\":{\"message\":\"'email' is required\"}},{\"login.provider\":{\"message\":\"'provider' is required\"},\"login.email\":{\"message\":\"'email' is required\"}}]",
"value": {}
}
The stringify'd JSON isn't incredibly handy, what are your thoughts on a updated structure being:
"login": {
"message": "Could not match the union against any of the items.",
"fields": [
{
"login.provider":{
"message":"'provider' is required"
},
"login.email":{
"message":"'email' is required"
}
}
]
"value": {}
}
Also FYI I'm happy to make a PR if you think this is a good idea.
The reason is that the errors can affect the same property.
We can make a breaking change here, but I'd have to see a format that works for all the cases involved.
I'll take a stab at making a PR so we can make the determination if it is a breaking change
thanks @WoH
any update about this ?
I was looking into this as well. Simply stringifying the validator error makes the message incomprehensible. @cnuss have you worked on this issue at all?
Sorry no I never got around to it l!
@WoH does repeating the the same key in the values array breaks something? In case of #1170 the error would be:
[
{
"requestBody.$0.email": {
"message": "maxLength 10",
"value": "PCPNPsdfsdfsdfsdfsfgsdgf"
}
},
{
"requestBody.$0.email": {
"message": "should be one of the following; [null]",
"value": "PCPNPsdfsdfsdfsdfsfgsdgf"
}
}
]
but would still be more informative.