Class luya\admin\openapi\ActionRouteParser
Inheritance | luya\admin\openapi\ActionRouteParser » luya\admin\openapi\BasePathParser |
---|---|
Available since version | 3.2.0 |
Source Code | https://github.com/luyadev/luya-module-admin/blob/master/src/openapi/ActionRouteParser.php |
Generate a path for a absolute route to an action.
Protected Properties
Public Methods
Method | Description | Defined By |
---|---|---|
__construct() | luya\admin\openapi\ActionRouteParser | |
generateOperationId() | Generate a readable operation id for current route and verb. | luya\admin\openapi\BasePathParser |
getPath() | Returns the path which should be associated with this endpoint. | luya\admin\openapi\ActionRouteParser |
getPathItem() | Return a PathItem. | luya\admin\openapi\ActionRouteParser |
isValid() | Whether this Parser is valid or not. | luya\admin\openapi\ActionRouteParser |
normalizeTag() | Generate a normalized tag from a given route. | luya\admin\openapi\BasePathParser |
routes() | Returns all absolute controller map routes which are covered by this parser. | luya\admin\openapi\ActionRouteParser |
Property Details
Method Details
public void __construct ( yii\base\Controller $controller, $actionName, $absoluteRoute, $controllerMapRoute ) | ||
$controller | ||
$actionName | ||
$absoluteRoute | ||
$controllerMapRoute |
public function __construct(Controller $controller, $actionName, $absoluteRoute, $controllerMapRoute)
{
$this->controllerSpecs = new ControllerSpecs($controller);
$this->actionSpecs = new ControllerActionSpecs($controller, $actionName, 'get');
$this->absoluteRoute = $absoluteRoute;
$this->controllerMapRoute = $controllerMapRoute;
$this->actionName = $actionName;
}
Defined in: luya\admin\openapi\BasePathParser::generateOperationId()
Generate a readable operation id for current route and verb.
public string generateOperationId ( $verb ) | ||
$verb | string |
public function generateOperationId($verb)
{
$path = ltrim(str_replace(["admin/api-", "admin/api", "admin/"], '', $this->getPath()), '/');
$operation = $verb . '-'. str_replace("/", " ", $path); // replace slashes with newlines
$camelCase = Inflector::slug($operation, '-', true, false);
return Generator::generateUniqueOperationId(Inflector::id2camel($camelCase));
}
Returns the path which should be associated with this endpoint.
This is the actual route which then recieves the request.
public string getPath ( ) |
public function getPath(): string
{
return '/'.$this->absoluteRoute;
}
Return a PathItem.
A PathItem represents a path within the openapi definition. A path (or maybe also named as endpoint/route) can have multiple verbs. Like post, get, put
public \cebe\openapi\spec\PathItem getPathItem ( ) |
public function getPathItem(): PathItem
{
return new PathItem([
'summary' => $this->controllerSpecs->getSummary(),
'description' => $this->controllerSpecs->getDescription(),
'get' => new Operation([
'tags' => [$this->normalizeTag($this->controllerMapRoute)],
'summary' => $this->actionSpecs->getSummary(),
'description' => $this->actionSpecs->getDescription(),
'operationId' => $this->generateOperationId('get'),
'parameters' => $this->actionSpecs->getParameters(),
'responses' => new Responses($this->actionSpecs->getResponses())
])
]);
}
Whether this Parser is valid or not.
public boolean isValid ( ) |
public function isValid(): bool
{
if ($this->controllerSpecs->controller instanceof Api && $this->actionName == 'filter') {
if (empty($this->controllerSpecs->controller->model->ngRestFilters())) {
return false;
}
}
return true;
}
Defined in: luya\admin\openapi\BasePathParser::normalizeTag()
Generate a normalized tag from a given route.
public string normalizeTag ( $route ) | ||
$route | string |
public function normalizeTag($route)
{
$route = str_replace(["admin/"], '', $route);
return ltrim(trim($route, '/'));
}
Returns all absolute controller map routes which are covered by this parser.
For example the update and post route are difference and covered, it would be:
- admin/api-admin-user/create
- admin/api-admin-user/update
public array routes ( ) |
public function routes(): array
{
return [$this->controllerMapRoute];
}