mirror of
https://github.com/fastapi/fastapi.git
synced 2026-04-16 12:57:44 -04:00
✨ Add support for disabling the separation of input and output JSON Schemas in OpenAPI with Pydantic v2 (#10145)
* 📝 Add docs for Separate OpenAPI Schemas for Input and Output * 🔧 Add new docs page to MkDocs config * ✨ Add separate_input_output_schemas parameter to FastAPI class * 📝 Add source examples for separating OpenAPI schemas * ✅ Add tests for separated OpenAPI schemas * 📝 Add source examples for Python 3.10, 3.9, and 3.7+ * 📝 Update docs for Separate OpenAPI Schemas with new multi-version examples * ✅ Add and update tests for different Python versions * ✅ Add tests for corner cases with separate_input_output_schemas * 📝 Update tutorial to use Union instead of Optional * 🐛 Fix type annotations * 🐛 Fix correct import in test * 💄 Add CSS to simulate browser windows for screenshots * ➕ Add playwright as a dev dependency to automate generating screenshots * 🔨 Add Playwright scripts to generate screenshots for new docs * 📝 Update docs, tweak text to match screenshots * 🍱 Add screenshots for new docs
This commit is contained in:
committed by
GitHub
parent
10a127ea4a
commit
ea43f227e5
29
scripts/playwright/separate_openapi_schemas/image01.py
Normal file
29
scripts/playwright/separate_openapi_schemas/image01.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import subprocess
|
||||
|
||||
from playwright.sync_api import Playwright, sync_playwright
|
||||
|
||||
|
||||
def run(playwright: Playwright) -> None:
|
||||
browser = playwright.chromium.launch(headless=False)
|
||||
context = browser.new_context(viewport={"width": 960, "height": 1080})
|
||||
page = context.new_page()
|
||||
page.goto("http://localhost:8000/docs")
|
||||
page.get_by_text("POST/items/Create Item").click()
|
||||
page.get_by_role("tab", name="Schema").first.click()
|
||||
page.screenshot(
|
||||
path="docs/en/docs/img/tutorial/separate-openapi-schemas/image01.png"
|
||||
)
|
||||
|
||||
# ---------------------
|
||||
context.close()
|
||||
browser.close()
|
||||
|
||||
|
||||
process = subprocess.Popen(
|
||||
["uvicorn", "docs_src.separate_openapi_schemas.tutorial001:app"]
|
||||
)
|
||||
try:
|
||||
with sync_playwright() as playwright:
|
||||
run(playwright)
|
||||
finally:
|
||||
process.terminate()
|
||||
30
scripts/playwright/separate_openapi_schemas/image02.py
Normal file
30
scripts/playwright/separate_openapi_schemas/image02.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import subprocess
|
||||
|
||||
from playwright.sync_api import Playwright, sync_playwright
|
||||
|
||||
|
||||
def run(playwright: Playwright) -> None:
|
||||
browser = playwright.chromium.launch(headless=False)
|
||||
context = browser.new_context(viewport={"width": 960, "height": 1080})
|
||||
page = context.new_page()
|
||||
page.goto("http://localhost:8000/docs")
|
||||
page.get_by_text("GET/items/Read Items").click()
|
||||
page.get_by_role("button", name="Try it out").click()
|
||||
page.get_by_role("button", name="Execute").click()
|
||||
page.screenshot(
|
||||
path="docs/en/docs/img/tutorial/separate-openapi-schemas/image02.png"
|
||||
)
|
||||
|
||||
# ---------------------
|
||||
context.close()
|
||||
browser.close()
|
||||
|
||||
|
||||
process = subprocess.Popen(
|
||||
["uvicorn", "docs_src.separate_openapi_schemas.tutorial001:app"]
|
||||
)
|
||||
try:
|
||||
with sync_playwright() as playwright:
|
||||
run(playwright)
|
||||
finally:
|
||||
process.terminate()
|
||||
30
scripts/playwright/separate_openapi_schemas/image03.py
Normal file
30
scripts/playwright/separate_openapi_schemas/image03.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import subprocess
|
||||
|
||||
from playwright.sync_api import Playwright, sync_playwright
|
||||
|
||||
|
||||
def run(playwright: Playwright) -> None:
|
||||
browser = playwright.chromium.launch(headless=False)
|
||||
context = browser.new_context(viewport={"width": 960, "height": 1080})
|
||||
page = context.new_page()
|
||||
page.goto("http://localhost:8000/docs")
|
||||
page.get_by_text("GET/items/Read Items").click()
|
||||
page.get_by_role("tab", name="Schema").click()
|
||||
page.get_by_label("Schema").get_by_role("button", name="Expand all").click()
|
||||
page.screenshot(
|
||||
path="docs/en/docs/img/tutorial/separate-openapi-schemas/image03.png"
|
||||
)
|
||||
|
||||
# ---------------------
|
||||
context.close()
|
||||
browser.close()
|
||||
|
||||
|
||||
process = subprocess.Popen(
|
||||
["uvicorn", "docs_src.separate_openapi_schemas.tutorial001:app"]
|
||||
)
|
||||
try:
|
||||
with sync_playwright() as playwright:
|
||||
run(playwright)
|
||||
finally:
|
||||
process.terminate()
|
||||
29
scripts/playwright/separate_openapi_schemas/image04.py
Normal file
29
scripts/playwright/separate_openapi_schemas/image04.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import subprocess
|
||||
|
||||
from playwright.sync_api import Playwright, sync_playwright
|
||||
|
||||
|
||||
def run(playwright: Playwright) -> None:
|
||||
browser = playwright.chromium.launch(headless=False)
|
||||
context = browser.new_context(viewport={"width": 960, "height": 1080})
|
||||
page = context.new_page()
|
||||
page.goto("http://localhost:8000/docs")
|
||||
page.get_by_role("button", name="Item-Input").click()
|
||||
page.get_by_role("button", name="Item-Output").click()
|
||||
page.set_viewport_size({"width": 960, "height": 820})
|
||||
page.screenshot(
|
||||
path="docs/en/docs/img/tutorial/separate-openapi-schemas/image04.png"
|
||||
)
|
||||
# ---------------------
|
||||
context.close()
|
||||
browser.close()
|
||||
|
||||
|
||||
process = subprocess.Popen(
|
||||
["uvicorn", "docs_src.separate_openapi_schemas.tutorial001:app"]
|
||||
)
|
||||
try:
|
||||
with sync_playwright() as playwright:
|
||||
run(playwright)
|
||||
finally:
|
||||
process.terminate()
|
||||
29
scripts/playwright/separate_openapi_schemas/image05.py
Normal file
29
scripts/playwright/separate_openapi_schemas/image05.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import subprocess
|
||||
|
||||
from playwright.sync_api import Playwright, sync_playwright
|
||||
|
||||
|
||||
def run(playwright: Playwright) -> None:
|
||||
browser = playwright.chromium.launch(headless=False)
|
||||
context = browser.new_context(viewport={"width": 960, "height": 1080})
|
||||
page = context.new_page()
|
||||
page.goto("http://localhost:8000/docs")
|
||||
page.get_by_role("button", name="Item", exact=True).click()
|
||||
page.set_viewport_size({"width": 960, "height": 700})
|
||||
page.screenshot(
|
||||
path="docs/en/docs/img/tutorial/separate-openapi-schemas/image05.png"
|
||||
)
|
||||
|
||||
# ---------------------
|
||||
context.close()
|
||||
browser.close()
|
||||
|
||||
|
||||
process = subprocess.Popen(
|
||||
["uvicorn", "docs_src.separate_openapi_schemas.tutorial002:app"]
|
||||
)
|
||||
try:
|
||||
with sync_playwright() as playwright:
|
||||
run(playwright)
|
||||
finally:
|
||||
process.terminate()
|
||||
Reference in New Issue
Block a user