Open gnanavinaymurari opened 1 month ago
When we debug an issue in depth, we encounter a model like this:
{
"name": "John Doe",
"age": 30,
"hobbies": ["reading", "coding", "hiking"],
"address": {
"street": "123 Main St",
"city": "Anytown",
"country": "USA"
}
}
However, when it is returned from Mirage, it appears as:
{
"name": "John Doe",
"age": 30,
"hobbies": '["reading", "coding", "hiking"]',
"address": {
"street": "123 Main St",
"city": "Anytown",
"country": "USA"
}
}
The hobbies
field is an array but is being returned as a string instead of being converted back to an array.
Bug or question
mirage is giving string as response when we tried to return array in endpoint and it returns as object when we tried to return only one object from array:
Illustration: I have below endpoints:
this.get('/users/:id',function(schema,request){ return schema.users.findBy({id:request.params.id}) }
this.get('/users',function(schema,request){ return schema.users.all() }
In test environment, both are working fine whereas in dev environment, second endpoint is giving response in string instead of an array.