thephpleague / thephpleague.github.io

The League of Extraordinary Packages website
thephpleague.com
MIT License
45 stars 34 forks source link

Fractal ArraySerializer docs are incorrect #84

Closed brandonkelly closed 7 years ago

brandonkelly commented 7 years ago

The example given for how Collections with metadata are serialized using ArraySerializer is incorrect, and it’s not even valid JSON:

// Collection with Meta
[
    [
        'foo' => 'bar'
    ]
    'meta' => [
        ...
    ]
];

In reality it will be:

// Collection with Meta
[
    'data' => [
        {
            'foo' => 'bar'
        }
    ],
    'meta' => [
        ...
    ]
];

Other parts of the ArraySerializer docs give it a bad wrap as well, for no good reason, as the collections do in fact get tucked inside a data attribute.

As far as I can tell, there’s only two differences between ArraySerializer and DataArraySerializer:

  1. ArraySerializer serializes the resource at the top level rather than under a data key
  2. ArraySerializer respects the resourceKey it was configured with; DataArraySerializer forces 'data' (which seems like a bug, but will file a separate issue on the Fractal repo for that)
frankdejonge commented 7 years ago

@brandonkelly Hi, could you submit this issue to the fractal repository, that way the maintainers are notified and it can be picked up. Even better would be a PR on the gh-pages branch of that repo to change the docs.

brandonkelly commented 7 years ago