-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Fix webapi returns variables in JSON using snake case and I need came… #31001
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
Conversation
Hi @jayankaghosh. Thank you for your contribution
❗ Automated tests can be triggered manually with an appropriate comment:
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. 🕙 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 |
@magento run all tests |
There was a problem hiding this 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?
lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php
Outdated
Show resolved
Hide resolved
@@ -128,7 +136,7 @@ public function buildOutputDataArray($dataObject, $dataObjectType) | |||
} | |||
} | |||
|
|||
$outputData[$key] = $value; | |||
$outputData[$this->mapObjectKey($key, ltrim($dataObjectType, '\\'))] = $value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move ltrim inside the mapObjectKey method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could. But that wouldn't make any difference to the flow right? The mapObjectKey
should only be responsible for mapping the object keys. Which is why I had kept the ltrim
(to include any class names with preceding slashes given in the di.xml as well) outside of it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue with it that it might not find the correct key, if in the client code we'll not do ltrim.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I understand. The mapObjectKey
can't be called from any other class. It'll just be called from the buildOutputDataArray
function, and we have done the ltrim
there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. but in case if someone will adjust this code a bit later or will call it in the another method - this issue will appear. It's better to incapsulate this logic inside the method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Okay. In that case I think it's better that we name the function something other than mapObjectKey
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getKeyByObjectType?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guess that'll work
There was a problem hiding this 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?
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 |
@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 😛 |
Hello @ihor-sviziev @jayankaghosh Sorry for the late response. Let me please clarify the situation. |
Can this solution be used? Perhaps with an override/plugin? |
@sdzhepa When can I expect an update on this? |
Add this in werbapi_rest\di.xml:
This way you can name your vars as you please. |
@jayankaghosh could I take your pull request to another one with test unit #39237, any problem with you? |
No problem man. Please do |
Hello @jayankaghosh, Thanks for the contributions! Please resolve the conflict so we can proceed with this PR. Thanks. |
@engcom-Dash @jayankaghosh any problem if we close this and switch to #39237 |
@jayankaghosh can you grand me the collaborator access on https://github.com/jayankaghosh/magento2/, I can push my change and follow this pull request |
Hi @jayankaghosh, Thank you for your contribution! @tuyennn, as @jayankaghosh aggred to go ahead with your PR here and we didnt get any input on conflict resolution, we are closing this PR now. @jayankaghosh, please feel free to reopen once done with changes. |
@engcom-Charlie I mean #39237 not this pull request |
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 thewebapi_rest
directory.Fixed Issues (if relevant)
Manual testing scenarios (*)
di.xml
insidewebapi_rest
directory of any module and inject object key names to it, similar to the followingContribution checklist (*)