Skip to content

Commit f37e45e

Browse files
committed
Refactor and add docs
1 parent 2816f28 commit f37e45e

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ Generated URL rules config for above is (in `urls.rest.php` or pertinent file):
382382
'POST a1/b1' => 'abc/xyz',
383383
'a1/b1' => 'abc/options',
384384
```
385+
`x-route` does not support [Yii Modules](https://www.yiiframework.com/doc/guide/2.0/en/structure-modules).
385386

386387
## Many-to-Many relation definition
387388

src/generator/ApiGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ public function generate():array
474474
$urlRulesGenerator = Yii::createObject(UrlRulesGenerator::class, [$config, $actions]);
475475
$files = $urlRulesGenerator->generate();
476476

477-
$actions = static::removeDuplicateActions($actions);
477+
$actions = static::removeDuplicateActions($actions); // in case of non-crud actions having custom route `x-route` set
478478
$controllersGenerator = Yii::createObject(ControllersGenerator::class, [$config, $actions]);
479479
$files->merge($controllersGenerator->generate());
480480

src/lib/generators/RestActionGenerator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,19 @@ protected function resolvePath(string $path, PathItem $pathItem):array
7979
}
8080

8181
// TODO rename
82-
$actionHere = $this->prepareAction($method, $operation, $routeData, $customRoute);
82+
$action = $this->prepareAction($method, $operation, $routeData, $customRoute);
8383
if ($customRoute !== null) {
8484
if (in_array($customRoute, array_keys($this->allCustomRoutes))) {
85-
$actionHere->isDuplicate = true;
86-
if ($actionHere->params !== $this->allCustomRoutes[$customRoute]) {
85+
$action->isDuplicate = true;
86+
if ($action->params !== $this->allCustomRoutes[$customRoute]) {
8787
$this->allCustomRoutes[$customRoute]->isOriginalForCustomRoute = true;
8888
}
8989
} else {
90-
$actionHere->isDuplicate = false;
91-
$this->allCustomRoutes[$customRoute] = $actionHere;
90+
$action->isDuplicate = false;
91+
$this->allCustomRoutes[$customRoute] = $action;
9292
}
9393
}
94-
$actions[] = $actionHere;
94+
$actions[] = $action;
9595
}
9696
return $actions;
9797
}

src/lib/items/RestAction.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,19 @@ final class RestAction extends BaseObject
7171
/**
7272
* @var bool
7373
* @see $isDuplicate
74+
* https://github.com/cebe/yii2-openapi/issues/84
75+
* see `x-route` in README.md
76+
* Used for generating only one action for paths like: `GET /calendar/domains` and `GET /calendar/domains/{id}` given that they have same `x-route`.
77+
* This is used to flag first of one or more duplicates
7478
*/
7579
public $isOriginalForCustomRoute = false;
80+
7681
/**
7782
* @var bool
7883
* https://github.com/cebe/yii2-openapi/issues/84
79-
* Generate only one action for paths like: `GET /calendar/domains` and `GET /calendar/domains/{id}`.
84+
* Generate only one action for paths like: `GET /calendar/domains` and `GET /calendar/domains/{id}` given that they have same `x-route`.
8085
* @see $isOriginalForCustomRoute
86+
* see `x-route` in README.md
8187
*/
8288
public $isDuplicate = false;
8389

0 commit comments

Comments
 (0)