Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the Swagger UI work through the front-end proxy #502

Merged
merged 1 commit into from
Mar 20, 2023

Conversation

JosephMarinier
Copy link
Contributor

Description:

In certain contexts, for example, our demo, the only (easy) way to access the back end API is through the front end's proxy, at /api/local/.... The Swagger UI was therefore available at /api/local/docs, but it didn't work since it was trying to fetch the spec from /openapi.json instead of /api/local/openapi.json. This PR tells the Swagger UI to fetch the spec from ./openapi.json (relative path), so it works through the front-end proxy too. This also applies to the API URL if you Try it out. Here is the screenshot of the Swagger UI as expected when accessed through the front-end API:

Before:
image

After:
Screen Shot 2023-03-20 at 1 28 18 PM

Checklist:

You should check all boxes before the PR is ready. If a box does not apply, check it to acknowledge it.

  • ISSUE NUMBER. You linked the issue number (Ex: Resolve #XXX).
  • PRE-COMMIT. You ran pre-commit on all commits, or else, you
    ran pre-commit run --all-files at the end.
  • USER CHANGES. The changes are added to CHANGELOG.md and the documentation, if they impact
    our users.
  • DEV CHANGES.
    • Update the documentation if this PR changes how to develop/launch on the app.
    • Update the README files and our wiki for any big design decisions, if relevant.
    • Add unit tests, docstrings, typing and comments for complex sections.

@JosephMarinier JosephMarinier self-assigned this Mar 20, 2023
@@ -134,6 +134,8 @@ def create_app() -> FastAPI:
description="Azimuth API",
version="1.0",
default_response_class=JSONResponseIgnoreNan,
root_path=".", # Tells Swagger UI and ReDoc to fetch the OpenAPI spec from ./openapi.json
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, I didn't even know 😅, but we are serving a ReDoc: https://clinc150-azimuth-pr.azurewebsites.net/redoc
It gives the same information as the Swagger UI, but in another way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, wow!

@JosephMarinier JosephMarinier enabled auto-merge (squash) March 20, 2023 18:00
@JosephMarinier JosephMarinier merged commit c8908dd into main Mar 20, 2023
@JosephMarinier JosephMarinier deleted the joseph/swagger-through-front-end-proxy branch March 20, 2023 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants