pyramid_swagger icon indicating copy to clipboard operation
pyramid_swagger copied to clipboard

No swagger.json when using config.route_prefix

Open weissglut-dev opened this issue 7 years ago • 2 comments

Hi,

when I use the setting config.route_prefix = '/api/v1' the api routes do work, which is great. But I get an error when I try to get the swagger.json file with /api/v1/swagger.json

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/pyramid_debugtoolbar/toolbar.py", line 215, in toolbar_tween
    response = _handler(request)
  File "/usr/local/lib/python3.6/site-packages/pyramid_debugtoolbar/panels/performance.py", line 57, in resource_timer_handler
    result = handler(request)
  File "/usr/local/lib/python3.6/site-packages/pyramid/tweens.py", line 51, in excview_tween
    request_iface=request_iface.combined
  File "/usr/local/lib/python3.6/site-packages/pyramid/view.py", line 612, in _call_view
    response = view_callable(context, request)
  File "/usr/local/lib/python3.6/site-packages/pyramid/viewderivers.py", line 409, in viewresult_to_response
    result = view(context, request)
  File "/usr/local/lib/python3.6/site-packages/pyramid/tweens.py", line 22, in excview_tween
    response = handler(request)
  File "/usr/local/lib/python3.6/site-packages/pyramid_swagger/tween.py", line 155, in validator_tween
    return handler(request)
  File "/usr/local/lib/python3.6/site-packages/pyramid/router.py", line 155, in handle_request
    view_name
  File "/usr/local/lib/python3.6/site-packages/pyramid/view.py", line 612, in _call_view
    response = view_callable(context, request)
  File "/usr/local/lib/python3.6/site-packages/pyramid/viewderivers.py", line 438, in rendered_view
    result = view(context, request)
  File "/usr/local/lib/python3.6/site-packages/pyramid/viewderivers.py", line 147, in _requestonly_view
    response = view(request)
  File "/usr/local/lib/python3.6/site-packages/pyramid_swagger/api.py", line 540, in view_for_swagger_schema
    actual_fname = file_map[request.path]
KeyError: '/api/v1/swagger.json'

Do you have any idea what I am doing wrong?

Thank you very much Regards Seyhbold

weissglut-dev avatar Mar 27 '17 14:03 weissglut-dev

We define our own routes in https://github.com/striglia/pyramid_swagger/blob/master/pyramid_swagger/api.py#L18. Perhaps that code won't respect the route prefix for some reason?

Are you confident you're configuring this route prefix in advance of invoking the pyramid_swagger tween? I could believe it might be possible to do the reverse, so the route would already exist before you specify the prefix...

Also the version of pyramid and pyramid_swagger in use is always helpful 👍

striglia avatar Mar 27 '17 16:03 striglia

Sorry for the late answer.

I am using pyramid 1.8.3 and pyramid_swagger 2.3.1

with

    config = Configurator(settings=settings)
    config.include("pyramid_swagger")
    config.route_prefix = '/api/v1'

the api is available at /api/v1 and swagger.json at / But I would like swagger.json at /api/v1/swagger.json

    config = Configurator(settings=settings)
    config.route_prefix = '/api/v1'
    config.include("pyramid_swagger")

The api is available at /api/v1and swagger.json is not available. At /api/v1/swagger.json I get the error mentioned above.

image

Could it be that the file_map is not built correctly?

In api.py#_build_swagger_20_schema_views https://github.com/striglia/pyramid_swagger/blob/master/pyramid_swagger/api.py#L553

The route_prefix is not used. Do you think adding config.route_prefix to the path = '/{0}.{1}....' would be the right way? If so I would submit a PR for that.

Thanks very much Best Regards

Seyhbold

weissglut-dev avatar Apr 04 '17 07:04 weissglut-dev