cadwyn 3.4.2__tar.gz → 3.4.4__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 (34) hide show
  1. {cadwyn-3.4.2 → cadwyn-3.4.4}/PKG-INFO +1 -1
  2. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/codegen/_plugins/latest_version_aliasing.py +0 -2
  3. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/exceptions.py +4 -0
  4. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/routing.py +21 -1
  5. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/structure/versions.py +5 -6
  6. {cadwyn-3.4.2 → cadwyn-3.4.4}/pyproject.toml +1 -1
  7. {cadwyn-3.4.2 → cadwyn-3.4.4}/setup.py +1 -1
  8. {cadwyn-3.4.2 → cadwyn-3.4.4}/LICENSE +0 -0
  9. {cadwyn-3.4.2 → cadwyn-3.4.4}/README.md +0 -0
  10. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/__init__.py +0 -0
  11. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/__main__.py +0 -0
  12. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/_compat.py +0 -0
  13. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/_package_utils.py +0 -0
  14. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/_utils.py +0 -0
  15. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/codegen/README.md +0 -0
  16. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/codegen/__init__.py +0 -0
  17. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/codegen/_asts.py +0 -0
  18. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/codegen/_common.py +0 -0
  19. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/codegen/_main.py +0 -0
  20. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/codegen/_plugins/__init__.py +0 -0
  21. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/codegen/_plugins/class_migrations.py +0 -0
  22. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/codegen/_plugins/class_rebuilding.py +0 -0
  23. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/codegen/_plugins/class_renaming.py +0 -0
  24. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/codegen/_plugins/import_auto_adding.py +0 -0
  25. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/codegen/_plugins/module_migrations.py +0 -0
  26. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/main.py +0 -0
  27. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/py.typed +0 -0
  28. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/structure/__init__.py +0 -0
  29. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/structure/common.py +0 -0
  30. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/structure/data.py +0 -0
  31. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/structure/endpoints.py +0 -0
  32. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/structure/enums.py +0 -0
  33. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/structure/modules.py +0 -0
  34. {cadwyn-3.4.2 → cadwyn-3.4.4}/cadwyn/structure/schemas.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cadwyn
3
- Version: 3.4.2
3
+ Version: 3.4.4
4
4
  Summary: Production-ready community-driven modern Stripe-like API versioning in FastAPI
5
5
  Home-page: https://github.com/zmievsa/cadwyn
6
6
  License: MIT
@@ -64,8 +64,6 @@ class _ImportedModule:
64
64
  module = f"{self.path}.{self.name}"
65
65
  name = ast.alias(name="*")
66
66
  level = self.how_far_up_is_base_schema_dir_from_current_module
67
- if level == 2 and self.is_package:
68
- level -= 1
69
67
 
