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.

Comments

gabesullice created an issue. See original summary.

gabesullice’s picture

Issue tags: +php-novice

To fix this, see Drupal\jsonapi\Normalizer\LinkCollectionNormalizer. Some tests may need to be updated as well.

sokru’s picture

wim leers’s picture

@gabesullice I think the release notes snippet should call out this is not a BC break because that key is opaque, not meaningful.

mmenavas’s picture

Since https://www.drupal.org/project/drupal/issues/3036279 hasn't been resolved yet, the issue needs to be fixed in JsonApiDocumentTopLevelNormalizer too.

gabesullice’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.95 KB
new4.33 KB

Thanks @sokru and @mmenavas! Perfect. The attached patches don't contain any changes, all I did was generate a patch that only has the tests.

The last submitted patch, 6: 3077755-6--tests-only.patch, failed testing. View results

gabesullice’s picture

Status: Needs review » Reviewed & tested by the community

Test only patch fails, fix passes. Code looks good. Thanks @sokru and @mmenavas!!

gabesullice’s picture

Issue summary: View changes

I created a change record and shortened the release notes snippet.

mmenavas’s picture

Anytime!

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed bdc5bcd and pushed to 8.8.x. Thanks!

  • catch committed bdc5bcd on 8.8.x
    Issue #3077755 by gabesullice, mmenavas, sokru, Wim Leers: Spec...
catch’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

gabesullice’s picture

Issue tags: +8.8.0 release notes
wim leers’s picture

I'm not sure this is worth calling out in the release notes.

xjm’s picture

Issue summary: View changes
Issue tags: -

Just tweaking the CR link to be a string that is meaningful out of context (for accessibility).

xjm’s picture

Status: Closed (fixed) » Needs work

@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:

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 [something something something]. See the change record on the change to object omission link serialization for an example.

Any suggestions for "something something something"? ;)

gabesullice’s picture

Status: Needs work » Needs review

@xjm:

are parsing document omission links.

xjm’s picture

Issue summary: View changes
Status: Needs review » Fixed

Perfect, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.