This repository has been archived by the owner on Sep 10, 2021. It is now read-only.
/
ApidocsController.php
77 lines (68 loc) · 2.73 KB
/
ApidocsController.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
All rights reserved.
More information http://www.kitware.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
/**
* Apidocs Controller for the web API
*/
class ApidocsController extends AppController
{
public $_components = array('Apidocs');
/** init api actions */
public function init()
{
$this->disableLayout();
$this->disableView();
}
/** Index resource */
public function indexAction()
{
$results = array();
$results['apiVersion'] = '1.0';
$results['swaggerVersion'] = '1.1';
$baseUrl = $this->getRequest()->getScheme().'://'.$this->getRequest()->getHttpHost().$this->view->webroot;
$results['basePath'] = $baseUrl.'/apidocs';
$results['apis'] = array();
$resources = $this->Component->Apidocs->getEnabledResources();
foreach ($resources as $resourcePath) {
if (strpos($resourcePath, '/') > 0) {
$resourcePath = '/'.$resourcePath;
}
$curResource = array();
$curResource['path'] = $resourcePath;
$curResource['description'] = 'Operations on the '.$resourcePath.' resource';
array_push($results['apis'], $curResource);
}
echo JsonComponent::encode($results);
}
/**
* We override __call to intercept the path and transform
* it into a resource and module name, and pass that into the ApidocsComponent.
*/
public function __call($name, $args)
{
$pathParams = UtilityComponent::extractPathParams();
$module = '';
$resource = $this->getRequest()->getActionName();
if (count($pathParams)) {
if (in_array($this->getRequest()->getActionName(), Zend_Registry::get('modulesEnable'))) {
$module = $this->getRequest()->getActionName();
$resource = $pathParams[0];
}
}
$results = $this->Component->Apidocs->getResourceApiDocs($resource, $module);
echo JsonComponent::encode($results);
}
}