from . import Controller, BaseController, Endpoint, ENDPOINT_MAP
from .. import logger, mgr
+from ..tools import str_to_bool
+
@Controller('/docs', secure=False)
class Docs(BaseController):
# Scenarios to consider:
# * Intentionally make up a new tag name at controller => New tag name displayed.
# * Misspell or make up a new tag name at endpoint => Neither tag or endpoint displayed.
- # * Misspell tag name at controller (when refering to another controller) =>
+ # * Misspell tag name at controller (when referring to another controller) =>
# Tag displayed but no endpoints assigned
# * Description for a tag added at multiple locations => Only one description displayed.
list_of_ctrl = set()
@classmethod
# isinstance doesn't work: input is always <type 'type'>.
def _type_to_str(cls, type_as_type):
- """ Used if type is explcitly defined. """
+ """ Used if type is explicitly defined. """
if type_as_type is str:
type_as_str = 'string'
elif type_as_type is int:
def _add_param_info(cls, parameters, p_info):
# Cases to consider:
# * Parameter name (if not nested) misspelt in decorator => parameter not displayed
- # * Sometime a parameter is used for several endpoints (e.g. fs_id in CephFS).
- # Currently, there is no possiblity of reuse. Should there be?
+ # * Sometimes a parameter is used for several endpoints (e.g. fs_id in CephFS).
+ # Currently, there is no possibility of reuse. Should there be?
# But what if there are two parameters with same name but different functionality?
"""
- Adds explicitly desrcibed information for parameters of an endpoint.
+ Adds explicitly described information for parameters of an endpoint.
There are two cases:
* Either the parameter in p_info corresponds to an endpoint parameter. Implicit information
has higher priority, so only information that doesn't already exist is added.
* Or the parameter in p_info describes a nested parameter inside an endpoint parameter.
- In that case there is no implcit information at all so all explicitly described info needs
+ In that case there is no implicit information at all so all explicitly described info needs
to be added.
"""
for p in p_info:
return paths
- def _gen_spec(self, all_endpoints=False, baseUrl=""):
+ def _gen_spec(self, all_endpoints=False, base_url=""):
if all_endpoints:
- baseUrl = ""
+ base_url = ""
host = cherrypy.request.base
host = host[host.index(':')+3:]
logger.debug("DOCS: Host: %s", host)
- paths = self._gen_paths(all_endpoints, baseUrl)
+ paths = self._gen_paths(all_endpoints, base_url)
- if not baseUrl:
- baseUrl = "/"
+ if not base_url:
+ base_url = "/"
scheme = 'https'
- ssl = mgr.get_localized_module_option('ssl', 'True')
+ ssl = str_to_bool(mgr.get_localized_module_option('ssl', True))
if not ssl:
scheme = 'http'
'title': "Ceph-Dashboard REST API"
},
'host': host,
- 'basePath': baseUrl,
- 'servers': [{'url': "{}{}".format(cherrypy.request.base, baseUrl)}],
+ 'basePath': base_url,
+ 'servers': [{'url': "{}{}".format(cherrypy.request.base, base_url)}],
'tags': self._gen_tags(all_endpoints),
'schemes': [scheme],
'paths': paths,
if token is not None:
jwt_token = token
- apiKeyCallback = """, onComplete: () => {{
+ api_key_callback = """, onComplete: () => {{
ui.preauthorizeApiKey('jwt', '{}');
}}
""".format(jwt_token)
</script>
</body>
</html>
- """.format(spec_url, apiKeyCallback)
+ """.format(spec_url, api_key_callback)
return page
cls.setup_controllers([DecoratedController, Docs], "/test")
def test_group_info_attr(self):
- testCtrl = DecoratedController()
- self.assertTrue(hasattr(testCtrl, 'doc_info'))
- self.assertIn('tag_descr', testCtrl.doc_info)
- self.assertIn('tag', testCtrl.doc_info)
+ test_ctrl = DecoratedController()
+ self.assertTrue(hasattr(test_ctrl, 'doc_info'))
+ self.assertIn('tag_descr', test_ctrl.doc_info)
+ self.assertIn('tag', test_ctrl.doc_info)
def test_endpoint_info_attr(self):
- testCtrl = DecoratedController()
- testEndpoint = testCtrl.decorated_func
- self.assertTrue(hasattr(testEndpoint, 'doc_info'))
- self.assertIn('summary', testEndpoint.doc_info)
- self.assertIn('tag', testEndpoint.doc_info)
- self.assertIn('parameters', testEndpoint.doc_info)
- self.assertIn('response', testEndpoint.doc_info)
+ test_ctrl = DecoratedController()
+ test_endpoint = test_ctrl.decorated_func
+ self.assertTrue(hasattr(test_endpoint, 'doc_info'))
+ self.assertIn('summary', test_endpoint.doc_info)
+ self.assertIn('tag', test_endpoint.doc_info)
+ self.assertIn('parameters', test_endpoint.doc_info)
+ self.assertIn('response', test_endpoint.doc_info)
# To assure functionality of Docs.py