Skip to content

fixed registration order of routes and added operation name #5105

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Core/Upgrade/UpgradeApiResourceVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ public function enterNode(Node $node)

$arguments = [];
$operations = null === $this->resourceAnnotation->itemOperations && null === $this->resourceAnnotation->collectionOperations ? null : array_merge(
$this->legacyOperationsToOperations($this->getLegacyOperations()),
$this->legacyOperationsToOperations($this->getLegacyOperations(true), true)
$this->legacyOperationsToOperations($this->getLegacyOperations(true), true),
$this->legacyOperationsToOperations($this->getLegacyOperations())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can't be the default, indeed in API Platform 3 we recommend to put the item GET operation as first one because this is the one that identifies the Resource in the first place.

Copy link
Contributor Author

@WilliamPeralta WilliamPeralta Nov 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soyuka you kindly tell me how I can avoid that the route of the "itemOperation" take also the customized routes without changing the order? i get a 404 error if i put itemoperation first.

);

if (null !== $operations) {
Expand Down Expand Up @@ -443,6 +443,9 @@ private function legacyOperationsToOperations($legacyOperations, bool $isCollect

$method = $operation['method'] ?? strtoupper($operationName);
unset($operation['method']);
if(!in_array($operationName, ['get', 'post', 'put', 'patch', 'delete'])) {
$operation['name']= $operationName;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll keep this patch, it's a good idea thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soyuka Great, I am very pleased to have been helpful.

}
$operations[] = $this->createOperation($this->getOperationNamespace($method, $isCollection), $operation);
}

Expand Down