devour-client
devour-client copied to clipboard
Resource type is pluralized
I created the following model:
jsonApiInstance.define('screen', {
name: ''
}
When I send patch request, I get the following error:
:5000/screens/3:1 PATCH http://localhost:5000/screens/3 409 (CONFLICT)
minilog.js?2831:17 devour Error: Request failed with status code 409
at createError (createError.js?16d0:16)
at settle (settle.js?db52:18)
at XMLHttpRequest.handleLoad (xhr.js?ec6c:77)
actions.js?e1db:23
{type: {…}}
type
:
{title: "Incorrect type", detail: "Invalid type. Expected "screen"."}
__proto__
:
Object
This can be resolved by explicitly specifying type in define's options argument:
jsonApiInstance.define('screen', {
name: ''
},
{
type: 'screen'
})
The cause for this issue is in devour/src/middleware/json-api/_serialize.js file:
function resource (modelName, item) {
// ...
let typeName = options.type || this.pluralize(modelName)
// ...
}
I think it is more correct to use this.pluralize.singular for this case.
I am seeing the same issue. Is pluralizing the resource part of the jsonapi spec?
I was able to take care of this by setting up the devour object with the pluralize option set to false
const jsonApi = new JsonApi({apiUrl:'https://site/jsonapi', pluralize: false});