fractal icon indicating copy to clipboard operation
fractal copied to clipboard

[JsonApiSerializer] A way to return requested realtionship without attributes and links

Open Insolita opened this issue 5 years ago • 2 comments

Even if we transform data as

   transform($data){
       return ['id' => $data['id']];
  }

the response will contain empty attributes object and link object with self-link like

 "data" : {
            "type":       "users" ,
            "id":         "55" ,
            "attributes": { } ,
            "links":      {
                "self": "http://127.0.0.1:80/users/55"
            }
        }

There is no way to receive a simple response for request like /articles/1/relationships/author r like in examples https://jsonapi.org/format/#fetching-relationships

 "data" : {"type":  "users" , "id":   "55" }

Insolita avatar Oct 05 '20 01:10 Insolita

How are you creating the serializer? If you create the serializer without a base URL, it shouldn't add the links.

Regarding the attributes, that's a tricky one which comes from the current implementation not being able to difrentiate between an empty object and an empty array, there are issues raised about this problem already and the changes required would essentially mean rebuilding the serializer from scratch. In theory, an empty object should not be there, but an empty array should be, so the API consumer knows that there is potentially an amount of items to be iterated over.

willishq avatar Jun 25 '21 10:06 willishq

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 4 weeks if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 16 '22 06:04 stale[bot]