You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

9.5 KiB

↔ 🗄

!!! 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 🈸 🛎:

{!../../../docs_src/extending_openapi/tutorial001.py!}

🏗 🗄 🔗

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

{!../../../docs_src/extending_openapi/tutorial001.py!}

🔀 🗄 🔗

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

{!../../../docs_src/extending_openapi/tutorial001.py!}

💾 🗄 🔗

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

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

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

{!../../../docs_src/extending_openapi/tutorial001.py!}

🔐 👩‍🔬

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

{!../../../docs_src/extending_openapi/tutorial001.py!}

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

👤-🕸 🕸 & 🎚 🩺

🛠️ 🩺 ⚙️ 🦁 🎚 & 📄, & 🔠 👈 💪 🕸 & 🎚 📁.

🔢, 👈 📁 🍦 ➡️ 💲.

💪 🛃 ️, 👆 💪🎯 💲, ⚖️ 🍦 📁 👆.

👈 ⚠, 🖼, 🚥 👆 💪 👆 📱 🚧 👷 📱, 🍵 📂 🕸 🔐, ⚖️ 🇧🇿 🕸.

📥 👆 🔜 👀 🍦 👈 📁 👆, 🎏 FastAPI 📱, & 🔗 🩺 ⚙️ 👫.

🏗 📁 📊

➡️ 💬 👆 🏗 📁 📊 👀 💖 👉:

.
├── app
│   ├── __init__.py
│   ├── main.py

🔜📁 🏪 📚 🎻 📁.

👆 🆕 📁 📊 💪 👀 💖 👉:

.
├── app
│   ├── __init__.py
│   ├── main.py
└── static/

📁

🎻 📁 💪 🩺 & 🚮 👫 🔛 👈 static/ 📁.

👆 💪 🎲 ▶️️-🖊 🔠 🔗 & 🖊 🎛 🎏 Save link as....

🦁 🎚 ⚙️ 📁:

& 📄 ⚙️ 📁:

⏮️ 👈, 👆 📁 📊 💪 👀 💖:

.
├── app
│   ├── __init__.py
│   ├── main.py
└── static
    ├── redoc.standalone.js
    ├── swagger-ui-bundle.js
    └── swagger-ui.css

🍦 🎻 📁

  • 🗄 StaticFiles.
  • "🗻" StaticFiles() 👐 🎯 ➡.
{!../../../docs_src/extending_openapi/tutorial002.py!}

💯 🎻 📁

▶️ 👆 🈸 & 🚶 http://127.0.0.1:8000/static/redoc.standalone.js.

👆 🔜 👀 📶 📏 🕸 📁 📄.

💪 ▶️ ⏮️ 🕳 💖:

/*!
 * ReDoc - OpenAPI/Swagger-generated API Reference Documentation
 * -------------------------------------------------------------
 *   Version: "2.0.0-rc.18"
 *   Repo: https://github.com/Redocly/redoc
 */
