? ? Pending

User tests: Successful: Unsuccessful:

avatar wilsonge
wilsonge
26 Dec 2022

Pull Request for Issue #39495 .

Summary of Changes

Fixes linked bug

Testing Instructions

In a webservice plugin (either custom or in a core one in the core add the following lines to the onBeforeApiRoute event (i used the content webservice plugin - but any will do)

        \JFactory::getApplication()->addFormatMap('application/ld+json', 'jsonld');
        $router->addRoute(
            new Route(['GET'], 'v1/format', '', [], ['format' => ['application/vnd.api+json', 'application/ld+json'], 'component' => 'com_content'])
        );

Then in the libraries/src/Application/ApiApplication.php add var_dump($this->input->get('format'), $this->input->get('option'));die; after this foreach loop (both before and after testing)

Generate a Bearer token and curl the url e.g. curl -H "Authentication: Bearer <bearer_token>" -H "Accept: application/ld+json" http://localhost/joomla-cms/api/index.php/v1/format

Actual result BEFORE applying this Pull Request

        array(2) {
          [0]=>
          string(22) "applicationvnd.apijson"
          [1]=>
          string(17) "applicationldjson"
        }
        string(11) "com_content"

Expected result AFTER applying this Pull Request

        string(7) "jsonld"
        string(11) "com_content"

i.e. the second dump (the component) is unchanged and the former (the format) now contains the Joomla format and not the array of possible options from the plugin

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

avatar joomla-cms-bot joomla-cms-bot - change - 26 Dec 2022
Category Libraries
avatar wilsonge wilsonge - open - 26 Dec 2022
avatar wilsonge wilsonge - change - 26 Dec 2022
Status New Pending
avatar nikosdion nikosdion - test_item - 26 Dec 2022 - Tested successfully
avatar nikosdion
nikosdion - comment - 26 Dec 2022

I have tested this item āœ… successfully on 83ac935

It works!

Just note that if you have Accept: application/ld+json you get the format applicationldjson instead of the expected jsonld.

To fix that, the plugin needs to have the following in its onBeforeApiRoute handler (where routes are registered):

$this->getApplication()->addFormatMap('application/ld+json', 'jsonld');

Since this is the expected behaviour of ApiApplication I consider my test successful. Thank you, George!


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39498.

avatar nikosdion
nikosdion - comment - 26 Dec 2022

I re-read my test description and it's… unclear. What I meant to say is that if you do not follow George's instruction to use addFormatMap you will get the "wrong" format, which is the expected behaviour in the Joomla API application. Even though there's this little gotcha, since it's an expected and documented gotcha, it does not affect me on marking this test successful.

I'm gonna go get some coffee now.

avatar carlitorweb carlitorweb - test_item - 26 Dec 2022 - Tested successfully
avatar carlitorweb
carlitorweb - comment - 26 Dec 2022

I have tested this item āœ… successfully on 83ac935

Using a custom component and only adding 'format' => ['application/json']


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39498.
avatar richard67 richard67 - change - 27 Dec 2022
Status Pending Ready to Commit
Labels Added: ?
avatar richard67
richard67 - comment - 27 Dec 2022

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39498.

avatar roland-d roland-d - change - 28 Dec 2022
Labels Added: ?
avatar roland-d roland-d - change - 28 Dec 2022
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2022-12-28 19:10:36
Closed_By roland-d
avatar roland-d roland-d - close - 28 Dec 2022
avatar roland-d roland-d - merge - 28 Dec 2022
avatar roland-d
roland-d - comment - 28 Dec 2022

Thank you

Add a Comment

Login with GitHub to post a comment