Skip to content

Commit 176fff2

Browse files
fix(metadata): upgrade script keep operation name (api-platform#5109)
origin: api-platform#5105 Co-authored-by: WilliamPeralta <[email protected]>
1 parent 5837ceb commit 176fff2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Core/Upgrade/UpgradeApiResourceVisitor.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ private function removeAttribute(Node\Stmt\Class_|Node\Stmt\Interface_ $node)
359359
}
360360
}
361361
foreach ($node->stmts as $k => $stmts) {
362-
foreach ($stmts->attrGroups as $i => $attrGroups) {
363-
foreach ($attrGroups->attrs as $j => $attrs) {
362+
foreach ($stmts->attrGroups ?? [] as $i => $attrGroups) {
363+
foreach ($attrGroups->attrs ?? [] as $j => $attrs) {
364364
if (str_ends_with(implode('\\', $attrs->name->parts), 'ApiSubresource')) {
365365
unset($node->stmts[$k]->attrGroups[$i]);
366366
break;
@@ -443,6 +443,9 @@ private function legacyOperationsToOperations($legacyOperations, bool $isCollect
443443

444444
$method = $operation['method'] ?? strtoupper($operationName);
445445
unset($operation['method']);
446+
if (!isset($operation['path']) && !\in_array($operationName, ['get', 'post', 'put', 'patch', 'delete'], true)) {
447+
$operation['name'] = $operationName;
448+
}
446449
$operations[] = $this->createOperation($this->getOperationNamespace($method, $isCollection), $operation);
447450
}
448451

0 commit comments

Comments
 (0)