cadwyn 4.5.0__tar.gz → 4.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cadwyn might be problematic. Click here for more details.
- {cadwyn-4.5.0 → cadwyn-4.6.0}/.github/workflows/ci.yaml +10 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/CHANGELOG.md +8 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/PKG-INFO +1 -1
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/applications.py +2 -2
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/schema_generation.py +36 -4
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/structure/schemas.py +64 -15
- {cadwyn-4.5.0 → cadwyn-4.6.0}/pyproject.toml +1 -1
- cadwyn-4.6.0/tests/test_router_generation_with_from_future_annotations.py +62 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/uv.lock +218 -217
- cadwyn-4.5.0/.github/workflows/validate_links.yaml +0 -25
- {cadwyn-4.5.0 → cadwyn-4.6.0}/.github/CODE_OF_CONDUCT.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/.github/actions/setup-python-uv/action.yaml +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/.github/workflows/daily_tests.yaml +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/.github/workflows/publish_docs.yaml +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/.github/workflows/release.yaml +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/.gitignore +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/.pre-commit-config.yaml +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/LICENSE +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/Makefile +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/README.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/__main__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/_asts.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/_importer.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/_render.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/_utils.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/changelogs.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/exceptions.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/middleware.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/py.typed +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/route_generation.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/routing.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/static/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/static/docs.html +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/structure/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/structure/common.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/structure/data.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/structure/endpoints.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/structure/enums.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/cadwyn/structure/versions.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/CNAME +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/concepts/api_version_header_and_context_variables.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/concepts/beware_of_data_versioning.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/concepts/changelogs.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/concepts/cli.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/concepts/endpoint_migrations.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/concepts/enum_migrations.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/concepts/index.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/concepts/main_app.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/concepts/methodology.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/concepts/schema_generation.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/concepts/schema_migrations.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/concepts/testing.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/concepts/version_changes.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/home/CONTRIBUTING.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/how_to/change_business_logic/index.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/how_to/change_endpoints/index.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/how_to/change_openapi_schemas/add_field.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/how_to/change_openapi_schemas/change_field_type.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/how_to/change_openapi_schemas/change_schema_without_endpoint.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/how_to/change_openapi_schemas/changing_constraints.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/how_to/change_openapi_schemas/remove_field.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/how_to/change_openapi_schemas/rename_a_field_in_schema.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/how_to/index.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/img/dashboard_with_one_version.png +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/img/dashboard_with_two_versions.png +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/img/get_users_endpoint_from_prior_version.png +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/img/simplified_migration_model.png +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/img/sponsor_logos/monite.png +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/img/unversioned_dashboard.png +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/index.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/plugin.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/quickstart/setup.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/quickstart/tutorial.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/theory/how_to_build_versioning_framework.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/theory/how_we_got_here.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs/theory/literature.md +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/how_to/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/how_to/change_openapi_schemas/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/how_to/change_openapi_schemas/change_schema_without_endpoint/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/how_to/change_openapi_schemas/change_schema_without_endpoint/block001.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/how_to/change_openapi_schemas/change_schema_without_endpoint/block002.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/how_to/change_openapi_schemas/change_schema_without_endpoint/tests/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/how_to/change_openapi_schemas/change_schema_without_endpoint/tests/test_block001.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/how_to/change_openapi_schemas/change_schema_without_endpoint/tests/test_block002.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/quickstart/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/quickstart/setup/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/quickstart/setup/block001.sh +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/quickstart/setup/block002.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/quickstart/setup/tests/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/quickstart/setup/tests/test_block002.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/quickstart/tutorial/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/quickstart/tutorial/block001.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/quickstart/tutorial/block002.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/quickstart/tutorial/block003.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/quickstart/tutorial/tests/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/quickstart/tutorial/tests/test_block001.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/quickstart/tutorial/tests/test_block002.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/docs_src/quickstart/tutorial/tests/test_block003.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/mkdocs.yml +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/ruff.toml +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/scripts/fix_links.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/scripts/split_md.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/_data/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/_data/unversioned_schema_dir/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/_data/unversioned_schema_dir/unversioned_schemas.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/_data/unversioned_schemas.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/_resources/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/_resources/app_for_testing_routing.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/_resources/render/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/_resources/render/classes.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/_resources/render/complex/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/_resources/render/complex/classes.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/_resources/render/complex/versions.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/_resources/render/versions.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/_resources/utils.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/_resources/versioned_app/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/_resources/versioned_app/app.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/_resources/versioned_app/v2021_01_01.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/_resources/versioned_app/v2022_01_02.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/_resources/versioned_app/webhooks.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/conftest.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/test_applications.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/test_auth_dependencies.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/test_changelog.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/test_cli.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/test_data_migrations.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/test_render.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/test_router_generation.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/test_routing.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/test_schema_generation/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/test_schema_generation/test_enum.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/test_schema_generation/test_schema.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/test_schema_generation/test_schema_field.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/test_schema_generation/test_schema_validator.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/test_structure.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/tutorial/__init__.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/tutorial/main.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tests/tutorial/test_example.py +0 -0
- {cadwyn-4.5.0 → cadwyn-4.6.0}/tox.ini +0 -0
|
@@ -102,6 +102,16 @@ jobs:
|
|
|
102
102
|
python -m pip install uv
|
|
103
103
|
uv pip install --system pre-commit pre-commit-uv
|
|
104
104
|
pre-commit run --all-files
|
|
105
|
+
|
|
106
|
+
Validate-links:
|
|
107
|
+
runs-on: ubuntu-latest
|
|
108
|
+
steps:
|
|
109
|
+
- uses: actions/checkout@v4
|
|
110
|
+
- uses: ./.github/actions/setup-python-uv
|
|
111
|
+
with:
|
|
112
|
+
# When this version is updated,
|
|
113
|
+
# update the pyright `base_python` version in `tox.ini`, too.
|
|
114
|
+
python-version: "3.10"
|
|
105
115
|
- run: tox run -e docs
|
|
106
116
|
- name: Validate links
|
|
107
117
|
uses: umbrelladocs/action-linkspector@v1
|
|
@@ -5,6 +5,14 @@ Please follow [the Keep a Changelog standard](https://keepachangelog.com/en/1.0.
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased]
|
|
7
7
|
|
|
8
|
+
## [4.6.0]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
* Support for more field attributes in `schema.had()` and `schema.didnt_have()`: `field_title_generator`, `fail_fast`, `coerce_numbers_to_str`, `union_mode`, `allow_mutation`, `pattern`, `discriminator`
|
|
13
|
+
* Support for forwardrefs in body fields (for example, when you use `from __future__ import annotations` in the file with your routes)
|
|
14
|
+
* Support for forwardrefs in route dependencies
|
|
15
|
+
|
|
8
16
|
## [4.5.0]
|
|
9
17
|
|
|
10
18
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cadwyn
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.6.0
|
|
4
4
|
Summary: Production-ready community-driven modern Stripe-like API versioning in FastAPI
|
|
5
5
|
Project-URL: Source code, https://github.com/zmievsa/cadwyn
|
|
6
6
|
Project-URL: Documentation, https://docs.cadwyn.dev
|
|
@@ -279,7 +279,7 @@ class Cadwyn(FastAPI):
|
|
|
279
279
|
except (ValueError, TypeError):
|
|
280
280
|
version = raw_version
|
|
281
281
|
|
|
282
|
-
if version in self.router.versioned_routers:
|
|
282
|
+
if isinstance(version, date) and version in self.router.versioned_routers:
|
|
283
283
|
routes = self.router.versioned_routers[version].routes
|
|
284
284
|
formatted_version = version.isoformat()
|
|
285
285
|
elif version == "unversioned" and self._there_are_public_unversioned_routes():
|
|
@@ -296,7 +296,7 @@ class Cadwyn(FastAPI):
|
|
|
296
296
|
self.servers.insert(0, {"url": root_path})
|
|
297
297
|
|
|
298
298
|
webhook_routes = None
|
|
299
|
-
if version in self._versioned_webhook_routers:
|
|
299
|
+
if isinstance(version, date) and version in self._versioned_webhook_routers:
|
|
300
300
|
webhook_routes = self._versioned_webhook_routers[version].routes
|
|
301
301
|
|
|
302
302
|
return JSONResponse(
|
|
@@ -40,6 +40,7 @@ from pydantic._internal._decorators import (
|
|
|
40
40
|
RootValidatorDecoratorInfo,
|
|
41
41
|
ValidatorDecoratorInfo,
|
|
42
42
|
)
|
|
43
|
+
from pydantic._internal._typing_extra import try_eval_type as pydantic_try_eval_type
|
|
43
44
|
from pydantic.fields import ComputedFieldInfo, FieldInfo
|
|
44
45
|
from typing_extensions import Doc, Self, _AnnotatedAlias, assert_never
|
|
45
46
|
|
|
@@ -231,6 +232,12 @@ def _is_dunder(attr_name: str):
|
|
|
231
232
|
|
|
232
233
|
|
|
233
234
|
def _wrap_pydantic_model(model: type[_T_PYDANTIC_MODEL]) -> "_PydanticModelWrapper[_T_PYDANTIC_MODEL]":
|
|
235
|
+
# In case we have a forwardref within one of the fields
|
|
236
|
+
# For example, when "from __future__ import annotations" is used in the file with the schema
|
|
237
|
+
if model is not BaseModel:
|
|
238
|
+
model.model_rebuild(raise_errors=False)
|
|
239
|
+
model = cast(type[_T_PYDANTIC_MODEL], model)
|
|
240
|
+
|
|
234
241
|
decorators = _get_model_decorators(model)
|
|
235
242
|
validators = {}
|
|
236
243
|
for decorator_wrapper in decorators:
|
|
@@ -239,8 +246,20 @@ def _wrap_pydantic_model(model: type[_T_PYDANTIC_MODEL]) -> "_PydanticModelWrapp
|
|
|
239
246
|
|
|
240
247
|
wrapped_validator = _wrap_validator(decorator_wrapper.func, decorator_wrapper.shim, decorator_wrapper.info)
|
|
241
248
|
validators[decorator_wrapper.cls_var_name] = wrapped_validator
|
|
249
|
+
|
|
250
|
+
annotations = {
|
|
251
|
+
name: value
|
|
252
|
+
if not isinstance(value, str)
|
|
253
|
+
else model.model_fields[name].annotation or model.__annotations__[name]
|
|
254
|
+
for name, value in model.__annotations__.items()
|
|
255
|
+
}
|
|
256
|
+
|
|
242
257
|
fields = {
|
|
243
|
-
field_name: PydanticFieldWrapper(
|
|
258
|
+
field_name: PydanticFieldWrapper(
|
|
259
|
+
model.model_fields[field_name],
|
|
260
|
+
annotations[field_name],
|
|
261
|
+
field_name,
|
|
262
|
+
)
|
|
244
263
|
for field_name in model.__annotations__
|
|
245
264
|
}
|
|
246
265
|
|
|
@@ -263,7 +282,7 @@ def _wrap_pydantic_model(model: type[_T_PYDANTIC_MODEL]) -> "_PydanticModelWrapp
|
|
|
263
282
|
fields=fields,
|
|
264
283
|
other_attributes=other_attributes,
|
|
265
284
|
validators=validators,
|
|
266
|
-
annotations=
|
|
285
|
+
annotations=annotations,
|
|
267
286
|
)
|
|
268
287
|
|
|
269
288
|
|
|
@@ -355,6 +374,7 @@ class _PydanticModelWrapper(Generic[_T_PYDANTIC_MODEL]):
|
|
|
355
374
|
if not validator.is_deleted and type(validator) == _ValidatorWrapper # noqa: E721
|
|
356
375
|
}
|
|
357
376
|
fields = {name: field.generate_field_copy(generator) for name, field in self.fields.items()}
|
|
377
|
+
|
|
358
378
|
model_copy = type(self.cls)(
|
|
359
379
|
self.name,
|
|
360
380
|
tuple(generator[cast(type[BaseModel], base)] for base in self.cls.__bases__),
|
|
@@ -418,6 +438,7 @@ class _AnnotationTransformer:
|
|
|
418
438
|
# because such copies could produce weird behaviors at runtime, especially if you/fastapi do any comparisons.
|
|
419
439
|
# It's defined here and not on the method because of this: https://youtu.be/sVjtp6tGo0g
|
|
420
440
|
self.generator = generator
|
|
441
|
+
# TODO: Rewrite this to memoize
|
|
421
442
|
self.change_versions_of_a_non_container_annotation = functools.cache(
|
|
422
443
|
self._change_version_of_a_non_container_annotation
|
|
423
444
|
)
|
|
@@ -531,6 +552,9 @@ class _AnnotationTransformer:
|
|
|
531
552
|
annotation_modifying_wrapper = annotation_modifying_wrapper_factory(call)
|
|
532
553
|
old_params = inspect.signature(call).parameters
|
|
533
554
|
callable_annotations = annotation_modifying_wrapper.__annotations__
|
|
555
|
+
callable_annotations = {
|
|
556
|
+
k: v if type(v) is not str else _try_eval_type(v, call.__globals__) for k, v in callable_annotations.items()
|
|
557
|
+
}
|
|
534
558
|
annotation_modifying_wrapper.__annotations__ = modify_annotations(callable_annotations)
|
|
535
559
|
annotation_modifying_wrapper.__defaults__ = modify_defaults(
|
|
536
560
|
tuple(p.default for p in old_params.values() if p.default is not inspect.Signature.empty),
|
|
@@ -631,8 +655,6 @@ class SchemaGenerator:
|
|
|
631
655
|
|
|
632
656
|
if model in self.concrete_models:
|
|
633
657
|
return self.concrete_models[model]
|
|
634
|
-
else:
|
|
635
|
-
wrapper = self._get_wrapper_for_model(model)
|
|
636
658
|
|
|
637
659
|
wrapper = self._get_wrapper_for_model(model)
|
|
638
660
|
model_copy = wrapper.generate_model_copy(self)
|
|
@@ -655,6 +677,8 @@ class SchemaGenerator:
|
|
|
655
677
|
return self.model_bundle.enums[model]
|
|
656
678
|
|
|
657
679
|
if lenient_issubclass(model, BaseModel):
|
|
680
|
+
# TODO: My god, what if one of its fields is in our concrete schemas and we don't use it? :O
|
|
681
|
+
# TODO: Add an argument with our concrete schemas for _wrap_pydantic_model
|
|
658
682
|
wrapper = _wrap_pydantic_model(model)
|
|
659
683
|
self.model_bundle.schemas[model] = wrapper
|
|
660
684
|
elif lenient_issubclass(model, Enum):
|
|
@@ -977,3 +1001,11 @@ class _EnumWrapper(Generic[_T_ENUM]):
|
|
|
977
1001
|
and k not in _DummyEnum.__dict__
|
|
978
1002
|
and (k not in mro_dict or mro_dict[k] is not v)
|
|
979
1003
|
}
|
|
1004
|
+
|
|
1005
|
+
|
|
1006
|
+
def _try_eval_type(value: Any, globals: dict[str, Any]) -> Any:
|
|
1007
|
+
new_value, success = pydantic_try_eval_type(value, globals)
|
|
1008
|
+
if success:
|
|
1009
|
+
return new_value
|
|
1010
|
+
else: # pragma: no cover # Can't imagine when this would happen
|
|
1011
|
+
return value
|
|
@@ -3,7 +3,7 @@ from dataclasses import dataclass
|
|
|
3
3
|
from typing import TYPE_CHECKING, Any, Literal, cast
|
|
4
4
|
|
|
5
5
|
from issubclass import issubclass as lenient_issubclass
|
|
6
|
-
from pydantic import BaseModel, Field
|
|
6
|
+
from pydantic import AliasChoices, AliasPath, BaseModel, Field
|
|
7
7
|
from pydantic._internal._decorators import PydanticDescriptorProxy, unwrap_wrapped_function
|
|
8
8
|
from pydantic.fields import FieldInfo
|
|
9
9
|
|
|
@@ -18,58 +18,83 @@ if TYPE_CHECKING:
|
|
|
18
18
|
|
|
19
19
|
PossibleFieldAttributes = Literal[
|
|
20
20
|
"default",
|
|
21
|
-
"default_factory",
|
|
22
21
|
"alias",
|
|
22
|
+
"alias_priority",
|
|
23
|
+
"default_factory",
|
|
24
|
+
"validation_alias",
|
|
25
|
+
"serialization_alias",
|
|
23
26
|
"title",
|
|
27
|
+
"field_title_generator",
|
|
24
28
|
"description",
|
|
29
|
+
"examples",
|
|
25
30
|
"exclude",
|
|
26
31
|
"const",
|
|
32
|
+
"deprecated",
|
|
33
|
+
"frozen",
|
|
34
|
+
"validate_default",
|
|
35
|
+
"repr",
|
|
36
|
+
"init",
|
|
37
|
+
"init_var",
|
|
38
|
+
"kw_only",
|
|
39
|
+
"fail_fast",
|
|
27
40
|
"gt",
|
|
28
41
|
"ge",
|
|
29
42
|
"lt",
|
|
30
43
|
"le",
|
|
31
|
-
"deprecated",
|
|
32
|
-
"fail_fast",
|
|
33
44
|
"strict",
|
|
45
|
+
"coerce_numbers_to_str",
|
|
34
46
|
"multiple_of",
|
|
35
47
|
"allow_inf_nan",
|
|
36
48
|
"max_digits",
|
|
37
49
|
"decimal_places",
|
|
38
50
|
"min_length",
|
|
39
51
|
"max_length",
|
|
52
|
+
"union_mode",
|
|
40
53
|
"allow_mutation",
|
|
41
54
|
"pattern",
|
|
42
55
|
"discriminator",
|
|
43
|
-
"repr",
|
|
44
56
|
]
|
|
45
57
|
|
|
46
58
|
|
|
59
|
+
# TODO: Add json_schema_extra as a breaking change in a major version
|
|
47
60
|
@dataclass(slots=True)
|
|
48
61
|
class FieldChanges:
|
|
49
62
|
default: Any
|
|
63
|
+
alias: str | None
|
|
50
64
|
default_factory: Any
|
|
51
|
-
|
|
52
|
-
|
|
65
|
+
alias_priority: int | None
|
|
66
|
+
validation_alias: str | AliasPath | AliasChoices | None
|
|
67
|
+
serialization_alias: str | None
|
|
68
|
+
title: str | None
|
|
69
|
+
field_title_generator: Callable[[str, FieldInfo], str] | None
|
|
53
70
|
description: str
|
|
71
|
+
examples: list[Any] | None
|
|
54
72
|
exclude: "AbstractSetIntStr | MappingIntStrAny | Any"
|
|
55
73
|
const: bool
|
|
56
74
|
deprecated: bool
|
|
75
|
+
frozen: bool | None
|
|
76
|
+
validate_default: bool | None
|
|
77
|
+
repr: bool
|
|
78
|
+
init: bool | None
|
|
79
|
+
init_var: bool | None
|
|
80
|
+
kw_only: bool | None
|
|
57
81
|
fail_fast: bool
|
|
58
82
|
gt: float
|
|
59
83
|
ge: float
|
|
60
84
|
lt: float
|
|
61
85
|
le: float
|
|
62
86
|
strict: bool
|
|
87
|
+
coerce_numbers_to_str: bool | None
|
|
63
88
|
multiple_of: float
|
|
64
89
|
allow_inf_nan: bool
|
|
65
90
|
max_digits: int
|
|
66
91
|
decimal_places: int
|
|
67
92
|
min_length: int
|
|
68
93
|
max_length: int
|
|
94
|
+
union_mode: Literal["smart", "left_to_right"]
|
|
69
95
|
allow_mutation: bool
|
|
70
96
|
pattern: str
|
|
71
97
|
discriminator: str
|
|
72
|
-
repr: bool
|
|
73
98
|
|
|
74
99
|
|
|
75
100
|
@dataclass(slots=True)
|
|
@@ -113,29 +138,41 @@ class AlterFieldInstructionFactory:
|
|
|
113
138
|
name: str = Sentinel,
|
|
114
139
|
type: Any = Sentinel,
|
|
115
140
|
default: Any = Sentinel,
|
|
141
|
+
alias: str | None = Sentinel,
|
|
116
142
|
default_factory: Callable = Sentinel,
|
|
117
|
-
|
|
143
|
+
alias_priority: int = Sentinel,
|
|
144
|
+
validation_alias: str = Sentinel,
|
|
145
|
+
serialization_alias: str = Sentinel,
|
|
118
146
|
title: str = Sentinel,
|
|
147
|
+
field_title_generator: Callable[[str, FieldInfo], str] = Sentinel,
|
|
119
148
|
description: str = Sentinel,
|
|
149
|
+
examples: list[Any] = Sentinel,
|
|
120
150
|
exclude: "AbstractSetIntStr | MappingIntStrAny | Any" = Sentinel,
|
|
121
151
|
const: bool = Sentinel,
|
|
152
|
+
deprecated: bool = Sentinel,
|
|
153
|
+
frozen: bool = Sentinel,
|
|
154
|
+
validate_default: bool = Sentinel,
|
|
155
|
+
repr: bool = Sentinel,
|
|
156
|
+
init: bool = Sentinel,
|
|
157
|
+
init_var: bool = Sentinel,
|
|
158
|
+
kw_only: bool = Sentinel,
|
|
159
|
+
fail_fast: bool = Sentinel,
|
|
122
160
|
gt: float = Sentinel,
|
|
123
161
|
ge: float = Sentinel,
|
|
124
162
|
lt: float = Sentinel,
|
|
125
163
|
le: float = Sentinel,
|
|
126
164
|
strict: bool = Sentinel,
|
|
127
|
-
|
|
165
|
+
coerce_numbers_to_str: bool = Sentinel,
|
|
128
166
|
multiple_of: float = Sentinel,
|
|
129
167
|
allow_inf_nan: bool = Sentinel,
|
|
130
168
|
max_digits: int = Sentinel,
|
|
131
169
|
decimal_places: int = Sentinel,
|
|
132
170
|
min_length: int = Sentinel,
|
|
133
171
|
max_length: int = Sentinel,
|
|
172
|
+
union_mode: Literal["smart", "left_to_right"] = Sentinel,
|
|
134
173
|
allow_mutation: bool = Sentinel,
|
|
135
174
|
pattern: str = Sentinel,
|
|
136
175
|
discriminator: str = Sentinel,
|
|
137
|
-
repr: bool = Sentinel,
|
|
138
|
-
fail_fast: bool = Sentinel,
|
|
139
176
|
) -> FieldHadInstruction:
|
|
140
177
|
return FieldHadInstruction(
|
|
141
178
|
schema=self.schema,
|
|
@@ -145,28 +182,40 @@ class AlterFieldInstructionFactory:
|
|
|
145
182
|
field_changes=FieldChanges(
|
|
146
183
|
default=default,
|
|
147
184
|
default_factory=default_factory,
|
|
185
|
+
alias_priority=alias_priority,
|
|
148
186
|
alias=alias,
|
|
187
|
+
validation_alias=validation_alias,
|
|
188
|
+
serialization_alias=serialization_alias,
|
|
149
189
|
title=title,
|
|
190
|
+
field_title_generator=field_title_generator,
|
|
150
191
|
description=description,
|
|
192
|
+
examples=examples,
|
|
151
193
|
exclude=exclude,
|
|
152
194
|
const=const,
|
|
195
|
+
deprecated=deprecated,
|
|
196
|
+
frozen=frozen,
|
|
197
|
+
validate_default=validate_default,
|
|
198
|
+
repr=repr,
|
|
199
|
+
init=init,
|
|
200
|
+
init_var=init_var,
|
|
201
|
+
kw_only=kw_only,
|
|
202
|
+
fail_fast=fail_fast,
|
|
153
203
|
gt=gt,
|
|
154
204
|
ge=ge,
|
|
155
205
|
lt=lt,
|
|
156
206
|
le=le,
|
|
157
|
-
deprecated=deprecated,
|
|
158
207
|
strict=strict,
|
|
208
|
+
coerce_numbers_to_str=coerce_numbers_to_str,
|
|
159
209
|
multiple_of=multiple_of,
|
|
160
210
|
allow_inf_nan=allow_inf_nan,
|
|
161
211
|
max_digits=max_digits,
|
|
162
212
|
decimal_places=decimal_places,
|
|
163
213
|
min_length=min_length,
|
|
164
214
|
max_length=max_length,
|
|
215
|
+
union_mode=union_mode,
|
|
165
216
|
allow_mutation=allow_mutation,
|
|
166
217
|
pattern=pattern,
|
|
167
218
|
discriminator=discriminator,
|
|
168
|
-
repr=repr,
|
|
169
|
-
fail_fast=fail_fast,
|
|
170
219
|
),
|
|
171
220
|
)
|
|
172
221
|
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from fastapi.testclient import TestClient
|
|
4
|
+
from pydantic import BaseModel, Field
|
|
5
|
+
|
|
6
|
+
from cadwyn.applications import Cadwyn
|
|
7
|
+
from cadwyn.route_generation import VersionedAPIRouter
|
|
8
|
+
from cadwyn.structure.schemas import schema
|
|
9
|
+
from cadwyn.structure.versions import Version, VersionBundle, VersionChange
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class OuterSchema(BaseModel):
|
|
13
|
+
bar: MySchema
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class MySchema(BaseModel):
|
|
17
|
+
foo: str = Field(coerce_numbers_to_str=True)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class MyVersionChange(VersionChange):
|
|
21
|
+
description = "Hello"
|
|
22
|
+
instructions_to_migrate_to_previous_version = (
|
|
23
|
+
schema(MySchema).field("foo").had(type=int),
|
|
24
|
+
schema(MySchema).field("foo").didnt_have("coerce_numbers_to_str"),
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
app = Cadwyn(versions=VersionBundle(Version("2001-01-01", MyVersionChange), Version("2000-01-01")))
|
|
29
|
+
router = VersionedAPIRouter()
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@router.post("/test")
|
|
33
|
+
async def route_with_inner_schema_forwardref(dep: MySchema) -> MySchema:
|
|
34
|
+
return dep
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@router.post("/test2")
|
|
38
|
+
async def route_with_outer_schema_forwardref(dep: OuterSchema) -> OuterSchema:
|
|
39
|
+
return dep
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
app.generate_and_include_versioned_routers(router)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test__router_generation__using_forwardref_inner_global_schema_in_body():
|
|
46
|
+
unversioned_client = TestClient(app)
|
|
47
|
+
client_2000 = TestClient(app, headers={app.router.api_version_header_name: "2000-01-01"})
|
|
48
|
+
client_2001 = TestClient(app, headers={app.router.api_version_header_name: "2001-01-01"})
|
|
49
|
+
assert client_2000.post("/test", json={"foo": 1}).json() == {"foo": 1}
|
|
50
|
+
assert client_2001.post("/test", json={"foo": 1}).json() == {"foo": "1"}
|
|
51
|
+
assert unversioned_client.get("/openapi.json?version=2000-01-01").status_code == 200
|
|
52
|
+
assert unversioned_client.get("/openapi.json?version=2001-01-01").status_code == 200
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test__router_generation__using_forwardref_outer_global_schema_in_body():
|
|
56
|
+
unversioned_client = TestClient(app)
|
|
57
|
+
client_2000 = TestClient(app, headers={app.router.api_version_header_name: "2000-01-01"})
|
|
58
|
+
client_2001 = TestClient(app, headers={app.router.api_version_header_name: "2001-01-01"})
|
|
59
|
+
assert client_2000.post("/test2", json={"bar": {"foo": 1}}).json() == {"bar": {"foo": 1}}
|
|
60
|
+
assert client_2001.post("/test2", json={"bar": {"foo": 1}}).json() == {"bar": {"foo": "1"}}
|
|
61
|
+
assert unversioned_client.get("/openapi.json?version=2000-01-01").status_code == 200
|
|
62
|
+
assert unversioned_client.get("/openapi.json?version=2001-01-01").status_code == 200
|