-
-
Notifications
You must be signed in to change notification settings - Fork 848
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
Impossible to use messenger Input class with empty DTO (no attributes) #2773
Comments
#2757 might help you fix this |
Hey, thanks for the quick answer! Sure if we can control the listener it will handle our use case perfectly and be less intrusive in the Validation process ;) I think we can say: No validation if No attribute & No data. But I'm not sure if there is some drawback to do this. |
If your input DTO has no attributes, you must send an empty JSON object, not an empty body. |
I tried with an empty DTO and send an empty JSON object {} but still an error:
Response:
|
I think this issue exists indeed because your class is empty. |
Ok, so I think it could be a nice feature to be able to handle Empty DTO (Command) for some use case such as ResendUserPassword, POST workflow change state, ... I think we could discuss on this implementation. Is it link to the possibility to toggle listeners or is it built in the different part of API platform (add condition on validator, propertyInfo, ...)? |
IMO if you really want this behavior you should implement your own listener. |
it's not a feature we want to handle in API Platform itself? I can make a PR if it's the subject here. |
I think that we should fix this in the core/src/Bridge/Symfony/PropertyInfo/Metadata/Property/PropertyInfoPropertyNameCollectionFactory.php Line 46 in 2f941fc
new PropertyNameCollection([]) instead but I'm afraid it'd break some stuff :p.
|
No, it should be fixed in PropertyInfo. |
This is wrong: https://github.com/symfony/symfony/blob/v4.2.8/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php#L98 But perhaps it's done that way because PropertyInfo does not have a way to merge results from multiple extractors. |
👍 indeed I also thought about this, we should try to fix this upstream then :/ |
For me this workaround works:
It would by nice if PlaceholderAction allows null as value for $data - this problem raise everytime when you disable read listener and has empty body. For example, I have delete action for notification token for logged user, so there is no need to send id for entity. Read, validation listeners are disabled and everything I need is custom data persister - there is also POST endpoint for set tokens. |
Greetings! We appreciate your concern but weren't able to reproduce this issue or it is more of a question. As described in the API Platform contributing guide, we use GitHub issues for bugs and feature requests only. For support question ("How To", usage advice, or troubleshooting your own code), you have several options:
Feel free reach one of the support channels above. In the meantime we're closing this issue. |
Hey folks,
I'm running into an issue where I want to use API entrypoint with
messenger="input"
and my input class (Command) is a DTO and it has no attributes.A simple example of a User entity who needs to resend its validation email:
Entity/User.php
And the input class (DTO) here we called them Command:
ResendValidationMailCommand.php
This will always throw an error because the body is empty when we call the POST entrypoint:
Analysis
It seems the Symfony Validator is always called even if there is no attribute to be validated. It think it could be great to handle this case in https://github.com/api-platform/core/blob/master/src/Bridge/Symfony/Validator/EventListener/ValidateListener.php#L85
When the $validationGroup & $data are null/empty, don't call validate.
I think it's more in https://github.com/api-platform/core/blob/master/src/Validator/EventListener/ValidateListener.php#L60 we need to handle empty DTO input.
Further investigation
I tried to put
"defaults"={"_api_receive"=false},
on the operation but it can't handle $data null for POST:Workaround
The only workaround we found is to add a dummy attribute in the DTO but it's not ideal:
ideas or other workaround?
Any idea on this? Or workaround because we have several entrypoint we want to manage with CQRS pattern which haven't data to transport (just the info that Command is called).
Thanks in advance ;)
The text was updated successfully, but these errors were encountered: