-
-
Notifications
You must be signed in to change notification settings - Fork 959
Feature support entity identfiers to become JSON:API semantics compliant #7702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.2
Are you sure you want to change the base?
Conversation
The JSONAPI spec combines a type and an id to uniquely identify a resource: https://jsonapi.org/format/#document-resource-object-identification The current api platform implementation uses the IRI as the ID which is not JSONAPI compliant.
|
I like this a lot, I suggest however that we deprecate this at some point (in 4.4 with a removal in 5.0). I think that ideally our JSON:API representation should be like this: It's definitely possible to use I suggest that we use a boolean for this option and to add |
|
Thanks for your response. At this point, I’m unsure how to proceed. When you say “deprecate it,” do you mean the use of IRIs as resource identifiers? I’m not certain whether the approach in this PR is slightly over-engineered, or whether it is actually the correct way to support JSON:API in API Platform. My main goal was to respect what I understand to be the core concepts behind API Platform. In my production application, my current workaround for the id == IRI situation is to hook into the serialization process and normalize the output produced by the API Platform item normalizer. During normalization, I transform: into: During denormalization, before passing the data back to the API Platform item normalizer, I reverse the process: becomes: (for example: /api/role/3). The rest of the document — including links, meta, and other JSON:API members — remains unchanged. Given my requirements and system constraints (notably the use of Doctrine), this approach works well for me. However, I’m unsure whether this solution is transferable to all other ways API Platform can expose resources, or whether it is robust enough to be considered proper JSON:API support in a more general sense. In a way it would feel like a slimmer solution. |
|
I think that for JSON:API the identifier should just be a scalar value not an IRI (id + type is enought information and fits well the specification). You're patch is nice I think that we should have a boolean as option and that in 5.0 the behavior you described should be the default one. |
|
Ok, thanks. I will modify the option to become a boolean. |
|
I need to test this in details, it should target |
API platform uses IRIs to manage identity and applies it for linked data formats. JSON:API has different semantics.
This change aims at making JSON:API output spec-compliant without changing the internal identity model.
The current implementation returns resources as:
The resource identification of the JSON:API spec (https://jsonapi.org/format/#document-resource-object-identification) requires it to be:
The combination of type and id makes the resource unique.
The proposed implementation wants to keep the original behavior to be downward compatible but introduces a configuration flag, that allows to switch to the spec compliant version.
I would be grateful for any pointers that improves the pull request or its suitability to the concepts used in API platform.