Skip to content

Commit b3c6e6b

Browse files
committed
Fix the rest of the issues from fastapi==0.119.0
1 parent 16a81cc commit b3c6e6b

File tree

5 files changed

+36
-35
lines changed

5 files changed

+36
-35
lines changed

cadwyn/changelogs.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
import sys
33
from enum import auto
44
from logging import getLogger
5-
from typing import TYPE_CHECKING, Any, Literal, TypeVar, Union, cast, get_args
5+
from typing import Any, Literal, TypeVar, Union, cast, get_args
66

7-
from fastapi.openapi.constants import REF_TEMPLATE
7+
from fastapi._compat import (
8+
get_compat_model_name_map,
9+
get_definitions,
10+
)
11+
from fastapi._compat.v2 import ModelField
812
from fastapi.openapi.utils import (
913
get_fields_from_routes,
1014
get_openapi,
@@ -35,9 +39,6 @@
3539
ValidatorExistedInstruction,
3640
)
3741

38-
if TYPE_CHECKING:
39-
from fastapi._compat import ModelField
40-
4142
if sys.version_info >= (3, 11): # pragma: no cover
4243
from enum import StrEnum
4344
else: # pragma: no cover
@@ -89,7 +90,7 @@ def _generate_changelog(versions: VersionBundle, router: _RootCadwynAPIRouter) -
8990
version_change,
9091
generator_from_newer_version,
9192
generator_from_older_version,
92-
schemas_from_older_version,
93+
schemas_from_older_version, # pyright: ignore[reportArgumentType]
9394
cast("list[APIRoute]", routes_from_newer_version),
9495
)
9596
if changelog_entry is not None: # pragma: no branch # This should never happen
@@ -153,21 +154,22 @@ def _get_all_pydantic_models_from_generic(annotation: Any) -> list[type[BaseMode
153154

154155

155156
def _get_openapi_representation_of_a_field(model: type[BaseModel], field_name: str) -> dict:
156-
from fastapi._compat import (
157-
GenerateJsonSchema,
158-
ModelField,
159-
get_compat_model_name_map,
160-
get_definitions,
161-
)
162-
163157
class CadwynDummyModelForRepresentation(BaseModel):
164158
my_field: model
165159

166-
model_name_map = get_compat_model_name_map([CadwynDummyModelForRepresentation.model_fields["my_field"]])
167-
schema_generator = GenerateJsonSchema(ref_template=REF_TEMPLATE)
160+
model_name_map = get_compat_model_name_map(
161+
[
162+
CadwynDummyModelForRepresentation.model_fields["my_field"], # pyright: ignore[reportArgumentType]
163+
]
164+
)
165+
168166
_, definitions = get_definitions(
169-
fields=[ModelField(CadwynDummyModelForRepresentation.model_fields["my_field"], "my_field")],
170-
schema_generator=schema_generator,
167+
fields=[
168+
ModelField(
169+
CadwynDummyModelForRepresentation.model_fields["my_field"],
170+
"my_field",
171+
), # pyright: ignore[reportArgumentType]
172+
],
171173
model_name_map=model_name_map,
172174
separate_input_output_schemas=False,
173175
)

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "cadwyn"
3-
version = "5.4.5"
3+
version = "5.5.0"
44
description = "Production-ready community-driven modern Stripe-like API versioning in FastAPI"
55
authors = [{ name = "Stanislav Zmiev", email = "[email protected]" }]
66
license = "MIT"
@@ -51,7 +51,7 @@ classifiers = [
5151
"Topic :: Internet :: WWW/HTTP",
5252
]
5353
dependencies = [
54-
"fastapi >=0.112.4",
54+
"fastapi >=0.119.0",
5555
"starlette >=0.30.0",
5656
"pydantic >=2.11.0",
5757
"jinja2 >=3.1.2",
@@ -62,7 +62,7 @@ dependencies = [
6262

6363

6464
[project.optional-dependencies]
65-
standard = ["fastapi[standard]>=0.112.3", "typer>=0.7.0"]
65+
standard = ["fastapi[standard]>=0.119.0", "typer>=0.7.0"]
6666

6767
[tool.uv]
6868
dev-dependencies = [

tests/test_render.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
from tests.test_cli import code
1111

1212

13-
# TODO: Return this test once https://github.com/pydantic/pydantic/pull/11898 is merged
14-
@pytest.mark.xfail
1513
def test__render_model__with_weird_types():
1614
result = render_model_by_path(
1715
"tests._resources.render.complex.classes:ModelWithWeirdFields",

tests/test_schema_generation/test_schema_field.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,17 @@ class ExpectedSchema(BaseModel):
6868

6969

7070
def test__field_existed_as__extras_are_added(create_runtime_schemas: CreateRuntimeSchemas):
71-
schemas = create_runtime_schemas(
72-
version_change(
73-
schema(EmptySchema)
74-
.field("foo")
75-
.existed_as(
76-
type=int,
77-
info=Field(deflolbtt="hewwo"), # pyright: ignore[reportCallIssue]
78-
),
71+
with pytest.warns(DeprecationWarning):
72+
schemas = create_runtime_schemas(
73+
version_change(
74+
schema(EmptySchema)
75+
.field("foo")
76+
.existed_as(
77+
type=int,
78+
info=Field(deflolbtt="hewwo"), # pyright: ignore[reportCallIssue]
79+
),
80+
)
7981
)
80-
)
8182

8283
class ExpectedSchema(BaseModel):
8384
foo: int = Field(json_schema_extra={"deflolbtt": "hewwo"})
@@ -266,7 +267,7 @@ class SchemaWithOneDecimalField(BaseModel):
266267

267268
@pytest.mark.parametrize(
268269
("attr", "attr_value"),
269-
[("exclude", [16, 17, 18])],
270+
[("exclude", True)],
270271
)
271272
def test__schema_field_had__list_of_int_field(attr: str, attr_value: Any, create_runtime_schemas: CreateRuntimeSchemas):
272273
class SchemaWithOneListOfIntField(BaseModel):

uv.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)