danivek/json-api-serializer

The result after serialize will not have `included` if the input doesn't have attributes

yidongw opened this issue · 5 comments

Considering this data

  {
      id: 'u999',
      name: 'Awesome Project',
      description: 'This is an awesome project',
      format: {
        id: 'u1',
        inputFormats: [ 'u45', 'u46' ],
        outputFormats: [ 'u47', 'u48' ],
      }
    }

with this serializer

serializer.register("projects", {
  whitelist: ["name", "description"],
  relationships: {
    format: {
      type: 'format',
    }
  },
});

serializer.register("format", {
  relationships: {
    inputFormats: {
      type: 'inputFormats',
    },
    outputFormats: {
      type: 'outputFormats',
    }
  }
});

After serializing the data, it will not serialize the [ 'u45', 'u46' ] and [ 'u47', 'u48' ] and include the results in the included, unless I have some attributes in the format serializer and provide that attributes in the format in the data

Another thing is I can't have an empty list of attributes (whitelist). AFAIK JSON API doesn't say we have to have attributes in the resource

it closes the first issue you mentioned.

For the empty list of attributes a major version is required because the default value of this option is a currently empty list.

It needed a new issue.

@yidongw Actually, a possible workaround to have an empty list of attributes is to use the option like that: whitelist: ['']

@danivek thanks for this fix! I faced this bug earlier today and saw it fixed on master when checking the codebase. Would it be possible for you to create a patch release?

@groyoh v2.6.4 🎉

Thanks @danivek ! 🙌