eosnewmedia / JSON-API-Common

Basic php implementation (shared structures for client and server) of the json api specification (jsonapi.org)
https://eosnewmedia.github.io/JSON-API-Common/
MIT License
14 stars 13 forks source link

Resource Creation: Server-Side generated ID's #23

Open chris-doehring opened 4 years ago

chris-doehring commented 4 years ago

Hi,

The JSON:API protocol accepts both server and client side generated resource IDs. This implements, that a resource id can be left out when executing the create resource request (see the protocol docs for reference).

Unfortunately, the ResourceInterface expects the ID to be a string, so the only solution for a server-side generated ID would be to submit an empty ID string. In my case this breaks the server-side validation, as the server correctly assumes a non-existing id resource member.

I guess the only correct solution would be to make the id function nullable in the ResourceInterface, which will break other stuff. I must find another temporary solution for this in order to proceed without adjusting the server-side validation.

Are there any plans to support the server-side generated ID's in this package? Thanks in advance!

chris-doehring commented 4 years ago

I was able to find a workaround by creating a custom Serializer which removes empty IDs from the resources, but that's not an ideal solution.