70
68
  return ast.ImportFrom(
71
69
  level=level,
@@ -25,6 +25,10 @@ class RouterGenerationError(CadwynError):
25
25
  pass
26
26
 
27
27
 
28
+ class RouterPathParamsModifiedError(RouterGenerationError):
29
+ pass
30
+
31
+
28
32
  class RouteAlreadyExistsError(RouterGenerationError):
29
33
  def __init__(self, *routes: APIRoute):
30
34
  self.routes = routes
@@ -1,5 +1,6 @@
1
1
  import functools
2
2
  import inspect
3
+ import re
3
4
  import sys
4
5
  import typing
5
6
  import warnings
@@ -45,7 +46,13 @@ from typing_extensions import Self, assert_never
45
46
  from cadwyn._compat import model_fields, rebuild_fastapi_body_param
46
47
  from cadwyn._package_utils import get_package_path_from_module, get_version_dir_path
47
48
  from cadwyn._utils import Sentinel, UnionType, get_another_version_of_module
48
- from cadwyn.exceptions import CadwynError, ModuleIsNotVersionedError, RouteAlreadyExistsError, RouterGenerationError
49
+ from cadwyn.exceptions import (
50
+ CadwynError,
51
+ ModuleIsNotVersionedError,
52
+ RouteAlreadyExistsError,
53
+ RouterGenerationError,
54
+ RouterPathParamsModifiedError,
55
+ )
49
56
  from cadwyn.structure import Version, VersionBundle
50
57
  from cadwyn.structure.common import Endpoint, VersionDate
51
58
  from cadwyn.structure.endpoints import (
@@ -624,6 +631,19 @@ def _apply_endpoint_had_instruction(
624
631
  " It means that your version change has no effect on the attribute"
625
632
  " and can be removed.",
626
633
  )
634
+ if attr_name == "path":
635
+ original_path_params = {p.alias for p in original_route.dependant.path_params}
636
+ new_path_params = set(re.findall("{(.*?)}", attr))
637
+ if new_path_params != original_path_params:
638
+ raise RouterPathParamsModifiedError(
639
+ f'When altering the path of "{original_route.path}" in "{version_change.__name__}",'
640
+ " you have tried to change its path params "
641
+ f'from "{list(original_route.methods)}" to "{list(new_path_params)}". It is not allowed to '
642
+ "change the path params of a route because the endpoint was created to handle the old path "
643
+ "params. In fact, there is no need to change them because the change of path params is "
644
+ "not a breaking change. If you really need to change the path params, you should create a "
645
+ "new route with the new path params and delete the old one.",
646
+ )
627
647
  setattr(original_route, attr_name, attr)
628
648
 
629
649
 
@@ -303,13 +303,13 @@ class VersionBundle:
303
303
  self,
304
304
  body_type: type[BaseModel] | None,
305
305
  latest_dependant_with_internal_schema: Dependant,
306
+ path: str,
306
307
  request: FastapiRequest,
307
308
  response: FastapiResponse,
308
309
  request_info: RequestInfo,
309
310
  current_version: VersionDate,
310
311
  latest_route: APIRoute,
311
312
  ) -> dict[str, Any]:
312
- path = request.scope["path"]
313
313
  method = request.method
314
314
  for v in reversed(self.versions):
315
315
  if v.value <= current_version:
@@ -363,7 +363,6 @@ class VersionBundle:
363
363
  Returns:
364
364
  Modified data
365
365
  """
366
-
367
366
  for v in self.versions:
368
367
  if v.value <= current_version:
369
368
  break
@@ -396,7 +395,6 @@ class VersionBundle:
396
395
  async def decorator(*args: Any, **kwargs: Any) -> _R:
397
396
  request: FastapiRequest = kwargs[request_param_name]
398
397
  response: FastapiResponse = kwargs[response_param_name]
399
- path = request.scope["path"]
400
398
  method = request.method
401
399
  kwargs = await self._convert_endpoint_kwargs_to_version(
402
400
  template_module_body_field_for_request_migrations,
@@ -413,7 +411,7 @@ class VersionBundle:
413
411
  return await self._convert_endpoint_response_to_version(
414
412
  endpoint,
415
413
  latest_route,
416
- path,
414
+ route,
417
415
  method,
418
416
  response_param_name,
419
417
  kwargs,
@@ -433,7 +431,7 @@ class VersionBundle:
433
431
  self,
434
432
  func_to_get_response_from: Endpoint,
435
433
  latest_route: APIRoute,
436
- path: str,
434
+ route: APIRoute,
437
435
  method: str,
438
436
  response_param_name: str,
439
437
  kwargs: dict[str, Any],
@@ -480,7 +478,7 @@ class VersionBundle:
480
478
  response_info,
481
479
  api_version,
482
480
  latest_route,
483
- path,
481
+ route.path,
484
482
  method,
485
483
  )
486
484
  if isinstance(response_or_response_body, FastapiResponse):
@@ -545,6 +543,7 @@ class VersionBundle:
545
543
  new_kwargs = await self._migrate_request(
546
544
  template_module_body_field_for_request_migrations,
547
545
  latest_dependant_with_internal_schema,
546
+ route.path,
548
547
  request,
549
548
  response,
550
549
  request_info,
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "cadwyn"
3
- version = "3.4.2"
3
+ version = "3.4.4"
4
4
  description = "Production-ready community-driven modern Stripe-like API versioning in FastAPI"
5
5
  authors = ["Stanislav Zmiev <zmievsa@gmail.com>"]
6
6
  license = "MIT"
@@ -22,7 +22,7 @@ entry_points = \
22
22
 
23
23
  setup_kwargs = {
24
24
  'name': 'cadwyn',
25
- 'version': '3.4.2',
25
+ 'version': '3.4.4',
26
26
  'description': 'Production-ready community-driven modern Stripe-like API versioning in FastAPI',
27
27
  'long_description': '# Cadwyn\n\nProduction-ready community-driven modern [Stripe-like](https://stripe.com/blog/api-versioning) API versioning in FastAPI\n\n---\n\n<p align="center">\n<a href="https://github.com/zmievsa/cadwyn/actions?query=workflow%3ATests+event%3Apush+branch%3Amain" target="_blank">\n <img src="https://github.com/zmievsa/cadwyn/actions/workflows/test.yaml/badge.svg?branch=main&event=push" alt="Test">\n</a>\n<a href="https://codecov.io/gh/ovsyanka83/cadwyn" target="_blank">\n <img src="https://img.shields.io/codecov/c/github/ovsyanka83/cadwyn?color=%2334D058" alt="Coverage">\n</a>\n<a href="https://pypi.org/project/cadwyn/" target="_blank">\n <img alt="PyPI" src="https://img.shields.io/pypi/v/cadwyn?color=%2334D058&label=pypi%20package" alt="Package version">\n</a>\n<a href="https://pypi.org/project/cadwyn/" target="_blank">\n <img src="https://img.shields.io/pypi/pyversions/cadwyn?color=%2334D058" alt="Supported Python versions">\n</a>\n</p>\n\n## Who is this for?\n\nCadwyn allows you to support a single version of your code while auto-generating the schemas and routes for older versions. You keep API versioning encapsulated in small and independent "version change" modules while your business logic stays simple and knows nothing about versioning.\n\nIts [approach](https://docs.cadwyn.dev/theory/#ii-migration-based-response-building) will be useful if you want to:\n\n1. Support many API versions for a long time\n2. Effortlessly backport features and bugfixes to older API versions\n\nWhether you are a newbie in API versioning, a pro looking for a sophisticated tool, an experimenter looking to build a similar framework, or even someone who just wants to learn about all approaches to API versioning -- Cadwyn has the functionality, theory, and documentation to cover all the mentioned use cases.\n\n## Get started\n\nThe [documentation](https://docs.cadwyn.dev) has everything you need to succeed.\n\n## Sponsors\n\nThese are our gorgeous sponsors. They are using Cadwyn and are sponsoring it through various means. Contact [me](https://github.com/zmievsa) if you would like to become one too!\n\n[![Monite](https://docs.cadwyn.dev/img/sponsor_logos/monite.png)](https://docs.monite.com/)\n',
28
28
  'author': 'Stanislav Zmiev',
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes