Problem/motivation
When JSON:API is set to readonly, the results of the openapi module still defines the endpoints for creating, updating and deleting resources.
This makes the documentation a bit weird since the endpoints don't really work but are documented.
Proposed solution
It seems the routes from the`getJsonApiRoutes` method that are used in the `JsonApiGenerator` returns routes with all methods enabled even though only `GET` is allowed when switching the `jsonapi` to readonly. This should not be the case.
It should probably be fixed in `JsonApiGenerator` to check if readonly is enabled in the config.
Issue fork openapi_jsonapi-3079209
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
bbralaI've made a possible fix, although no tests yet. Would this be the proper place to fix this?
Comment #3
bbralaI've fixed some glaring codestyle issues for the patch in comment #2
Comment #4
bbralaComment #5
richgerdesI had to fix the diff header to get it to apply correctly. Attached is the rerolled patch.
Lets run tests to verify this doesn't break anything
Comment #7
richgerdesThe patch does work, but I hadn't considered how the tests would react. Since jsonapi defaults to read only mode, I will need to write tests, or at least alter the existing tests.. They should be simple, I'll try to get to this later today. Basically, the only change to the existing test is changing the jsonapi config to non read only mode. We should then add a secondary test for jsonapi, which verifies that with the default config (read only mode) the only method is get.
Comment #8
bbralaThanks for taking the time.
If I knew how to run tests locally for modules I'd do that but I don't.
Seems reasonable to split the tests to read only mode on and off at some point.
Comment #9
abu-zakham commentedComment #10
abu-zakham commentedComment #11
abu-zakham commentedRe-rolled patch for openapi_jsonapi
Comment #12
abu-zakham commentedPatch for 8.x-2.x branch
Comment #13
abu-zakham commentedComment #14
guypaddock commentedCorrected title to be more precise, because endpoints disabled via JSON:API Extras definitely do not appear in the documentation. So, looks like this is specifically about hiding mutable resources from the docs.
Comment #15
rajab natshahComment #16
bbralaThink that statuschange is not fair rajab, tests fail, i see no comments from you. Think this is not RTBC to be honest.
Comment #17
rajab natshahThank you, Björn for following up on the issue.
We had been working with patch #12 for around 8 months.
And I did a test for fresh Drupal sites.
#3189326: Add 2 patches for the OpenAPI for JSON:API module to fix issues with endpoints when JSON:API is configured to be read-only
The patch apply on the 3.0.x branch too
Comment #18
guypaddock commented@Rajab: automated tests, not manual tests. The patch doesn't update the automated tests, so they are failing with this patch. Back to NW.
Comment #21
hitchshockUpdated tests according to the last changes. Also created merge request.
Comment #22
hitchshockComment #23
bbralaAlthough the changes to uuid are a bit puzzling to me the changes do look good. Testing this way also seems like it's correct so I'm gonna give it a rtbc (even though I worked out this a while back :))
Comment #24
broonI did need the same functionality and already hacked in JsonApiGenerator class to create a PoC. Before I decorated that service in a custom module, I stumbled upon this issue and patch and can confirm that it works as expected.
Comment #25
vacilando commentedCould this please be merged to DEV?
Comment #26
psf_ commentedThe last patch don't merge with openapi_jsonapi:3.0.4
I see too that the last patch add changes not related with this issue.
Comment #27
broonRe-roll patch #12 against 3.0.4
Comment #28
bbralaThanks for the reroll, but you forgot to include the changes from #21
Comment #29
bharath-kondeti commentedAddressed #28 and updated the changes from #21. Please review
Comment #30
bbralaWhen posting patches try and add and interdiff, it does sometimes fail when resolving though, then I wouldn't add it
https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupa...
Comment #31
rajab natshahComment #32
bradjones1Comment #33
ricovandevin commentedPatch from #29 seems to work fine. Leaving status to Needs work until we have a green test result. Queued patch for retest.
Comment #34
anybodyComment #38
sokru commentedRebased the MR and fixed few coding standards related issues. A bit unsure about the test coverage, since the tests seem to pass even if I mix the contents of
test/expectations/read_only_*directories.Comment #39
phernand42 commentedPatch from #29 also working for me too.
Comment #40
rajab natshah