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
[HELP] Add a custom operation without overriding an existing item/collection operation #1482
Comments
Okay so I simply used the below * collectionOperations={
* "bulk"={
* "method"="POST",
* "route_name"="api_entity_post_bulk"
* },
* "post"={"method"="POST"},
* "get"={"method"="GET"}
* } I also reviewed the custom denormalize method: public function denormalize($data, $class, $format = null, array $context = [])
{
if (is_array($data) &&
OperationType::COLLECTION === $context['operation_type'] &&
'bulk' === $context['collection_operation_name'] &&
Entity::class === $class) {
// bulk operation must update on POST as PUT is only allowed for item and not collection
// https://api-platform.com/docs/core/operations
$context['api_allow_update'] = true;
return array_map(function($item) use ($class, $format, $context) {
return $this->normalizer->denormalize($item, $class, $format, $context);
}, $data);
}
return $this->normalizer->denormalize($data, $class, $format, $context);
} |
@mickaelprevot How did you change the swagger model to reflect you now expect an array if entities? |
hi @mikaelcom I'm trying to use your approach to get bulk post working but I'm getting a Thanks |
@maaxxicarvalho in my services.yml file, I have these settings : AppBundle\Serializer\CustomItemNormalizer:
arguments:
- '@api_platform.serializer.normalizer.item'
tags: [ 'serializer.normalizer' ] That's all |
@mikaelcom it worked! thanks for your fast reply! |
First of all, it rocks!
I'm trying to add a bulk operation for a collection of entities of the same type so I did this way:
As PUT is defined for an item collection, I had to use the POST verb. In addition, I had to allow the update as my goal is to allow an update on many entities. So I added a custom normalizer:
Unfortunately, the POST verb is now only available with the
/api/entities/bulk
path.My questions are:
Thanks in advance 😄
The text was updated successfully, but these errors were encountered: