Skip to content

Commit 60d0b1e

Browse files
committed
Fix failing tests
1 parent fcf4147 commit 60d0b1e

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

src/generator/ApiGenerator.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77

88
namespace cebe\yii2openapi\generator;
99

10-
use cebe\yii2openapi\lib\items\RestAction;
11-
use yii\db\mysql\Schema as MySqlSchema;
12-
use SamIT\Yii2\MariaDb\Schema as MariaDbSchema;
13-
use yii\db\pgsql\Schema as PgSqlSchema;
1410
use cebe\openapi\Reader;
1511
use cebe\openapi\spec\OpenApi;
1612
use cebe\yii2openapi\lib\Config;
@@ -21,9 +17,13 @@
2117
use cebe\yii2openapi\lib\generators\RestActionGenerator;
2218
use cebe\yii2openapi\lib\generators\TransformersGenerator;
2319
use cebe\yii2openapi\lib\generators\UrlRulesGenerator;
20+
use cebe\yii2openapi\lib\items\FractalAction;
21+
use cebe\yii2openapi\lib\items\RestAction;
2422
use cebe\yii2openapi\lib\PathAutoCompletion;
2523
use cebe\yii2openapi\lib\SchemaToDatabase;
2624
use Yii;
25+
use yii\db\mysql\Schema as MySqlSchema;
26+
use yii\db\pgsql\Schema as PgSqlSchema;
2727
use yii\gii\CodeFile;
2828
use yii\gii\Generator;
2929
use yii\helpers\Html;
@@ -525,21 +525,23 @@ public static function isMariaDb():bool
525525
}
526526

527527
/**
528-
* @param RestAction[] $actions
529-
* @return RestAction[]
528+
* @param RestAction[]|FractalAction[] $actions
529+
* @return RestAction[]|FractalAction[]
530530
* https://github.com/cebe/yii2-openapi/issues/84
531531
*/
532532
public static function removeDuplicateActions(array $actions): array
533533
{
534-
$actions = array_filter($actions, function (RestAction $action) {
535-
if ($action->isDuplicate) {
534+
$actions = array_filter($actions, function ($action) {
535+
/** @var $action RestAction|FractalAction */
536+
if ($action instanceof RestAction && $action->isDuplicate) {
536537
return false;
537538
}
538539
return true;
539540
});
540541

541-
$actions = array_map(function (RestAction $action) {
542-
if ($action->isOriginalForCustomRoute) {
542+
$actions = array_map(function ($action) {
543+
/** @var $action RestAction|FractalAction */
544+
if ($action instanceof RestAction && $action->isOriginalForCustomRoute) {
543545
$action->idParam = null;
544546
$action->params = [];
545547
}

src/lib/generators/RestActionGenerator.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,18 @@ protected function resolvePath(string $path, PathItem $pathItem):array
7777
if (isset($operation->{CustomSpecAttr::ROUTE})) { # https://github.com/cebe/yii2-openapi/issues/144
7878
$customRoute = $operation->{CustomSpecAttr::ROUTE};
7979
}
80-
if ($customRoute === null) {
81-
$actions[] = $this->prepareAction($method, $operation, $routeData, $customRoute);
82-
} else {
83-
// TODO rename
84-
$actionHere = $this->prepareAction($method, $operation, $routeData, $customRoute);
85-
$actionHere->isOriginalForCustomRoute = true;
86-
if (!in_array($customRoute, $this->allCustomRoutes)) {
87-
$actionHere->isOriginalForCustomRoute = false;
80+
81+
// TODO rename
82+
$actionHere = $this->prepareAction($method, $operation, $routeData, $customRoute);
83+
if ($customRoute !== null) {
84+
if (in_array($customRoute, $this->allCustomRoutes)) {
8885
$actionHere->isDuplicate = true;
86+
} else {
87+
$actionHere->isDuplicate = false;
8988
$this->allCustomRoutes[] = $customRoute;
9089
}
91-
$actions[] = $actionHere;
9290
}
91+
$actions[] = $actionHere;
9392
}
9493
return $actions;
9594
}

tests/specs/issue_fix/144_methods_naming_for_non_crud_actions/app/controllers/base/AbcController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,4 @@ abstract public function checkAccess($action, $model = null, $params = []);
2929

3030
abstract public function actionXyz();
3131

32-
abstract public function actionXyz();
33-
3432
}

0 commit comments

Comments
 (0)