Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/apiurls.py
Show All 24 Lines | class APIUrls(UrlsIndex): | ||||
_apidoc_routes = {} # type: Dict[str, Dict[str, str]] | _apidoc_routes = {} # type: Dict[str, Dict[str, str]] | ||||
scope = 'api' | scope = 'api' | ||||
@classmethod | @classmethod | ||||
def get_app_endpoints(cls): | def get_app_endpoints(cls): | ||||
return cls._apidoc_routes | return cls._apidoc_routes | ||||
@classmethod | @classmethod | ||||
def add_route(cls, route, docstring, **kwargs): | def add_doc_route(cls, route, docstring, noargs=False, | ||||
api_version='1', **kwargs): | |||||
""" | """ | ||||
Add a route to the self-documenting API reference | Add a route to the self-documenting API reference | ||||
""" | """ | ||||
route_view_name = 'api-1-%s' % route[1:-1].replace('/', '-') | route_name = route[1:-1].replace('/', '-') | ||||
if not noargs: | |||||
route_name = '%s-doc' % route_name | |||||
route_view_name = 'api-%s-%s' % (api_version, route_name) | |||||
if route not in cls._apidoc_routes: | if route not in cls._apidoc_routes: | ||||
d = {'docstring': docstring, | d = {'docstring': docstring, | ||||
'route': '/api/%s%s' % (api_version, route), | |||||
'route_view_name': route_view_name} | 'route_view_name': route_view_name} | ||||
for k, v in kwargs.items(): | for k, v in kwargs.items(): | ||||
d[k] = v | d[k] = v | ||||
cls._apidoc_routes[route] = d | cls._apidoc_routes[route] = d | ||||
def api_route(url_pattern=None, view_name=None, | def api_route(url_pattern=None, view_name=None, | ||||
methods=['GET', 'HEAD', 'OPTIONS'], | methods=['GET', 'HEAD', 'OPTIONS'], | ||||
Show All 39 Lines |