Skip to content

Commit f3d71e7

Browse files
committed
Complete tests
1 parent 3a44f9b commit f3d71e7

File tree

18 files changed

+379
-24
lines changed

18 files changed

+379
-24
lines changed

TODO.taskpaper

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
TODO.taskpaper
22

33
### Add validation rules by attribute name or pattern #30
4-
Re-check
5-
create failing test
6-
implement the solution
7-
fix failing tests if any
8-
resolve TODOs if any
9-
review PR
4+
Re-check @done (24-09-03 16:48)
5+
create failing test @done (24-09-03 16:48)
6+
implement the solution @done (24-09-03 16:48)
7+
fix failing tests if any @done (24-09-03 16:48)
8+
resolve TODOs if any @done (24-09-03 16:55)
9+
review PR @done (24-09-03 16:55)
1010
☐ delete this file and submit PR

src/lib/items/FractalAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*/
3333
final class FractalAction extends BaseObject
3434
{
35-
use OptionsRouteTrait;
35+
use OptionsRoutesTrait;
3636

3737
/**@var string* */
3838
public $id;

src/lib/items/OptionsRouteTrait.php renamed to src/lib/items/OptionsRoutesTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
namespace cebe\yii2openapi\lib\items;
99

10-
trait OptionsRouteTrait
10+
trait OptionsRoutesTrait
1111
{
1212
public function getOptionsRoute():string
1313
{
1414
if ($this->prefix && !empty($this->prefixSettings)) {
1515
if (isset($this->prefixSettings['module'])) {
1616
$prefix = $this->prefixSettings['module'];
1717
return static::finalOptionsRoute($prefix, $this->controllerId);
18-
} elseif (isset($this->prefixSettings['namespace']) && str_contains($this->prefixSettings['namespace'], '\modules\\')) {
18+
} elseif (isset($this->prefixSettings['namespace']) && str_contains($this->prefixSettings['namespace'], '\modules\\')) { # if `module` not present then check in namespace and then in path
1919
$prefix = static::computeModule('\\', $this->prefixSettings['namespace']);
2020
if ($prefix) {
2121
return static::finalOptionsRoute($prefix, $this->controllerId);

src/lib/items/RestAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*/
3232
final class RestAction extends BaseObject
3333
{
34-
use OptionsRouteTrait;
34+
use OptionsRoutesTrait;
3535

3636
/**@var string* */
3737
public $id;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* OpenAPI UrlRules
4+
*
5+
* This file is auto generated.
6+
*/
7+
return [
8+
'GET api/v1/pets' => 'api/v1/pet/list',
9+
'POST api/v1/pets' => 'api/v1/pet/create',
10+
'GET animals/pets/<id:[\w-]+>' => 'pet/view',
11+
'DELETE animals/pets/<id:[\w-]+>' => 'pet/delete',
12+
'PATCH animals/pets/<id:[\w-]+>' => 'pet/update',
13+
'GET petComments' => 'pet-comment/list',
14+
'GET info/pet-details' => 'petinfo/pet-detail/list',
15+
'GET forum/pet2-details' => 'forum/pet2-detail/list',
16+
'GET forum2/pet3-details' => 'forum2/pet3-detail/list',
17+
'GET api/v2/comments' => 'api/v2/comment/list',
18+
'api/v1/pets' => 'some/pet/options',
19+
'animals/pets/<id:[\w-]+>' => 'pet/options',
20+
'petComments' => 'pet-comment/options',
21+
'info/pet-details' => 'petinfo/pet-detail/options',
22+
'forum/pet2-details' => 'forum/pet2-detail/options',
23+
'forum2/pet3-details' => 'forum2/pet3-detail/options',
24+
'api/v2/comments' => 'api/v2/comment/options',
25+
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace app\controllers;
4+
5+
class PetCommentController extends \app\controllers\base\PetCommentController
6+
{
7+
8+
public function checkAccess($action, $model = null, $params = [])
9+
{
10+
//TODO implement checkAccess
11+
}
12+
13+
public function actionList()
14+
{
15+
//TODO implement actionList
16+
}
17+
18+
19+
}
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace app\controllers\base;
4+
5+
abstract class PetCommentController extends \yii\rest\Controller
6+
{
7+
public function actions()
8+
{
9+
return [
10+
'options' => [
11+
'class' => \yii\rest\OptionsAction::class,
12+
],
13+
];
14+
}
15+
16+
/**
17+
* Checks the privilege of the current user.
18+
*
19+
* This method checks whether the current user has the privilege
20+
* to run the specified action against the specified data model.
21+
* If the user does not have access, a [[ForbiddenHttpException]] should be thrown.
22+
*
23+
* @param string $action the ID of the action to be executed
24+
* @param object $model the model to be accessed. If null, it means no specific model is being accessed.
25+
* @param array $params additional parameters
26+
* @throws \yii\web\ForbiddenHttpException if the user does not have access
27+
*/
28+
abstract public function checkAccess($action, $model = null, $params = []);
29+
30+
abstract public function actionList();
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace app\some\controllers;
4+
5+
class CommentController extends \app\some\controllers\base\CommentController
6+
{
7+
8+
public function checkAccess($action, $model = null, $params = [])
9+
{
10+
//TODO implement checkAccess
11+
}
12+
13+
public function actionList()
14+
{
15+
//TODO implement actionList
16+
}
17+
18+
19+
}
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace app\some\controllers\base;
4+
5+
abstract class CommentController extends \yii\rest\Controller
6+
{
7+
public function actions()
8+
{
9+
return [
10+
'options' => [
11+
'class' => \yii\rest\OptionsAction::class,
12+
],
13+
];
14+
}
15+
16+
/**
17+
* Checks the privilege of the current user.
18+
*
19+
* This method checks whether the current user has the privilege
20+
* to run the specified action against the specified data model.
21+
* If the user does not have access, a [[ForbiddenHttpException]] should be thrown.
22+
*
23+
* @param string $action the ID of the action to be executed
24+
* @param object $model the model to be accessed. If null, it means no specific model is being accessed.
25+
* @param array $params additional parameters
26+
* @throws \yii\web\ForbiddenHttpException if the user does not have access
27+
*/
28+
abstract public function checkAccess($action, $model = null, $params = []);
29+
30+
abstract public function actionList();
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace app\modules\forum\controllers;
4+
5+
class Pet2DetailController extends \app\modules\forum\controllers\base\Pet2DetailController
6+
{
7+
8+
public function checkAccess($action, $model = null, $params = [])
9+
{
10+
//TODO implement checkAccess
11+
}
12+
13+
public function actionList()
14+
{
15+
//TODO implement actionList
16+
}
17+
18+
19+
}
20+

0 commit comments

Comments
 (0)