Problem/Motivation
The allowed member names for JSON:API objects (i.e. JSON object property names) has an allowed character set. This includes letters, numbers, dashes, underscores, and spaces. Notably, colons are explicitly forbidden.
Unfortunately, JSON:API can serialize multiple links having the same key using a colon. This can happen if multiple resources are omitted from the response for access reasons.
Proposed resolution
Change the serialization to use a double dash (--) instead of a colon (:).
User interface changes
None.
API changes
None. See jsonapi.api.php:
* HTTP API: URLs and JSON response structures are considered part of this
* module's public API. However, inconsistencies with the JSON:API specification
* will be considered bugs. Fixes which bring the module into compliance with
* the specification are *not* guaranteed to be backwards-compatible. When
* compliance bugs are found, clients are expected to be made compatible with
* both the pre-fix and post-fix representations.
Data model changes
None.
Release notes snippet
JSON:API omission links are now keyed using a double-dash-separated syntax instead of a colon-separated syntax in order to be brought into compliance with the JSON:API specification on allowed member names. This may require changes to client applications that are parsing document omission links. See the change record on the change to object omission link serialization for an example.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 3077755-6.patch | 4.33 KB | gabesullice |
| #6 | 3077755-6--tests-only.patch | 1.95 KB | gabesullice |
| #5 | 3077755-5-interdiff.patch | 3.68 KB | mmenavas |
| #5 | 3077755-link-object-member-names-must-not-use-colons-5-d8.patch | 4.33 KB | mmenavas |
| #3 | 3077755-link-object-member-names-must-not-use-colons-3-d8.patch | 980 bytes | sokru |
Comments
Comment #2
gabesulliceTo fix this, see
Drupal\jsonapi\Normalizer\LinkCollectionNormalizer. Some tests may need to be updated as well.Comment #3
sokru commentedComment #4
wim leers@gabesullice I think the release notes snippet should call out this is not a BC break because that key is opaque, not meaningful.
Comment #5
mmenavas commentedSince https://www.drupal.org/project/drupal/issues/3036279 hasn't been resolved yet, the issue needs to be fixed in
JsonApiDocumentTopLevelNormalizertoo.Comment #6
gabesulliceThanks @sokru and @mmenavas! Perfect. The attached patches don't contain any changes, all I did was generate a patch that only has the tests.
Comment #8
gabesulliceTest only patch fails, fix passes. Code looks good. Thanks @sokru and @mmenavas!!
Comment #9
gabesulliceI created a change record and shortened the release notes snippet.
Comment #10
mmenavas commentedAnytime!
Comment #11
catchCommitted bdc5bcd and pushed to 8.8.x. Thanks!
Comment #13
catchComment #15
gabesulliceComment #16
wim leersI'm not sure this is worth calling out in the release notes.
Comment #17
xjmJust tweaking the CR link to be a string that is meaningful out of context (for accessibility).
Comment #18
xjm@Wim Leers if a client application might need to change their code for the new syntax, it's worth mentioning.
A little more info in the release note might help. My current draft has:
Any suggestions for "something something something"? ;)
Comment #19
gabesullice@xjm:
Comment #20
xjmPerfect, thanks!