Created
March 12, 2023 08:52
-
-
Save wiseaidev/87943b4171ae69b3ca4155d9f2d7c56a to your computer and use it in GitHub Desktop.
A simple script to to change default fastapi JWT Auth schema.
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
from fastapi import ( | |
FastAPI, | |
) | |
from fastapi.openapi.utils import ( | |
get_openapi, | |
) | |
from typing import ( | |
Any, | |
) | |
app = FastAPI( | |
docs_url="/docs", | |
redoc_url="/redocs", | |
title="FastAPI Server", | |
description="FastAPI's server.", | |
version="3.0", | |
openapi_url="/api/v3/openapi.json", | |
) | |
def custom_openapi() -> any: | |
if app.openapi_schema: | |
return app.openapi_schema | |
openapi_schema = get_openapi( | |
title="FastAPI Server", | |
version="3.0", | |
routes=app.routes, | |
) | |
openapi_schema["components"]["securitySchemes"]["JWT"]["type"] = "http" | |
openapi_schema["components"]["securitySchemes"]["JWT"]["scheme"] = "bearer" | |
app.openapi_schema = openapi_schema | |
return app.openapi_schema | |
app.openapi = custom_openapi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment