Problem/Motivation
The api_json
format is intended to only be usable by the JSON API module's routes. But … it's in fact possible to also use it on REST resources. Which then leads to confusion for end users, like for example #2835070: Views is returning empty entities.. If we want to avoid massive numbers of support requests along these lines (as well as related bugs), then we need to figure out a solution for this.
Steps to reproduce
- Install the JSON API module. The JSON API module has its own routes, but it also provides a serialization format.
- Install the REST module anyway.
- Create a "REST Export" view, and use the
api_json
format.
(Note that even Preston So got this wrong in his article at https://dev.acquia.com/blog/decoupled-drupal-with-ember-introducing-embe....)
I think this is a real problem: the REST module makes every installed serialization format available for use on REST resources, even when it's a format that does not really make sense in the REST module.
Proposed resolution
TBD
Remaining tasks
TBD
User interface changes
TBD
API changes
TBD
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#14 | 2841027--jsonapi-not-in-rest--14.patch | 9.82 KB | Wim Leers |
|
Comments
Comment #2
Wim LeersThis is also a problem that modules like https://www.drupal.org/project/acquia_contenthub face.
Comment #3
Wim LeersDiscussed with e0ipso, we agreed that this is major, because this is a pre-existing bug in core (see #2575761: Discuss a better system for discovering and selecting normalizers + #2822201: Allow contrib modules to deploy REST resources by creating routes, removing the need for config entities in that special case) due to an architectural oversight, that should only require minimal changes in the JSON API module code.
Comment #4
Wim LeersBeen working on this today.
Comment #5
Wim LeersFirst: a failing test. To prove that currently,
api_json
is indeed one of the formats supported by the REST module.Comment #6
Wim LeersUgh, I rolled it wrong NID and CID. Ah well. It's the right patch.
Comment #8
Wim LeersSolution.
Comment #9
Wim LeersClean-up.
Comment #10
Wim LeersFix phpcs violations.
Comment #11
Wim LeersComment #12
Wim LeersThe reason we have to do this messy thing:
We have #2575761: Discuss a better system for discovering and selecting normalizers to improve that in D9.
Comment #13
e0ipsoI took a slightly different approach.
Comment #14
Wim LeersHAHAHAHAHAHA.
^^-> that's me laughing at myself for being a moron. This is simpler. I like it :) Although it is also a bit more misleading/less explicit. That's okay though, at least for the foreseeable future :)
Review time!
#13 has no interdiff. I manually diffed, and the test coverage is identical to the one that I created. Great!
These comments need to be updated. This class should contain a long comment similar to the one I added in
jsonapi.services.yml
.Comment #15
e0ipsoLooks good to me. Merging.
Comment #17
e0ipsoThis is a great DX fix!!
Comment #18
Wim LeersYes it is :)
Comment #20
effulgentsia CreditAttribution: effulgentsia at Acquia commentedThis needs an additional step: #3029630: RemoveJsonapiFormatCompilerPass removes api_json from serializer.formats but not from serializer.format_providers, hence allowing it to be selected in REST export View displays.