-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8c7b0c
commit 5d1c25e
Showing
21 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
Documentation startup module | ||
Module asigns adds the /docs route to the API, to display the APIS's documentation. | ||
Usage: | ||
- Import the add_documentation function, and pass the FastAPI app as a parameter. | ||
""" | ||
|
||
from fastapi import FastAPI, status, HTTPException, Request | ||
from fastapi.openapi.docs import get_swagger_ui_html | ||
from fastapi.responses import HTMLResponse | ||
from fastapi.staticfiles import StaticFiles | ||
|
||
|
||
def add_documentation(app: FastAPI): | ||
""" | ||
This function adds the API /docs route | ||
""" | ||
app.mount("/static", StaticFiles(directory="static"), name="static") | ||
|
||
@app.get("/docs", include_in_schema=False) | ||
def overridden_swagger(req: Request) -> HTMLResponse: | ||
root_path = req.scope.get("root_path", "").rstrip("/") | ||
openapi_url = root_path + app.openapi_url | ||
oauth2_redirect_url = app.swagger_ui_oauth2_redirect_url | ||
if oauth2_redirect_url: | ||
oauth2_redirect_url = root_path + oauth2_redirect_url | ||
return get_swagger_ui_html( | ||
openapi_url=openapi_url, | ||
title=app.title + " | Docs", | ||
oauth2_redirect_url=oauth2_redirect_url, | ||
init_oauth=app.swagger_ui_init_oauth, | ||
swagger_favicon_url="/static/logo.png", | ||
swagger_ui_parameters=app.swagger_ui_parameters, | ||
) | ||
|
||
@app.get("/redoc", include_in_schema=False) | ||
def overridden_redoc(): | ||
raise HTTPException( | ||
status_code=status.HTTP_400_BAD_REQUEST, | ||
detail="Not Found" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.