-
-
Notifications
You must be signed in to change notification settings - Fork 932
fix #582 itemOperation Normalization/Denormalization in doc #587
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 #582 itemOperation Normalization/Denormalization in doc #587
Conversation
e330e79
to
e7acfef
Compare
@Simperfit This is not the right way to fix it. Please use And the same fix needs to be applied to the collection operations too (because normalization and denormalization also take place). |
@teohhanhui This does not change the behaviour, or does it, just to reuse already implemented method ? Yes thanks I forgot about the collection. |
ae2a8b6
to
2706b5e
Compare
@teohhanhui I've changed. 'serializer_groups' =>
'thing_default_output',
'thing_default_input',
'thing_default_out_get',
'thing_default_out_put', But it does not show the parameters linked to |
ab306bd
to
b5eed48
Compare
b5eed48
to
17beb51
Compare
ping @AlexandreHagen could you please test this and tell me if it's correct the issue ? ping @teohhanhui @dunglas @theofidry this is RFR. |
f6dd043
to
51c6dd6
Compare
Hi @Simperfit Unfortunately, it is not seem to work as expected: Annotations setup: * @ApiResource(
* attributes={
* "normalization_context"={"groups"={"user","user_read"}},
* "denormalization_context"={"groups"={"user","user_write"}},
* },
* collectionOperations={
* "get"={"method"="GET"},
* "post"={"method"="POST"},
* },
* itemOperations={
* "get"={"method"="GET"},
* "delete"={"method"="DELETE"},
* "put"={
* "method"="PUT",
* "normalization_context"={"groups"={"user_read_put"}},
* "denormalization_context"={"groups"={"put"}},
* }
* },
* )
...
/**
* @var string Username of the user.
*
* @Groups({"user_read", "user_write", "user_read_put"})
* @Assert\NotBlank()
*/
protected $username;
/**
* @var string Email of the user.
*
* @Groups({"user_read", "user_write"})
* @Assert\Email(message="The email '{{ value }}' is not a valid email.", checkMX=true, checkHost=true)
*/
protected $email;
/**
* @var string Firstname of the user.
*
* @Groups({"user_read", "user_write", "user_read_put", "user_write_put"})
*
* @ORM\Column(name="firstname", type="string", length=255)
* @Assert\NotBlank
*/
protected $firstname;
... And i get: For POST: |
@teohhanhui @dunglas @vincentchalamon I need some help in here ;) I can't get it working, either I get the itemCollection & operationCollection, either the resource groups for one entity. I think it is directly related to nelmio and this has to be checked in nelmio. I don't think I can do things in Is there another class related to this ? edit: yep the provider helped me. |
f19818d
to
7269a33
Compare
ping @AlexandreHagen I think this time is the good time ;). Thank you for ur time. |
You are close ! But something still not working. Example: * @ApiResource(
* attributes={
* "normalization_context"={"groups"={"user_read"}},
* "denormalization_context"={"groups"={"user_write"}},
* },
* collectionOperations={
* "get"={"method"="GET"},
* "post"={"method"="POST"},
* "confirmation"={
* "route_name"="user_confirmation",
* },
* "post_invitation"={
* "method"="POST",
* "path"="/users/{invitation_code}",
* "normalization_context"={"groups"={"user_read_invitation"}},
* "denormalization_context"={"groups"={"user_write_invitation"}}
* },
* },
* )
...
/**
* @var string Username of the user.
*
* @Groups({"user_read", "user_write", "user_write_invitation"})
* @Assert\NotBlank()
*/
protected $username;
/**
* @var string Email of the user.
*
* @Groups({"user_read", "user_write", "user_write_invitation"})
* @Assert\NotBlank()
* @Assert\Email(message="The email '{{ value }}' is not a valid email.", checkMX=true, checkHost=true)
*/
protected $email;
/**
* @var string Firstname of the user.
*
* @Groups({"user_read", "user_write", "user_write_invitation"})
*
* @ORM\Column(name="firstname", type="string", length=255)
* @Assert\NotBlank()
*/
protected $firstname;
/**
* @var string Lastname of the user.
*
* @Groups({"user_read", "user_write", "user_write_invitation"})
* @ORM\Column(name="lastname", type="string", length=255)
* @Assert\NotBlank()
*/
protected $lastname;
/**
* @var boolean Shows that the user is enabled (email confrimation)
*
* @Groups({"user_read", "user_read_invitation"})
*/
protected $enabled;
/**
* @var string Password of the user.
*
* @Groups({"user_write", "user_write_invitation"})
* @Assert\Regex(
* pattern="/(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).{7,}/",
* message="Le mot de passe doit contenir au moins 7 caractères alphanumériques dont une majuscule, une minuscule et un chiffre."
* )
*/
protected $plainPassword;
... As expected I hope it's help and thanks for you work ! |
* | ||
* @return array | ||
*/ | ||
private function getGroupsForItemAndCollectionOperation(ResourceMetadata $resourceMetadata, string $resourceClass, string $io, string $operationName, array $visited = []) : array |
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.
What is this for? Please just use ResourceMetadata::getItemOperationAttribute
and ResourceMetadata::getCollectionOperationAttribute
properly. There's already a fallback mechanism in place (4th / last argument).
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.
This is what i'm doing inside of it. Look at the parse method, I added the operationName because I needed to. In in order to have the parse method not full of code, I made this 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.
@Simperfit If you just use the fallback mechanism, it'd avoid a lot of unnecessary code.
This method is not needed in the first place.
/cc @dunglas
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.
@teohhanhui you're right, this method should be deleted.
@Simperfit can you finish this PR? Can I help you in any way? |
if (isset($attributes['normalization_context']['groups'])) { | ||
$options['serializer_groups'] = $attributes['normalization_context']['groups']; | ||
} | ||
$options['serializer_groups'] = $resourceMetadata->getAttribute( |
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.
IMO the problem is here, shoud should keep the if(isset())
/else
structure or both read and write groups are added.
7269a33
to
82de009
Compare
@dunglas Thank you for the help. @AlexandreHagen Is it ok for you ? I have been testing this and this I feel it ok. Thanks for the time & and the help |
I don't know why but I got that:
I'm trying to solve it |
Okey ! It's can be merged ! Thanks @Simperfit ! |
Thanks for fixing this Hamza. |
…oc (api-platform#587) * feature: fix api-platform#582 add itemOperation Normalization/Denormalization into the doc * hotfix: take comments in account * hotfix: fix test * hotfix: refactor parser * hotfix: refactor parser * hotfix: fix test * hotfix: fix cs * feat: add tests on attributes.
I think i'm not bad on this but there is a part of this I don't know how to handle :
Since we are overriding on method, how do I tell the property-info / nelmio that we want this only for the PUT part ?
Right now I only get the overrided part in the doc. It is the intended behaviour ?
Which means I lost the ones in the attributes.
@dunglas What do I miss ?