mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-30 09:39:20 -05:00
* root_path included in servers object instead of path prefix * ♻️ Refactor implementation of auto-including root_path in OpenAPI servers * 📝 Update docs and examples for Behind a Proxy, including servers * 📝 Update Extending OpenAPI as openapi_prefix is no longer needed * ✅ Add extra tests for root_path in servers and root_path_in_servers=False * 🍱 Update security docs images with relative token URL * 📝 Update security docs with relative token URL * 📝 Update example sources with relative token URLs * ✅ Update tests with relative tokens Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
29 lines
657 B
Python
29 lines
657 B
Python
from fastapi import FastAPI
|
|
from fastapi.openapi.utils import get_openapi
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
@app.get("/items/")
|
|
async def read_items():
|
|
return [{"name": "Foo"}]
|
|
|
|
|
|
def custom_openapi():
|
|
if app.openapi_schema:
|
|
return app.openapi_schema
|
|
openapi_schema = get_openapi(
|
|
title="Custom title",
|
|
version="2.5.0",
|
|
description="This is a very custom OpenAPI schema",
|
|
routes=app.routes,
|
|
)
|
|
openapi_schema["info"]["x-logo"] = {
|
|
"url": "https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png"
|
|
}
|
|
app.openapi_schema = openapi_schema
|
|
return app.openapi_schema
|
|
|
|
|
|
app.openapi = custom_openapi
|