swagger-api / swagger-api/swagger-ui

Accessing swagger ui endpoints behind a reverse proxy?

Open
#7,957 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Q&A (please complete the following information)
  • OS: macOS
  • Browser: chrome
  • Version: 99
  • Method of installation: flasgger
  • Swagger-UI version: ?
  • Swagger/OpenAPI version: Swagger 2.0
How can we help?

Let's assume I have a Flask app exposing an endpoint /login and I expose this app behind a reverse proxy (traefik) using the prefix my_app (the proxy has to strip the prefix, however when I use the "try it out" function in swagger ui, it send the request to /my_app/login and my app doesn't know this route).

With this configuration, I can't reach the Swagger UI: if I set url_prefix to my_app in Flask configuration, the documentation will be exposed on /my_app/apidocs but the proxy will strip the first part of the path. I can "cheat" by accessing /my_app/my_app/apidocs but the page doesn't load (css, js etc...) because it will call my_app/swagger-ui-bundle.js for example (and the my_app will be stripped by the proxy).

Is there any way to set the prefix only when accessing the ressources of the swagger ui?

To recap I would like to have the following endpoints exposed :

  • /login
  • /apidocs
  • /* (swagger resources)

but when I'm loading the ui, I would like to perform requests to /my_app/* (similarly to the try it out functionality where I can use basePath

Thanks

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names Flask's url_prefix, Traefik's stripped prefix, Swagger UI's Try it out function, and basePath. Start by reproducing the described /my_app and /apidocs paths, then trace how Swagger UI builds asset and API request URLs. Done means the UI assets load and Try it out sends requests through the intended prefix.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, javascript, python
Domain
api, backend, documentation
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.