When trying to request Web API end-point which has an interface with methods returning DateTime Magento throws the following error:
Each getter must have a doc block. See DateTime::format()
interface TestInterface
{
/**
* Gets the current date.
*
* @return \DateTime
*/
public function getDate() : \DateTime;
}
class TestApi implements TestInterface
{
/**
* Gets the current date.
*
* @return \DateTime
*/
public function getDate() : \DateTime {
return new \DateTime();
}
}
<route method="GET" url="/V1/test">
<service class="TestInterface" method="getDate"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
Each getter must have a doc block. See DateTime::format()
Hi @zingix. Thank you for your report.
To help us process this issue please make sure that you provided the following information:
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
@magento give me 2.3-develop instance - upcoming 2.3.x release
For more details, please, review the Magento Contributor Assistant documentation.
@zingix do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?
Hi @engcom-Charlie. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.
[ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
[ ] 4. Verify that the issue is reproducible on 2.3-develop branchDetails
- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!
[ ] 5. Add label Issue: Confirmed once verification is complete.
[ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
Hi @engcom-Charlie , do I need to do anything? Can I help with providing more infomration?
:white_check_mark: Confirmed by @engcom-Charlie
Thank you for verifying the issue. Based on the provided information internal tickets MC-20656 were created
Issue Available: @engcom-Charlie, _You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself._
Hello @zingix ! No, thanks. I reproduced this issue.
Hi @kkorushkin. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:
Component: XXXXX label(s) to the ticket, indicating the components it may be related to.[ ] 2. Verify that the issue is reproducible on 2.3-develop branchDetails
- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!
[ ] 3. If the issue is not relevant or is not reproducible any more, feel free to close it.
Hi @zingix, thanks for reporting this, I believe the reason for not having a serializer for the DateTime class is even though there is an ISO for standardization, the format of the DateTime still may need to be different depending on country or client.
We recommend to your getDate method to return a string formatted on the way need.
I will be closing this issue since there are no plans to implement such a feature.
Hi @gabrieldagama, I do not agree that the date should be formatted as string. Using this method, you cannot directly load date types from the database and use the Magento default tools to have it properly mapped - except you store the dates as strings as well.
I added this issue for the API not Magento in general. The API should exactly be client independent and close to standard as possible. It is way easier to e. g. in front-end use libraries like moment.js for bringing the date into the clients preferred format. Think of multi-country / multi-language sites. In your scenario you would need to have an endpoint for each config.
To be honest, after waiting more than one year to get a focus on this issue I also do not expect it to be solved.