From aff8fb61036bb3b6c50673e2a3b1578bc573946e Mon Sep 17 00:00:00 2001 From: WilliamPeralta Date: Mon, 31 Oct 2022 13:18:50 +0100 Subject: [PATCH] fix(metadata): upgrade script keep operation name origin: https://github.com/api-platform/core/pull/5105 --- src/Core/Upgrade/UpgradeApiResourceVisitor.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Core/Upgrade/UpgradeApiResourceVisitor.php b/src/Core/Upgrade/UpgradeApiResourceVisitor.php index ead9a207f01..df48a3dee7b 100644 --- a/src/Core/Upgrade/UpgradeApiResourceVisitor.php +++ b/src/Core/Upgrade/UpgradeApiResourceVisitor.php @@ -359,8 +359,8 @@ private function removeAttribute(Node\Stmt\Class_|Node\Stmt\Interface_ $node) } } foreach ($node->stmts as $k => $stmts) { - foreach ($stmts->attrGroups as $i => $attrGroups) { - foreach ($attrGroups->attrs as $j => $attrs) { + foreach ($stmts->attrGroups ?? [] as $i => $attrGroups) { + foreach ($attrGroups->attrs ?? [] as $j => $attrs) { if (str_ends_with(implode('\\', $attrs->name->parts), 'ApiSubresource')) { unset($node->stmts[$k]->attrGroups[$i]); break; @@ -443,6 +443,9 @@ private function legacyOperationsToOperations($legacyOperations, bool $isCollect $method = $operation['method'] ?? strtoupper($operationName); unset($operation['method']); + if (!isset($operation['path']) && !\in_array($operationName, ['get', 'post', 'put', 'patch', 'delete'], true)) { + $operation['name'] = $operationName; + } $operations[] = $this->createOperation($this->getOperationNamespace($method, $isCollection), $operation); }