dingo / api

A RESTful API package for the Laravel and Lumen frameworks.
BSD 3-Clause "New" or "Revised" License
9.32k stars 1.25k forks source link

Implement a proper array response function, which uses a transformer #1724

Closed specialtactics closed 4 years ago

specialtactics commented 4 years ago

This will pass array responses through the normal transformation and wrap it inside the "data" key

RoyHP commented 4 years ago

@specialtactics This change broke our API. We did not anticipate a backwards-breaking change like this in a SEMVER patch release: "Argument 1 passed to GovWorks\Transformers\Facility\FacilityTransformer::transform() must be an instance of GovWorks\Models\Facility, instance of stdClass given, called in \/var\/www\/html\/vendor\/league\/fractal\/src\/Scope.php on line 407"

We had the following implementation. $facilities is a laravel collection of Facility models.

Screen Shot 2020-05-01 at 2 52 10 PM Screen Shot 2020-05-01 at 2 52 23 PM Screen Shot 2020-05-01 at 2 53 46 PM
specialtactics commented 4 years ago

@RoyHP I do apologise that's happened for you, but it's not clear to me why you are using that function in that way.

It does not make sense to pass an array to a transformer which transforms a model.

You should either use response->item, or you should change your transformer to accept Stdclass.

RoyHP commented 4 years ago

@specialtactics Yeah I'm not saying we're using it correctly, just that it has had this side effect. We will update the implementation to use item. Thank you.