Skip to content

Commit e08b802

Browse files
committed
Add tests and fix failing tests
1 parent 75cafa9 commit e08b802

File tree

19 files changed

+309
-23
lines changed

19 files changed

+309
-23
lines changed

src/lib/items/RouteData.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,18 @@ public function getPrefixSettings():array
310310
protected function detectUrlPattern():void
311311
{
312312
if ($this->path === '/') {
313-
$this->type = self::TYPE_DEFAULT;
313+
$this->type = self::TYPE_DEFAULT; // issue is here https://github.com/php-openapi/yii2-openapi/issues/102
314314
$this->action = '';
315315
$this->controller = 'default';
316+
if (isset($this->operation->{CustomSpecAttr::ROUTE})) { # https://github.com/cebe/yii2-openapi/issues/144
317+
$customRoute = $this->operation->{CustomSpecAttr::ROUTE};
318+
$parts = explode('/', $customRoute);
319+
$this->action = array_pop($parts);
320+
$this->controller = array_pop($parts);
321+
}
316322
return;
317323
}
324+
318325
foreach ($this->urlPrefixes as $prefix => $rule) {
319326
if (!str_starts_with(trim($this->path, '/'), trim($prefix, '/'))) {
320327
continue;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* OpenAPI UrlRules
4+
*
5+
* This file is auto generated.
6+
*/
7+
return [
8+
'GET tasks' => 'fruit/mango/alphonso/list',
9+
'GET task/<id:\d+>' => 'fruit2/mango/alphonso/view',
10+
'tasks' => 'fruit/mango/alphonso/options',
11+
'task/<id:\d+>' => 'fruit2/mango/alphonso/options',
12+
];
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace app\models;
4+
5+
class Task extends \app\models\base\Task
6+
{
7+
8+
9+
}
10+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/**
4+
* This file is generated by Gii, do not change manually!
5+
*/
6+
7+
namespace app\models\base;
8+
9+
/**
10+
* This is the model class for table "tasks".
11+
*
12+
* @property int $id
13+
* @property string $title
14+
*
15+
*/
16+
abstract class Task extends \yii\db\ActiveRecord
17+
{
18+
public static function tableName()
19+
{
20+
return '{{%tasks}}';
21+
}
22+
23+
public function rules()
24+
{
25+
return [
26+
'trim' => [['title'], 'trim'],
27+
'title_string' => [['title'], 'string'],
28+
];
29+
}
30+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace app\fruit;
4+
5+
class Module extends \yii\base\Module
6+
{
7+
8+
public function init()
9+
{
10+
parent::init();
11+
$this->modules = [
12+
'mango' => [
13+
'class' => \app\fruit\mango\Module::class,
14+
],
15+
];
16+
}
17+
18+
19+
}
20+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace app\fruit\mango;
4+
5+
class Module extends \yii\base\Module
6+
{
7+
8+
public function init()
9+
{
10+
parent::init();
11+
}
12+
13+
14+
}
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace app\fruit\mango\controllers;
4+
5+
class AlphonsoController extends \app\fruit\mango\controllers\base\AlphonsoController
6+
{
7+
8+
public function actions()
9+
{
10+
$actions = parent::actions();
11+
return $actions;
12+
}
13+
14+
public function checkAccess($action, $model = null, $params = [])
15+
{
16+
//TODO implement checkAccess
17+
}
18+
19+
20+
}
21+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
namespace app\fruit\mango\controllers\base;
3+
4+
use insolita\fractal\JsonApiController;
5+
use Yii;
6+
7+
abstract class AlphonsoController extends JsonApiController
8+
{
9+
public function actions()
10+
{
11+
return [
12+
'list' => [
13+
'class' => \insolita\fractal\actions\ListAction::class,
14+
'checkAccess' => [$this, 'checkAccess'],
15+
'transformer' => \app\transformers\TaskTransformer::class,
16+
'modelClass' => \app\models\Task::class,
17+
'resourceKey' => 'tasks',
18+
'dataFilter' => null,
19+
'prepareDataProvider' => null
20+
],
21+
'options' => [
22+
'class' => \yii\rest\OptionsAction::class,
23+
],
24+
];
25+
}
26+
27+
/**
28+
* Checks the privilege of the current user.
29+
*
30+
* This method checks whether the current user has the privilege
31+
* to run the specified action against the specified data model.
32+
* If the user does not have access, a [[ForbiddenHttpException]] should be thrown.
33+
*
34+
* @param string $action the ID of the action to be executed
35+
* @param object $model the model to be accessed. If null, it means no specific model is being accessed.
36+
* @param array $params additional parameters
37+
* @throws \yii\web\ForbiddenHttpException if the user does not have access
38+
*/
39+
abstract public function checkAccess($action, $model = null, $params = []);
40+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace app\fruit2;
4+
5+
class Module extends \yii\base\Module
6+
{
7+
8+
public function init()
9+
{
10+
parent::init();
11+
$this->modules = [
12+
'mango' => [
13+
'class' => \app\fruit2\mango\Module::class,
14+
],
15+
];
16+
}
17+
18+
19+
}
20+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace app\fruit2\mango;
4+
5+
class Module extends \yii\base\Module
6+
{
7+
8+
public function init()
9+
{
10+
parent::init();
11+
}
12+
13+
14+
}
15+

0 commit comments

Comments
 (0)