8000 Prepare for pydantic 2.12.0 · cjwatson/fastapi@a9d228a · GitHub
[go: up one dir, main page]

Skip to content

Commit a9d228a

Browse files
committed
Prepare for pydantic 2.12.0
`tests/test_multi_body_errors.py::test_openapi_schema` failed with pydantic 2.12.0a1 due to pydantic/pydantic#11987. Since we're testing the exact contents of the JSON schema, the easiest fix seems to be to add version-dependent handling for this.
1 parent 3e2dbf9 commit a9d228a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

requirements-tests.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ PyJWT==2.8.0
1111
pyyaml >=5.3.1,<7.0.0
1212
passlib[bcrypt] >=1.7.2,<2.0.0
1313
inline-snapshot>=0.21.1
14+
packaging>=14.0
1415
# types
1516
types-ujson ==5.10.0.20240515
1617
types-orjson ==3.6.2

tests/test_multi_body_errors.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
from dirty_equals import IsDict, IsOneOf
55
from fastapi import FastAPI
66
from fastapi.testclient import TestClient
7+
from packaging.version import Version
78
from pydantic import BaseModel, condecimal
9+
from pydantic.version import VERSION as pydantic_version
810

911
app = FastAPI()
1012

@@ -131,6 +133,10 @@ def test_put_incorrect_body_multiple():
131133

132134

133135
def test_openapi_schema():
136+
decimal_string_type = {"type": "string"}
137+
if Version(pydantic_version) >= Version("2.12.0a1"): # pragma: no cover
138+
decimal_string_type["pattern"] = r"^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$"
139+
134140
response = client.get("/openapi.json")
135141
assert response.status_code == 200, response.text
136142
assert response.json() == {
@@ -185,7 +191,7 @@ def test_openapi_schema():
185191
"title": "Age",
186192
"anyOf": [
187193
{"exclusiveMinimum": 0.0, "type": "number"},
188-
{"type": "string"},
194+
decimal_string_type,
189195
],
190196
}
191197
)

0 commit comments

Comments
 (0)
0