-
Notifications
You must be signed in to change notification settings - Fork 21
/
SwaggerController.php
48 lines (42 loc) · 1.34 KB
/
SwaggerController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
declare(strict_types=1);
namespace SwaggerBake\Controller;
use Cake\Controller\Controller;
use Cake\Http\Response;
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): Response
{
/*
* 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));
}
}