mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-31 10:10:51 -05:00
* 🌐 Refactor file structure to support internationalization * ✅ Update tests changed after i18n * 🔀 Merge Typer style from master * 🔧 Update MkConfig with Typer-styles * 🎨 Format mkdocs.yml with cannonical form * 🎨 Format mkdocs.yml * 🔧 Update MkDocs config * ➕ Add docs translation scripts dependencies * ✨ Add Typer scripts to handle translations * ✨ Add missing translation snippet to include * ✨ Update contributing docs, add docs for translations * 🙈 Add docs_build to gitignore * 🔧 Update scripts with new locations and docs scripts * 👷 Update docs deploy action with translations * 📝 Add note about languages not supported in the theme * ✨ Add first translation, for Spanish
36 lines
634 B
Python
36 lines
634 B
Python
from typing import Union
|
|
|
|
from fastapi import FastAPI
|
|
from pydantic import BaseModel
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
class BaseItem(BaseModel):
|
|
description: str
|
|
type: str
|
|
|
|
|
|
class CarItem(BaseItem):
|
|
type = "car"
|
|
|
|
|
|
class PlaneItem(BaseItem):
|
|
type = "plane"
|
|
size: int
|
|
|
|
|
|
items = {
|
|
"item1": {"description": "All my friends drive a low rider", "type": "car"},
|
|
"item2": {
|
|
"description": "Music is my aeroplane, it's my aeroplane",
|
|
"type": "plane",
|
|
"size": 5,
|
|
},
|
|
}
|
|
|
|
|
|
@app.get("/items/{item_id}", response_model=Union[PlaneItem, CarItem])
|
|
async def read_item(item_id: str):
|
|
return items[item_id]
|