magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Fix webapi returns variables in JSON using snake case and I need came…

Open jayankaghosh opened this issue 4 years ago • 13 comments

Description (*)

Added objectKeyMap which accepts parameters from di.xml to modify data object keys We can now modify the keys of any accessor on any class used in the rendering of the REST API, using the following (or similar) snippet in the di.xml of the webapi_rest directory.

<type name="Magento\Framework\Reflection\DataObjectProcessor">
        <arguments>
            <argument name="objectKeyMap" xsi:type="array">
                <item name="Magento\Cms\Api\Data\PageInterface" xsi:type="array"> <!-- Change the accessors keys of this class -->
                    <item name="page_layout" xsi:type="string">PageLayout</item> <!-- page_layout should be shown as PageLayout in the ouput -->
                </item>
            </argument>
        </arguments>
    </type>

Fixed Issues (if relevant)

  1. Fixes magento/magento2#24681 : webapi returns variables in JSON using snake case and I need camelCase

Manual testing scenarios (*)

  1. Add a di.xml inside webapi_rest directory of any module and inject object key names to it, similar to the following
<type name="Magento\Framework\Reflection\DataObjectProcessor">
        <arguments>
            <argument name="objectKeyMap" xsi:type="array">
                <item name="Magento\Cms\Api\Data\PageInterface" xsi:type="array">
                    <item name="page_layout" xsi:type="string">PageLayout</item>
                </item>
            </argument>
        </arguments>
    </type>
  1. Call the REST API and observe the new keys reflecting.

Contribution checklist (*)

  • [x] Pull request has a meaningful description of its purpose
  • [x] All commits are accompanied by meaningful commit messages
  • [ ] All new or changed code is covered with unit/integration tests (if applicable)
  • [ ] All automated tests passed successfully (all builds are green)

jayankaghosh avatar Nov 20 '20 17:11 jayankaghosh

Hi @jayankaghosh. Thank you for your contribution Here is some useful tips how you can test your changes using Magento test environment. Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

:exclamation: Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s) For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests

You can find more information about the builds here

:information_source: Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

:warning: According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

m2-assistant[bot] avatar Nov 20 '20 17:11 m2-assistant[bot]

@magento run all tests

ihor-sviziev avatar Nov 20 '20 17:11 ihor-sviziev

Hi @ihor-sviziev I am not affiliated with this PR in any way

aredridel avatar Nov 25 '20 16:11 aredridel

@aredridel , I just pressed wrong nick from the autocomplete. Sorry for disturbing you

ihor-sviziev avatar Nov 25 '20 18:11 ihor-sviziev

@magento run all tests

ihor-sviziev avatar Nov 25 '20 18:11 ihor-sviziev

Hi @jayankaghosh , Now the changes looks good to me. Could you cover your changes with some kind of automated test?

@ihor-sviziev I'm not sure how to proceed with writing the tests for this. Some help would be appreciated

jayankaghosh avatar Nov 25 '20 19:11 jayankaghosh

Hi @engcom-Bravo @engcom-Charlie @engcom-Delta could you help with cover thing this PR with automated tests?

ihor-sviziev avatar Nov 26 '20 04:11 ihor-sviziev

Maybe @engcom-Hotel @sdzhepa could help?

ihor-sviziev avatar Jan 05 '21 09:01 ihor-sviziev

@ihor-sviziev Guess they've abandoned us :stuck_out_tongue:

jayankaghosh avatar Jan 12 '21 13:01 jayankaghosh

Hello @ihor-sviziev @jayankaghosh

Sorry for the late response.

Let me please clarify the situation. We are working(fix, covering, QA, delivery, etc) and focusing on the Hight Priority(P0-P1-P2) tickets first. This issue was triaged as Priority: P4 . Currently, we do not have a plan to work on it

sdzhepa avatar Feb 05 '21 16:02 sdzhepa

Can this solution be used? Perhaps with an override/plugin?

xtremevision avatar Jun 27 '22 14:06 xtremevision

@sdzhepa When can I expect an update on this?

jayankaghosh avatar Sep 20 '22 14:09 jayankaghosh

@sdzhepa When can I expect an update on this?

Add this in werbapi_rest\di.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
	<type name="[Vendor]\[Module]\Plugin\DataObjectProcessor">
        <arguments>
            <argument name="objectKeyMap" xsi:type="array">
                <item name="[Vendor]\[Module]\Api\Data\[InterfaceFileWhereVarsAreDeclared]" xsi:type="array">
                    <item name="order_item" xsi:type="string">OrderItem</item>
                    <item name="transaction_id" xsi:type="string">TransactionID</item>
                </item>
            </argument>
        </arguments>
    </type>
</config>

This way you can name your vars as you please.

xtremevision avatar Sep 20 '22 14:09 xtremevision