No project description provided
Reason this release was yanked:
Too narrow dependency on fastapi==0.100
Project description
FastAPI Swagger Plugin
This plugin updates the FastAPI app to include a latest Swagger UI distribution. Also, it works locally and does not depend on the @tiangolo domains and cdns.
Why?
The FastAPI already includes a Swagger UI. However, author updates swagger not so often. Moreover he uses his own hosts for the resources, and they are not always available (especially in Russia). This plugin allows to use the latest Swagger UI distribution and host it inside your app.
Usage
Installation
pip install fastapi-swagger
Basic Usage
from fastapi import FastAPI
from fastapi_swagger import patch_fastapi
app = FastAPI(docs_url=None, swagger_ui_oauth2_redirect_url=None) # docs url will be at /docs
patch_fastapi(app)
How it works?
How it was before:
FastAPI uses the get_swagger_ui_html
function to render the Swagger UI under the hood.
def get_swagger_ui_html(
*,
openapi_url: str,
title: str,
swagger_js_url: str = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui-bundle.js",
swagger_css_url: str = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui.css",
swagger_favicon_url: str = "https://fastapi.tiangolo.com/img/favicon.png",
oauth2_redirect_url: Optional[str] = None,
init_oauth: Optional[Dict[str, Any]] = None,
swagger_ui_parameters: Optional[Dict[str, Any]] = None,
) -> HTMLResponse:
...
How it is now:
Actually, we just copy the Swagger UI distribution from
the GitHub releases to the fastapi_swagger
package, and serve it
from your app.
Patch creates several additional routes with the Swagger UI resources and one route for docs page (btw, using same
get_swagger_ui_html
function).
def patch_fastapi(
app: FastAPI,
docs_url: str = "/docs",
*,
title: Optional[str],
swagger_js_url: str = "/swagger/swagger-ui-bundle.js", # relative path from app root
swagger_css_url: str = "/swagger/swagger-ui.css", # relative path from app root
swagger_favicon_url: str = "/swagger/favicon-32x32.png", # relative path from app root
oauth2_redirect_url: Optional[str] = None,
init_oauth: Optional[Dict[str, Any]] = None,
swagger_ui_parameters: Optional[Dict[str, Any]] = None,
):
...
patch_fastapi(app)
# Now there are additional routes /swagger/swagger-ui-bundle.js, /swagger/swagger-ui.css, /swagger/favicon-32x32.png and /docs
# They all are not dependent on the external resources.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file fastapi_swagger-0.2.0.tar.gz
.
File metadata
- Download URL: fastapi_swagger-0.2.0.tar.gz
- Upload date:
- Size: 430.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49f25f9f01cdc2f35f4e1346e979c2ab81b29521953bf08e521f4c08f85d1c44 |
|
MD5 | b9f7030a53afb1fe62a8d0e735f39b52 |
|
BLAKE2b-256 | 831c20970cad5e4e420d4cf6f61e50827a96e5a84aae54a01686a7ec739620ce |
File details
Details for the file fastapi_swagger-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: fastapi_swagger-0.2.0-py3-none-any.whl
- Upload date:
- Size: 432.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 425e450646302b1a1507bfae445170efbab518db7932e59e2c23b40db0aa683e |
|
MD5 | 2c395f4fb9dce41c8f6eae556a466323 |
|
BLAKE2b-256 | eb311de6a2fe75139a8caf684dc47402a307bfb4cd6875a2aa053c71df0ba67d |