Skip to content

Instantly share code, notes, and snippets.

@wiseaidev
Created March 12, 2023 08:52
Show Gist options
  • Save wiseaidev/87943b4171ae69b3ca4155d9f2d7c56a to your computer and use it in GitHub Desktop.
Save wiseaidev/87943b4171ae69b3ca4155d9f2d7c56a to your computer and use it in GitHub Desktop.
A simple script to to change default fastapi JWT Auth schema.
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