magento2
magento2 copied to clipboard
Fix webapi returns variables in JSON using snake case and I need came…
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)
- Fixes magento/magento2#24681 : webapi returns variables in JSON using snake case and I need camelCase
Manual testing scenarios (*)
- Add a
di.xml
insidewebapi_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>
- 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)
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:
-
Database Compare
-
Functional Tests CE
-
Functional Tests EE
, -
Functional Tests B2B
-
Integration Tests
-
Magento Health Index
-
Sample Data Tests CE
-
Sample Data Tests EE
-
Sample Data Tests B2B
-
Static Tests
-
Unit Tests
-
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
@magento run all tests
Hi @ihor-sviziev I am not affiliated with this PR in any way
@aredridel , I just pressed wrong nick from the autocomplete. Sorry for disturbing you
@magento run all tests
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
Hi @engcom-Bravo @engcom-Charlie @engcom-Delta could you help with cover thing this PR with automated tests?
Maybe @engcom-Hotel @sdzhepa could help?
@ihor-sviziev Guess they've abandoned us :stuck_out_tongue:
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
Can this solution be used? Perhaps with an override/plugin?
@sdzhepa When can I expect an update on this?
@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.