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
Stop the app and start it again and reverse requests, First send request with Content-Type: application/x-www-form-urlencoded and then send request with Content-Type: application/json, The bug disappears.
Current Behavior
When we have an operation with multiple content types (application/x-www-form-urlencoded and application/json)
If we send request with Content-Type: application/json and then send request with Content-Type: application/x-www-form-urlencoded we get UnprocessableEntityError
{
"error": {
"statusCode": 422,
"name": "UnprocessableEntityError",
"message": "The request body is invalid. See error object `details` property for more info.",
"code": "VALIDATION_FAILED",
"details": [
{
"path": ".id",
"code": "type",
"message": "should be number",
"info": {
"type": "number"
}
}
]
}
}
But if we reverse requests we don't get this problem.
I can reproduce the problem. The root cause is that we cache AJV validators but the options is not taken into consideration. The json body does not require coercion while urlencoded body requires. As a result, the cached AJV validator does not support coercion if it's used first.
Steps to reproduce
With a simple model
Product
and controller operation with
@requestBody
hasapplication/x-www-form-urlencoded
andapplication/json
as content typesSend request with
Content-Type: application/json
And then send request with
Content-Type: application/x-www-form-urlencoded
The bug appears (
UnprocessableEntityError
).Stop the app and start it again and reverse requests, First send request with
Content-Type: application/x-www-form-urlencoded
and then send request withContent-Type: application/json
, The bug disappears.Current Behavior
When we have an operation with multiple content types (
application/x-www-form-urlencoded
andapplication/json
)If we send request with
Content-Type: application/json
and then send request withContent-Type: application/x-www-form-urlencoded
we getUnprocessableEntityError
But if we reverse requests we don't get this problem.
Additional information
linux x64 10.16.0
[email protected] /home/amr/Desktop/loopback-app
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── [email protected]
The text was updated successfully, but these errors were encountered: