noirbizarre / flask-restplus

Fully featured framework for fast, easy and documented API development with Flask
http://flask-restplus.readthedocs.org
Other
2.73k stars 507 forks source link

Flask-RESTPlus caches the Swagger basePath (and the rest of the schema), which breaks the Swagger page when proxy configuration enables multiple URLs to point to the Swagger page #755

Open michaeljb opened 5 years ago

michaeljb commented 5 years ago

Code

I have a repo set up using Docker containers to demonstrate the issue - https://github.com/michaeljb/flask-restplus-755-sscce/

Most relevant part is probably the nginx /api/ proxy configuration - https://github.com/michaeljb/flask-restplus-755-sscce/blob/master/nginx/frp-sscce.conf#L36-L48

Here's the code where Flask-RESTPlus is used - https://github.com/michaeljb/flask-restplus-755-sscce/blob/master/api/frp_sscce/__init__.py#L10-L14

Repro Steps (if applicable)

1) Have an app using Flask-RESTPlus running 2) Have a proxy server running that provides an alternate path to that app 3) Access the Swagger page (at the root of the app), and note the "Base URL"

This repo is setup to do the above with Docker - https://github.com/michaeljb/flask-restplus-755-sscce#running

I took a screen recording of myself reproducing the issue (skip the first 2:35, that's just the Docker containers being built and started for the first time) - https://github.com/michaeljb/flask-restplus-755-sscce/raw/master/demo.mov

Expected Behavior

The "Base URL" should correspond to whichever URL is currently being used to access the Swagger page.

Actual Behavior

The "Base URL" only corresponds to the first URL used to access the Swagger page; subsequent requests from different URLs re-use whichever value was used first.

Environment

Additional Context

I have tested a code change for Flask-RESTPlus that works, but I don't know if it has other unwanted side effects. I can open a pull request with that branch if it seems like an acceptable solution.

https://github.com/michaeljb/flask-restplus/commit/0bd8913ed6b6a66e0ac281dfeaeaa0353006fc9d

JuniorZilles commented 4 years ago

I'm having the same problem. My host it's like 'something.com' but the api works in 'something.com/api/name/resource', and when I call 'something.com/api/name/docs-api' the system try to get the info from 'something.com/swaggerui/...' but is nothing there to find so it doesn't show.

There is a workaround until its fixed?