Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
cakephp-swagger-bake/src/Controller/SwaggerController.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
47 lines (41 sloc)
1.3 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace SwaggerBake\Controller; | |
use Cake\Controller\Controller; | |
use SwaggerBake\Lib\Service\OpenApiControllerService; | |
class SwaggerController extends Controller | |
{ | |
/** | |
* Displays either Swagger UI or Redoc | |
* | |
* @param \SwaggerBake\Lib\Service\OpenApiControllerService $service Builds OpenAPI JSON and hot reloads if enabled | |
* @return \Cake\Http\Response Renders view | |
*/ | |
public function index(OpenApiControllerService $service) | |
{ | |
/* | |
* Rebuild OpenAPI if hotReload is enabled | |
*/ | |
$service->build(); | |
/* | |
* Set some view vars | |
*/ | |
$config = $service->getConfig(); | |
$title = $config->getTitleFromYml(); | |
$url = $config->getWebPath(); | |
$this->set(compact('title', 'url')); | |
/* | |
* Set layout to either swagger or redoc | |
* | |
* @see vendor/cnizzardini/cakephp-swagger-bake/templates/layout | |
*/ | |
$doctype = $service->getDocType($this->request); | |
$this->viewBuilder()->setLayout($config->getLayout($doctype)); | |
/* | |
* Render either the swagger or redoc view | |
* | |
* @see vendor/cnizzardini/cakephp-swagger-bake/templates/Swagger | |
*/ | |
return $this->render($config->getView($doctype)); | |
} | |
} |