Skip to content

↔ 🗄

Warning

👉 👍 🏧 ⚒. 👆 🎲 💪 🚶 ⚫️.

🚥 👆 📄 🔰 - 👩‍💻 🦮, 👆 💪 🎲 🚶 👉 📄.

🚥 👆 ⏪ 💭 👈 👆 💪 🔀 🏗 🗄 🔗, 😣 👂.

📤 💼 🌐❔ 👆 💪 💪 🔀 🏗 🗄 🔗.

👉 📄 👆 🔜 👀 ❔.

😐 🛠️

😐 (🔢) 🛠️, ⏩.

FastAPI 🈸 (👐) ✔️ .openapi() 👩‍🔬 👈 📈 📨 🗄 🔗.

🍕 🈸 🎚 🏗, ➡ 🛠️ /openapi.json (⚖️ ⚫️❔ 👆 ⚒ 👆 openapi_url) ®.

⚫️ 📨 🎻 📨 ⏮️ 🏁 🈸 .openapi() 👩‍🔬.

🔢, ⚫️❔ 👩‍🔬 .openapi() 🔨 ✅ 🏠 .openapi_schema 👀 🚥 ⚫️ ✔️ 🎚 & 📨 👫.

🚥 ⚫️ 🚫, ⚫️ 🏗 👫 ⚙️ 🚙 🔢 fastapi.openapi.utils.get_openapi.

& 👈 🔢 get_openapi() 📨 🔢:

  • title: 🗄 📛, 🎦 🩺.
  • version: ⏬ 👆 🛠️, ✅ 2.5.0.
  • openapi_version: ⏬ 🗄 🔧 ⚙️. 🔢, ⏪: 3.0.2.
  • description: 📛 👆 🛠️.
  • routes: 📇 🛣, 👫 🔠 ® ➡ 🛠️. 👫 ✊ ⚪️➡️ app.routes.

🔑 🔢

⚙️ ℹ 🔛, 👆 💪 ⚙️ 🎏 🚙 🔢 🏗 🗄 🔗 & 🔐 🔠 🍕 👈 👆 💪.

🖼, ➡️ 🚮 📄 🗄 ↔ 🔌 🛃 🔱.

😐 FastAPI

🥇, ✍ 🌐 👆 FastAPI 🈸 🛎:

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",
        summary="This is a very custom OpenAPI schema",
        description="Here's a longer description of the 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

🏗 🗄 🔗

⤴️, ⚙️ 🎏 🚙 🔢 🏗 🗄 🔗, 🔘 custom_openapi() 🔢:

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",
        summary="This is a very custom OpenAPI schema",
        description="Here's a longer description of the 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

🔀 🗄 🔗

🔜 👆 💪 🚮 📄 ↔, ❎ 🛃 x-logo info "🎚" 🗄 🔗:

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",
        summary="This is a very custom OpenAPI schema",
        description="Here's a longer description of the 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

💾 🗄 🔗

👆 💪 ⚙️ 🏠 .openapi_schema "💾", 🏪 👆 🏗 🔗.

👈 🌌, 👆 🈸 🏆 🚫 ✔️ 🏗 🔗 🔠 🕰 👩‍💻 📂 👆 🛠️ 🩺.

⚫️ 🔜 🏗 🕴 🕐, & ⤴️ 🎏 💾 🔗 🔜 ⚙️ ⏭ 📨.

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",
        summary="This is a very custom OpenAPI schema",
        description="Here's a longer description of the 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

🔐 👩‍🔬

🔜 👆 💪 ❎ .openapi() 👩‍🔬 ⏮️ 👆 🆕 🔢.

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",
        summary="This is a very custom OpenAPI schema",
        description="Here's a longer description of the 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

✅ ⚫️

🕐 👆 🚶 http://127.0.0.1:8000/redoc 👆 🔜 👀 👈 👆 ⚙️ 👆 🛃 🔱 (👉 🖼, FastAPI'Ⓜ 🔱):