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 #24681 Support camelCase webapi #39237

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

Conversation

tuyennn
Copy link
Member

@tuyennn tuyennn commented Oct 4, 2024

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>

Related Pull Requests

Add test cases version of #31001 thanks to jayankaghosh

Fixed Issues (if relevant)

  1. Fixes magento/magento2#24681

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.

Questions or comments

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)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

Copy link

m2-assistant bot commented Oct 4, 2024

Hi @tuyennn. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.
❗ 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
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github 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 Oct 4, 2024
@tuyennn
Copy link
Member Author

tuyennn commented Oct 4, 2024

@magento run all tests

@tuyennn
Copy link
Member Author

tuyennn commented Oct 4, 2024

@magento run all tests

@tuyennn
Copy link
Member Author

tuyennn commented Oct 4, 2024

@magento run all tests

@tuyennn
Copy link
Member Author

tuyennn commented Oct 4, 2024

@ihor-sviziev @sdzhepa does it look good?

@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Oct 7, 2024

Hi @tuyennn @jayankaghosh @csdougliss,
Could you please explain the use case when you need to have a different named key? Why can't it be implemented on your specific project as a custom module/patch?

I reviewed your changes—they look good. However, I'm not sure if it is worth accepting these changes to Magento core since they will slightly slow down all API requests for everyone and have quite limited usage of this feature.

@tuyennn
Copy link
Member Author

tuyennn commented Oct 7, 2024

@ihor-sviziev this is definitely used for specific projects. I'm not really sure if this might hit any performance issue incase we don't define any mapping object. Well a patch was created for years, and I believe it's not a problem if this wouldn't be accepted.

@tuyennn
Copy link
Member Author

tuyennn commented Oct 14, 2024

@magento run all tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: P4 No current plan to fix. Fixing can be deferred as a logical part of more important work. Progress: pending review Severity: S4 Affects aesthetics, professional look and feel, “quality” or “usability”.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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