Open
Description
Description/Steps to reproduce
- define a model with
forceId: true
- associate this model to a mongodb data source
- call the API to create a new model with an explicit empty string id
curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d "{
\"id\": \"\"
}" "http://localhost:3000/api/foos"
- this call creates a db entry with empty id and returns:
{"id": ""}
Seems related to #1453 (see my comment)
Link to reproduction sandbox
https://github.com/simonbrunel/loopback-sandbox/tree/bug/empty-id-mongodb
Expected result
{
"error": {
"name": "ValidationError",
"status": 422,
"message": "The `foo` instance is not valid. Details : `id` can't be set (value: \"\").",
"statusCode": 422,
"details": {
"context": "foo",
"codes": {
"id": [
"absence"
]
},
"messages": {
"id": [
"can't be set"
]
}
}
}
}
Additional information
node v6.11.3, Windows 10 64bit
npm ls --prod --depth 0 | grep loopback
[email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]