Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 4 commits into
base: 2.4-develop
Choose a base branch
from

Conversation

jayankaghosh
Copy link
Contributor

@jayankaghosh jayankaghosh commented Nov 20, 2020

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 webapi returns variables in JSON using snake case and I need camelCase #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 (*)

  • Pull request has a meaningful description of its purpose
  • 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)

@m2-assistant
Copy link

m2-assistant bot commented Nov 20, 2020

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

❗ 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

ℹ️ 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.

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

🕙 You can find the schedule on the Magento Community Calendar page.

📞 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.

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

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

@m2-community-project m2-community-project bot added Priority: P4 No current plan to fix. Fixing can be deferred as a logical part of more important work. Severity: S4 Affects aesthetics, professional look and feel, “quality” or “usability”. labels Nov 20, 2020
@m2-community-project m2-community-project bot added this to Pending Review in Pull Requests Dashboard Nov 20, 2020
@ihor-sviziev
Copy link
Contributor

@magento run all tests

@ihor-sviziev ihor-sviziev self-assigned this Nov 20, 2020
@m2-community-project m2-community-project bot moved this from Pending Review to Review in Progress in Pull Requests Dashboard Nov 20, 2020
Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jayankaghosh,
In general your changes looks good to me.

Could you make the new method to be private (due to backward compatibility reasons) and cover your changes with any type of automated tests?

@m2-community-project m2-community-project bot moved this from Review in Progress to Changes Requested in Pull Requests Dashboard Nov 23, 2020
@ihor-sviziev ihor-sviziev added Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests Award: bug fix Progress: review and removed Progress: needs update labels Nov 23, 2020
@m2-community-project m2-community-project bot moved this from Changes Requested to Review in Progress in Pull Requests Dashboard Nov 23, 2020
@m2-community-project m2-community-project bot moved this from Review in Progress to Changes Requested in Pull Requests Dashboard Nov 23, 2020
@m2-community-project m2-community-project bot moved this from Changes Requested to Review in Progress in Pull Requests Dashboard Nov 23, 2020
@m2-community-project m2-community-project bot moved this from Review in Progress to Changes Requested in Pull Requests Dashboard Nov 23, 2020
Co-authored-by: Ihor Sviziev <ihor-sviziev@users.noreply.github.com>
@m2-community-project m2-community-project bot moved this from Changes Requested to Review in Progress in Pull Requests Dashboard Nov 24, 2020
@m2-community-project m2-community-project bot moved this from Review in Progress to Changes Requested in Pull Requests Dashboard Nov 24, 2020
@m2-community-project m2-community-project bot moved this from Changes Requested to Review in Progress in Pull Requests Dashboard Nov 24, 2020
Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@m2-community-project m2-community-project bot moved this from Review in Progress to Changes Requested in Pull Requests Dashboard Nov 25, 2020
@aredridel
Copy link
Contributor

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

@ihor-sviziev
Copy link
Contributor

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

@ihor-sviziev
Copy link
Contributor

@magento run all tests

@jayankaghosh
Copy link
Contributor Author

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

@ihor-sviziev
Copy link
Contributor

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

@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Jan 5, 2021

Maybe @engcom-Hotel @sdzhepa could help?

@jayankaghosh
Copy link
Contributor Author

@ihor-sviziev Guess they've abandoned us 😛

@sdzhepa
Copy link
Contributor

sdzhepa commented Feb 5, 2021

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

@xtremevision
Copy link

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

@jayankaghosh
Copy link
Contributor Author

@sdzhepa When can I expect an update on this?

@xtremevision
Copy link

xtremevision commented Sep 20, 2022

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests Award: bug fix Component: Reflection help wanted Priority: P4 No current plan to fix. Fixing can be deferred as a logical part of more important work. Progress: needs update Release Line: 2.4 Severity: S4 Affects aesthetics, professional look and feel, “quality” or “usability”.
Projects
Pull Requests Dashboard
  
Changes Requested
Development

Successfully merging this pull request may close these issues.

webapi returns variables in JSON using snake case and I need camelCase
6 participants