Merge branch 'master' into refactor_get_openapi_path

This commit is contained in:
Simon-Huang-1 2025-12-09 18:41:55 +01:00 committed by GitHub
commit 59173d697c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 56 additions and 0 deletions

View File

@ -11,6 +11,10 @@ hide:
* 📝 Update tech stack in project generation docs. PR [#14472](https://github.com/fastapi/fastapi/pull/14472) by [@alejsdev](https://github.com/alejsdev).
### Internal
* ✅ Add test for Pydantic v2, dataclasses, UUID, and `__annotations__`. PR [#14477](https://github.com/fastapi/fastapi/pull/14477) by [@tiangolo](https://github.com/tiangolo).
## 0.124.0
### Features

View File

@ -0,0 +1,52 @@
from __future__ import annotations
import uuid
from dataclasses import dataclass, field
from typing import List, Union
from dirty_equals import IsUUID
from fastapi import FastAPI
from fastapi.testclient import TestClient
from inline_snapshot import snapshot
@dataclass
class Item:
id: uuid.UUID
name: str
price: float
tags: List[str] = field(default_factory=list)
description: Union[str, None] = None
tax: Union[float, None] = None
app = FastAPI()
@app.get("/item", response_model=Item)
async def read_item():
return {
"id": uuid.uuid4(),
"name": "Island In The Moon",
"price": 12.99,
"description": "A place to be be playin' and havin' fun",
"tags": ["breater"],
}
client = TestClient(app)
def test_annotations():
response = client.get("/item")
assert response.status_code == 200, response.text
assert response.json() == snapshot(
{
"id": IsUUID(),
"name": "Island In The Moon",
"price": 12.99,
"tags": ["breater"],
"description": "A place to be be playin' and havin' fun",
"tax": None,
}
)