!function(e,t){"object"==typeof exports&&"object"==typeof m

...

👈👈 👆 💆‍♂ 💪 🍦 🎻 📁 ➡️ 👆 📱, & 👈 👆 🥉 🎻 📁 🩺🥉.

🔜 👥 💪 🔗 📱 ⚙️ 📚 🎻 📁 🩺.

🏧 🩺

🥇 🔁 🏧 🩺, 📚 ⚙️ 💲 🔢.

👫, ⚒ 👫 📛 None 🕐 🏗 👆 FastAPI 📱:

{!../../../docs_src/extending_openapi/tutorial002.py!}

🔌 🛃 🩺

🔜 👆 💪🛠️ 🛃 🩺.

👆 💪 🏤-⚙️ FastAPI 🔗 🔢 ✍ 🕸 📃 🩺, & 🚶‍♀️ 👫 💪 :

  • openapi_url: 📛 🌐 🕸 📃 🩺 💪 🤚 🗄 🔗 👆 🛠️. 👆 💪 ⚙️ 📥 🔢 app.openapi_url.
  • title: 📛 👆 🛠️.
  • oauth2_redirect_url: 👆 💪 ⚙️ app.swagger_ui_oauth2_redirect_url 📥 ⚙️ 🔢.
  • swagger_js_url: 📛 🌐 🕸 👆 🦁 🎚 🩺 💪 🤚 🕸 📁. 👉 1️⃣ 👈 👆 👍 📱 🔜 🍦.
  • swagger_css_url: 📛 🌐 🕸 👆 🦁 🎚 🩺 💪 🤚 🎚 📁. 👉 1️⃣ 👈 👆 👍 📱 🔜 🍦.

& ➡ 📄...

{!../../../docs_src/extending_openapi/tutorial002.py!}

!!! tip 🛠️ swagger_ui_redirect 👩‍🎓 🕐 👆 ⚙️ Oauth2️⃣.

🚥 👆 🛠️ 👆 🛠️ ⏮️ Oauth2️⃣ 🐕‍🦺, 👆 🔜 💪 🔓 & 👟 🔙 🛠️ 🩺 ⏮️ 📎 🎓. & 🔗 ⏮️ ⚫️ ⚙️ 🎰 Oauth2️⃣ 🤝.

🦁 🎚 🔜 🍵 ⚫️ ⛅ 🎑 👆, ✋️ ⚫️ 💪 👉 "❎" 👩‍🎓.

🛠️ 💯

🔜, 💪 💯 👈 🌐 👷, ✍ 🛠️:

{!../../../docs_src/extending_openapi/tutorial002.py!}

💯

🔜, 👆 🔜 💪 🔌 👆 📻, 🚶 👆 🩺 http://127.0.0.1:8000/docs, & 🔃 📃.

& 🍵 🕸, 👆 🔜 💪 👀 🩺 👆 🛠️ & 🔗 ⏮️ ️.

🛠️ 🦁 🎚

👆 💪 🔗 🦁 🎚 🔢.

🔗 👫, 🚶‍♀️ swagger_ui_parameters 🕐 🏗 FastAPI() 📱 🎚 ⚖️ get_swagger_ui_html() 🔢.

swagger_ui_parameters 📨 📖 ⏮️ 📳 🚶‍♀️ 🦁 🎚 🔗.

FastAPI 🗜 📳 🎻👫 🔗 ⏮️ 🕸, 👈 🦁 🎚 💪.

🎦

🖼, 👆 💪 🎦 🦁 🎚.

🍵 🔀 ⚒, 🎦 🛠️ 🔢:

👆 💪 ️ ⚒ syntaxHighlight False:

{!../../../docs_src/extending_openapi/tutorial003.py!}

...& ⤴️ 🦁 🎚 🏆 🚫 🎦 🎦 🚫🔜:

🔀 🎢

🎏 🌌 👆 💪 🎦 🎢 ⏮️ 🔑 "syntaxHighlight.theme" (👀 👈 ✔️🖕):

{!../../../docs_src/extending_openapi/tutorial004.py!}

👈 📳 🔜 🔀 🎦 🎨 🎢:

🔀 🔢 🦁 🎚 🔢

FastAPI 🔌 🔢 📳 🔢🌅 ⚙️ 💼.

🔌 👫 🔢 📳:

{!../../../fastapi/openapi/docs.py[ln:7-13]!}

👆 💪 🔐 🙆 👫🎏 💲 swagger_ui_parameters.

🖼, deepLinking 👆 💪 🚶‍♀️ 👉swagger_ui_parameters:

{!../../../docs_src/extending_openapi/tutorial005.py!}

🎏 🦁 🎚 🔢

👀 🌐 🎏 💪 📳 👆 💪 ⚙️, ✍ 🛂 🩺 🦁 🎚 🔢.

🕸-🕴 ⚒

🦁 🎚 ✔ 🎏 📳 🕸-🕴 🎚 (🖼, 🕸 🔢).

FastAPI 🔌 👫 🕸-🕴 presets ⚒:

presets: [
    SwaggerUIBundle.presets.apis,
    SwaggerUIBundle.SwaggerUIStandalonePreset
]

👫 🕸 🎚, 🚫 🎻, 👆 💪 🚫 🚶‍♀️ 👫 ➡️ 🐍 📟 🔗.

🚥 👆 💪 ⚙️ 🕸-🕴 📳 💖 📚, 👆 💪 ⚙️ 1️⃣ 👩‍🔬 🔛. 🔐 🌐 🦁 🎚 🛠️ & 🙆 🕸 👆 💪.