cadwyn 4.5.0__tar.gz → 4.6.0a1__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.

Files changed (145) hide show
  1. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/.github/workflows/ci.yaml +10 -0
  2. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/CHANGELOG.md +6 -0
  3. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/PKG-INFO +1 -1
  4. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/applications.py +2 -2
  5. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/schema_generation.py +36 -4
  6. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/structure/schemas.py +64 -15
  7. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/pyproject.toml +1 -1
  8. cadwyn-4.6.0a1/tests/test_router_generation_with_from_future_annotations.py +62 -0
  9. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/uv.lock +218 -217
  10. cadwyn-4.5.0/.github/workflows/validate_links.yaml +0 -25
  11. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/.github/CODE_OF_CONDUCT.md +0 -0
  12. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  13. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  14. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/.github/actions/setup-python-uv/action.yaml +0 -0
  15. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/.github/workflows/daily_tests.yaml +0 -0
  16. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/.github/workflows/publish_docs.yaml +0 -0
  17. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/.github/workflows/release.yaml +0 -0
  18. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/.gitignore +0 -0
  19. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/.pre-commit-config.yaml +0 -0
  20. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/LICENSE +0 -0
  21. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/Makefile +0 -0
  22. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/README.md +0 -0
  23. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/__init__.py +0 -0
  24. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/__main__.py +0 -0
  25. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/_asts.py +0 -0
  26. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/_importer.py +0 -0
  27. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/_render.py +0 -0
  28. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/_utils.py +0 -0
  29. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/changelogs.py +0 -0
  30. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/exceptions.py +0 -0
  31. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/middleware.py +0 -0
  32. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/py.typed +0 -0
  33. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/route_generation.py +0 -0
  34. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/routing.py +0 -0
  35. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/static/__init__.py +0 -0
  36. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/static/docs.html +0 -0
  37. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/structure/__init__.py +0 -0
  38. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/structure/common.py +0 -0
  39. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/structure/data.py +0 -0
  40. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/structure/endpoints.py +0 -0
  41. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/structure/enums.py +0 -0
  42. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/cadwyn/structure/versions.py +0 -0
  43. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/CNAME +0 -0
  44. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/__init__.py +0 -0
  45. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/concepts/api_version_header_and_context_variables.md +0 -0
  46. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/concepts/beware_of_data_versioning.md +0 -0
  47. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/concepts/changelogs.md +0 -0
  48. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/concepts/cli.md +0 -0
  49. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/concepts/endpoint_migrations.md +0 -0
  50. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/concepts/enum_migrations.md +0 -0
  51. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/concepts/index.md +0 -0
  52. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/concepts/main_app.md +0 -0
  53. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/concepts/methodology.md +0 -0
  54. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/concepts/schema_generation.md +0 -0
  55. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/concepts/schema_migrations.md +0 -0
  56. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/concepts/testing.md +0 -0
  57. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/concepts/version_changes.md +0 -0
  58. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/home/CONTRIBUTING.md +0 -0
  59. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/how_to/change_business_logic/index.md +0 -0
  60. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/how_to/change_endpoints/index.md +0 -0
  61. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/how_to/change_openapi_schemas/add_field.md +0 -0
  62. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/how_to/change_openapi_schemas/change_field_type.md +0 -0
  63. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/how_to/change_openapi_schemas/change_schema_without_endpoint.md +0 -0
  64. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/how_to/change_openapi_schemas/changing_constraints.md +0 -0
  65. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/how_to/change_openapi_schemas/remove_field.md +0 -0
  66. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/how_to/change_openapi_schemas/rename_a_field_in_schema.md +0 -0
  67. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/how_to/index.md +0 -0
  68. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/img/dashboard_with_one_version.png +0 -0
  69. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/img/dashboard_with_two_versions.png +0 -0
  70. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/img/get_users_endpoint_from_prior_version.png +0 -0
  71. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/img/simplified_migration_model.png +0 -0
  72. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/img/sponsor_logos/monite.png +0 -0
  73. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/img/unversioned_dashboard.png +0 -0
  74. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/index.md +0 -0
  75. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/plugin.py +0 -0
  76. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/quickstart/setup.md +0 -0
  77. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/quickstart/tutorial.md +0 -0
  78. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/theory/how_to_build_versioning_framework.md +0 -0
  79. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/theory/how_we_got_here.md +0 -0
  80. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs/theory/literature.md +0 -0
  81. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/__init__.py +0 -0
  82. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/how_to/__init__.py +0 -0
  83. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/how_to/change_openapi_schemas/__init__.py +0 -0
  84. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/how_to/change_openapi_schemas/change_schema_without_endpoint/__init__.py +0 -0
  85. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/how_to/change_openapi_schemas/change_schema_without_endpoint/block001.py +0 -0
  86. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/how_to/change_openapi_schemas/change_schema_without_endpoint/block002.py +0 -0
  87. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/how_to/change_openapi_schemas/change_schema_without_endpoint/tests/__init__.py +0 -0
  88. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/how_to/change_openapi_schemas/change_schema_without_endpoint/tests/test_block001.py +0 -0
  89. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/how_to/change_openapi_schemas/change_schema_without_endpoint/tests/test_block002.py +0 -0
  90. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/quickstart/__init__.py +0 -0
  91. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/quickstart/setup/__init__.py +0 -0
  92. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/quickstart/setup/block001.sh +0 -0
  93. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/quickstart/setup/block002.py +0 -0
  94. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/quickstart/setup/tests/__init__.py +0 -0
  95. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/quickstart/setup/tests/test_block002.py +0 -0
  96. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/quickstart/tutorial/__init__.py +0 -0
  97. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/quickstart/tutorial/block001.py +0 -0
  98. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/quickstart/tutorial/block002.py +0 -0
  99. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/quickstart/tutorial/block003.py +0 -0
  100. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/quickstart/tutorial/tests/__init__.py +0 -0
  101. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/quickstart/tutorial/tests/test_block001.py +0 -0
  102. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/quickstart/tutorial/tests/test_block002.py +0 -0
  103. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/docs_src/quickstart/tutorial/tests/test_block003.py +0 -0
  104. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/mkdocs.yml +0 -0
  105. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/ruff.toml +0 -0
  106. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/scripts/fix_links.py +0 -0
  107. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/scripts/split_md.py +0 -0
  108. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/__init__.py +0 -0
  109. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/_data/__init__.py +0 -0
  110. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/_data/unversioned_schema_dir/__init__.py +0 -0
  111. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/_data/unversioned_schema_dir/unversioned_schemas.py +0 -0
  112. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/_data/unversioned_schemas.py +0 -0
  113. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/_resources/__init__.py +0 -0
  114. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/_resources/app_for_testing_routing.py +0 -0
  115. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/_resources/render/__init__.py +0 -0
  116. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/_resources/render/classes.py +0 -0
  117. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/_resources/render/complex/__init__.py +0 -0
  118. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/_resources/render/complex/classes.py +0 -0
  119. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/_resources/render/complex/versions.py +0 -0
  120. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/_resources/render/versions.py +0 -0
  121. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/_resources/utils.py +0 -0
  122. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/_resources/versioned_app/__init__.py +0 -0
  123. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/_resources/versioned_app/app.py +0 -0
  124. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/_resources/versioned_app/v2021_01_01.py +0 -0
  125. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/_resources/versioned_app/v2022_01_02.py +0 -0
  126. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/_resources/versioned_app/webhooks.py +0 -0
  127. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/conftest.py +0 -0
  128. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/test_applications.py +0 -0
  129. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/test_auth_dependencies.py +0 -0
  130. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/test_changelog.py +0 -0
  131. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/test_cli.py +0 -0
  132. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/test_data_migrations.py +0 -0
  133. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/test_render.py +0 -0
  134. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/test_router_generation.py +0 -0
  135. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/test_routing.py +0 -0
  136. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/test_schema_generation/__init__.py +0 -0
  137. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/test_schema_generation/test_enum.py +0 -0
  138. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/test_schema_generation/test_schema.py +0 -0
  139. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/test_schema_generation/test_schema_field.py +0 -0
  140. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/test_schema_generation/test_schema_validator.py +0 -0
  141. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/test_structure.py +0 -0
  142. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/tutorial/__init__.py +0 -0
  143. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/tutorial/main.py +0 -0
  144. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/tests/tutorial/test_example.py +0 -0
  145. {cadwyn-4.5.0 → cadwyn-4.6.0a1}/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,12 @@ Please follow [the Keep a Changelog standard](https://keepachangelog.com/en/1.0.
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ### Added
9
+
10
+ * Added 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`
11
+ * Added support for forwardrefs in body fields (for example, when you use `from __future__ import annotations` in the file with your routes)
12
+ * Added support for forwardrefs in route dependencies
13
+
8
14
  ## [4.5.0]
9
15
 
10
16
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cadwyn
3
- Version: 4.5.0
3
+ Version: 4.6.0a1
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(model.model_fields[field_name], model.__annotations__[field_name], field_name)
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=model.__annotations__.copy(),
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
- alias: str
52
- title: str
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
- alias: str = Sentinel,
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
- deprecated: bool = Sentinel,
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
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "cadwyn"
3
- version = "4.5.0"
3
+ version = "4.6.0-alpha.1"
4
4
  description = "Production-ready community-driven modern Stripe-like API versioning in FastAPI"
5
5
  authors = [{ name = "Stanislav Zmiev", email = "zmievsa@gmail.com" }]
6
6
  license = "MIT"
@@ -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