You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
used the search to make sure that a similar issue hasn't already been submit
Expected Behavior
Attempt to figure out which type a payload most conforms to amongst a union of many types before doing validation.
OR
as a workaround (for me) export validationService in the hapi.hbs template. I would like to be able to use this service directly to validate some things manually so the error response is more meaningful
Current Behavior
The issue is that some of our apis allow payloads of a of a type that is union of many types. When validation fails, the response is unhelpful because for each incorrect param, it lists out all of the types that it could be amongst the union of all types. In our pre-response handler, i'd like to intercept those validation errors and essentially revalidate the payload against the intended type.
Possible Solution
the ideal solution would be for the validator to see that the incoming payload has type "COW", so validate it against the Animal1 interface. (this is referencing the simplified code example below)
the other solution is to just expose the validationService in hapi.hbs so that i can manually do this check and show a meaningful error message.
Steps to Reproduce
simplified example:
// type definitions
interface Animal1 {
type: 'COW';
legs: number;
spots: number;
}
interface Animal2 {
type: 'CHICKEN';
legs: number;
feathers: number
}
interface Animal3 {
type: 'DOG';
legs: number;
barks: boolean;
}
type Animal = Animal1 | Animal2 | Animal3;
// api definition in a controller
@Post('animal')
updateAnimal ( @Body() body: Animal ) {
// do stuff
}
{
"name": "ValidateError",
"fields": {
"body": {
"message": "Could not match the union against any of the items. Issues: [{\"body.spots\":{\"message\":\"'spots' is required\"}},{\"body.type\":{\"message\":\"should be one of the following; ['CHICKEN']\",\"value\":\"COW\"},\"body.feathers\":{\"message\":\"'feathers' is required\"}},{\"body.type\":{\"message\":\"should be one of the following; ['DOG']\",\"value\":\"COW\"},\"body.barks\":{\"message\":\"'barks' is required\"}}]",
"value": {
"type": "COW",
"legs": 0
}
}
},
"message": "Internal Server Error"
}
Context (Environment)
Version of the library:
3.14.1
Version of NodeJS:
v18.16.0
Confirm you were using yarn not npm: [ ]
Detailed Description
Breaking change?
no
The text was updated successfully, but these errors were encountered:
Sorting
I'm submitting a ...
I confirm that I
Expected Behavior
Attempt to figure out which type a payload most conforms to amongst a union of many types before doing validation.
OR
as a workaround (for me) export
validationService
in thehapi.hbs
template. I would like to be able to use this service directly to validate some things manually so the error response is more meaningfulCurrent Behavior
The issue is that some of our apis allow payloads of a of a type that is union of many types. When validation fails, the response is unhelpful because for each incorrect param, it lists out all of the types that it could be amongst the union of all types. In our pre-response handler, i'd like to intercept those validation errors and essentially revalidate the payload against the intended type.
Possible Solution
the ideal solution would be for the validator to see that the incoming payload has type "COW", so validate it against the Animal1 interface. (this is referencing the simplified code example below)
the other solution is to just expose the validationService in hapi.hbs so that i can manually do this check and show a meaningful error message.
Steps to Reproduce
simplified example:
error response:
Context (Environment)
Version of the library:
3.14.1
Version of NodeJS:
v18.16.0
Detailed Description
Breaking change?
no
The text was updated successfully, but these errors were encountered: