Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource type is pluralized #129

Open
tomers opened this issue May 2, 2018 · 2 comments
Open

Resource type is pluralized #129

tomers opened this issue May 2, 2018 · 2 comments

Comments

@tomers
Copy link
Collaborator

tomers commented May 2, 2018

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.

@shrop
Copy link

shrop commented Jul 7, 2018

I am seeing the same issue. Is pluralizing the resource part of the jsonapi spec?

@shrop
Copy link

shrop commented Jul 7, 2018

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});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants