8000 📝 Fix docs UI asset paths to respect `root_path` in Custom Docs code example by bertomaniac · Pull Request #13825 · fastapi/fastapi · GitHub
[go: up one dir, main page]

Skip to content

📝 Fix docs UI asset paths to respect root_path in Custom Docs code example #13825

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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

bertomaniac
Copy link
@bertomaniac bertomaniac commented Jun 24, 2025

Description

Updates docs for https://fastapi.tiangolo.com/how-to/custom-docs-ui-assets/ with better examples for handling root_path setups.

Updates tests to validate static assets when root_path is used in conjunction with self-hosting swagger/redoc assets.

@github-actions github-actions bot added the docs Documentation about how to use FastAPI label Jun 24, 2025

This comment was marked as outdated.

This comment was marked as outdated.

@YuriiMotov YuriiMotov changed the title Add tests for self-hosted docs behind a proxy 📝 Fix docs UI asset paths to respect root_path in Custom Docs code example Jun 24, 2025
YuriiMotov

This comment was marked as resolved.

@bertomaniac
Copy link
Author

@YuriiMotov: Ahh...I didn't realize there was a test already for test_custom_docs_ui.

I'll move things over to there.

@bertomaniac bertomaniac requested a review from YuriiMotov June 24, 2025 16:34
@bertomaniac

This comment was marked as resolved.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

@YuriiMotov

This comment was marked as resolved.

@bertomaniac

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

@bertomaniac
Copy link
Author

@YuriiMotov

I updated tutorial_001.py and updated the tests for it to handle the different root_path/request_path/asgi_path params. I also updated the highlighting line numbers on the how-to/custom-docs-ui-assets page.

I think this is probably in a good spot now.

Copy link
Contributor
@YuriiMotov YuriiMotov left a comment

Choose a reason for hiding this comment

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

LGTM

This PR fixes the code examples in Custom Docs UI Static Assets (Self-Hosting).
Before changes those examples fail if we run server behind the stripping path proxy and specify root_path as a parameter to FastAPI(root_path="/api"). In this case app receives requests with path without root_path prefix (/static/swagger-ui.css instead of /api/static/swagger-ui.css) and UI fails to load self-hosted assets.

Updated code examples are in line with the current implementations of default swagger_ui_html (link) and redoc_html (link) routes.

Tests look a bit complicated, the idea is explained here.

Checked line highlights - all correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation about how to use FastAPI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0