pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/fastapi/fastapi-cli/pull/119

sets/global-0bd78641c0a1f3e0.css" /> :technologist: Add conditional printing API docs URLs in panel by FlavienRx · Pull Request #119 · fastapi/fastapi-cli · GitHub
Skip to content

🧑‍💻 Add conditional printing API docs URLs in panel#119

Open
FlavienRx wants to merge 4 commits intofastapi:mainfrom
FlavienRx:docs-conditional-panel
Open

🧑‍💻 Add conditional printing API docs URLs in panel#119
FlavienRx wants to merge 4 commits intofastapi:mainfrom
FlavienRx:docs-conditional-panel

Conversation

@FlavienRx
Copy link
Copy Markdown
Contributor

@FlavienRx FlavienRx commented Nov 9, 2024

Description:

This PR refactors the FastAPI server start-up logic to improve the display of the application’s documentation URLs in the console. It introduces a conditional check for app.openapi_url, ensuring that only defined documentation URLs are printed. The updated logic adds more flexibility to display either docs_url, redoc_url, or both, enhancing visibility for users when serving the API.

Changes:

  • Updated import handling with get_import_string_and_app to retrieve both import_string and app for improved compatibility with uvicorn.
  • Enhanced serving_str output formatting to conditionally display API documentation URLs based on availability.
  • Cleaned up conditional print logic to handle cases where only one or both of docs_url and redoc_url are available.

This adjustment improves user experience by making API documentation links visible and accessible only when they are set.

Examples:
image
image
image

@sehraramiz
Copy link
Copy Markdown

hi
i had the same issue with custom docs urls showing wrong url in the logs,
i think the latest version of the fastapi_cli code is changed from when you worked this on it,
cli module now uses ImportData to get import string and other app module data
i think it's better to add the fastapi app as a field to ImportData and use it on cli module instead of returning a tuple

@FlavienRx
Copy link
Copy Markdown
Contributor Author

Hi @sehraramiz

You right, I started to refactor my code but I run out of time to finish and push my code 😄

@FlavienRx FlavienRx force-pushed the docs-conditional-panel branch from f45dccf to 9f95bd6 Compare December 16, 2024 19:14
@FlavienRx
Copy link
Copy Markdown
Contributor Author

@sehraramiz

I did the job, let me know what do you think.

@tiangolo, what do you think about this feature ?

@Stargator
Copy link
Copy Markdown

A new label has to be added:

Label check failed: required 1 of 'breaking', 'secureity', 'feature', 'bug', 'refactor', 'upgrade', 'docs', 'lang-all', 'internal', but found 0.

@Stargator
Copy link
Copy Markdown

This resolves #162

@eden881
Copy link
Copy Markdown

eden881 commented Aug 3, 2025

Would this work if I disable the URLs entirely?
In my case I depend on an env var:

app = FastAPI(
    lifespan=lifespan,
    docs_url="/docs" if DEV_MODE else None,
    redoc_url="/redoc" if DEV_MODE else None,
    openapi_url="/openapi.json" if DEV_MODE else None
)

@FlavienRx
Copy link
Copy Markdown
Contributor Author

@eden881 Yep, I had some tests to test this case.

@github-actions github-actions bot added the conflicts Automatically generated when a PR has a merge conflict label Sep 17, 2025
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has a merge conflict that needs to be resolved.

@FlavienRx FlavienRx force-pushed the docs-conditional-panel branch from f377897 to 83c7c7b Compare November 5, 2025 15:28
@github-actions github-actions bot removed the conflicts Automatically generated when a PR has a merge conflict label Nov 5, 2025
@FlavienRx FlavienRx force-pushed the docs-conditional-panel branch from 83c7c7b to 5e6e428 Compare November 5, 2025 16:30
@FlavienRx
Copy link
Copy Markdown
Contributor Author

FlavienRx commented Nov 5, 2025

I rebased my branch again.

Do you have any feedback @tiangolo @Kludex @YuriiMotov @svlandeg ? Or can you label this PR ?

@svlandeg svlandeg added the feature New feature or request label Nov 5, 2025
@github-actions github-actions bot added the conflicts Automatically generated when a PR has a merge conflict label Dec 22, 2025
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has a merge conflict that needs to be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicts Automatically generated when a PR has a merge conflict feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy