Skip to content

Commit

Permalink
Merge pull request #103 from Ouranosinc/no-extra-slash
Browse files Browse the repository at this point in the history
remove all extra api swagger paths
  • Loading branch information
fmigneault authored Sep 15, 2018
2 parents 41099d4 + cbcc232 commit 81546e2
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 20 deletions.
7 changes: 0 additions & 7 deletions magpie/api/api_rest_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ def service_api_route_info(service_api):
path='/api',
name='swagger_schema_ui',
description="{} documentation".format(TitleAPI))
# trailing '/' allows the route to work on all following routes:
# - '/api'
# - '/api/'
# - '/magpie/api'
# - '/magpie/api/' (final '/' added automatically by application)
SwaggerAPI_extra_name = SwaggerAPI.name + '_extra'
SwaggerAPI_extra_path = SwaggerAPI.path + '/'
UsersAPI = Service(
path='/users',
name='Users')
Expand Down
4 changes: 0 additions & 4 deletions magpie/ui/swagger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@
def includeme(config):
logger.info('Adding swagger ...')
config.add_route(**service_api_route_info(SwaggerAPI))
config.add_route(SwaggerAPI_extra_name, SwaggerAPI_extra_path)
config.add_route(**service_api_route_info(SwaggerGenerator))
config.add_view(api_schema, route_name=SwaggerGenerator.name, request_method='GET',
renderer='json', permission=NO_PERMISSION_REQUIRED)
config.add_view(api_swagger, route_name=SwaggerAPI.name,
renderer='templates/swagger_ui.mako', permission=NO_PERMISSION_REQUIRED)
config.add_view(api_swagger, route_name=SwaggerAPI_extra_name,
renderer='templates/swagger_ui.mako', permission=NO_PERMISSION_REQUIRED)
# config.scan()
10 changes: 1 addition & 9 deletions magpie/ui/swagger/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@


@SwaggerAPI.get(tags=[APITag])
#@view_config(route_name=SwaggerAPI.name, renderer='templates/swagger_ui.mako', permission=NO_PERMISSION_REQUIRED)
#@view_config(route_name=SwaggerAPI_extra_name, renderer='templates/swagger_ui.mako', permission=NO_PERMISSION_REQUIRED)
def api_swagger(request):
"""
Swagger UI route to display the Magpie REST API schemas.
"""
swagger_versions_dir = '{}'.format(os.path.abspath(os.path.join(MAGPIE_MODULE_DIR, 'ui/swagger/versions')))
swagger_ui_path = SwaggerGenerator.path
# come back one level if path ends with '/' to properly find json (from Magpie API extra path)
if request.url.endswith(SwaggerAPI.path + '/'):
swagger_ui_path = '../{}'.format(swagger_ui_path.lstrip('/'))
# remove leading '/' if path is on same level so that json page can be found by relative route
elif swagger_ui_path.startswith('/'):
swagger_ui_path = swagger_ui_path.rstrip('/')
swagger_ui_path = SwaggerGenerator.path.lstrip('/')
return_data = {'api_title': TitleAPI,
'api_schema_path': swagger_ui_path,
'api_schema_versions_dir': swagger_versions_dir}
Expand Down

0 comments on commit 81546e2

Please sign in to comment.