mirror of
https://github.com/fastapi/fastapi.git
synced 2026-01-18 02:49:51 -05:00
* ➕ Add pydantic-settings to all extras * 📝 Update docs for Pydantic settings * 📝 Update Settings source examples to use Pydantic v2, and add a Pydantic v1 version * ✅ Add tests for settings with Pydantic v1 and v2 * 🔥 Remove solved TODO comment * ♻️ Update conditional OpenAPI to use new Pydantic v2 settings
17 lines
281 B
Python
17 lines
281 B
Python
from fastapi import FastAPI
|
|
from pydantic_settings import BaseSettings
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
openapi_url: str = "/openapi.json"
|
|
|
|
|
|
settings = Settings()
|
|
|
|
app = FastAPI(openapi_url=settings.openapi_url)
|
|
|
|
|
|
@app.get("/")
|
|
def root():
|
|
return {"message": "Hello World"}
|