cadwyn 5.2.2__py3-none-any.whl → 5.3.1__py3-none-any.whl

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/applications.py CHANGED
@@ -4,7 +4,7 @@ from collections.abc import Awaitable, Callable, Coroutine, Sequence
4
4
  from datetime import date
5
5
  from logging import getLogger
6
6
  from pathlib import Path
7
- from typing import TYPE_CHECKING, Annotated, Any, Union, cast
7
+ from typing import TYPE_CHECKING, Annotated, Any, Optional, Union, cast
8
8
 
9
9
  import fastapi
10
10
  from fastapi import APIRouter, FastAPI, HTTPException, routing
@@ -71,6 +71,8 @@ class Cadwyn(FastAPI):
71
71
  api_version_format: APIVersionFormat = "date",
72
72
  api_version_parameter_name: str = "x-api-version",
73
73
  api_version_default_value: Union[str, None, Callable[[Request], Awaitable[str]]] = None,
74
+ api_version_title: Optional[str] = None,
75
+ api_version_description: Optional[str] = None,
74
76
  versioning_middleware_class: type[VersionPickingMiddleware] = VersionPickingMiddleware,
75
77
  changelog_url: Union[str, None] = "/changelog",
76
78
  include_changelog_url_in_schema: bool = True,
@@ -207,6 +209,8 @@ class Cadwyn(FastAPI):
207
209
  self.api_version_format = api_version_format
208
210
  self.api_version_parameter_name = api_version_parameter_name
209
211
  self.api_version_pythonic_parameter_name = api_version_parameter_name.replace("-", "_")
212
+ self.api_version_title = api_version_title
213
+ self.api_version_description = api_version_description
210
214
  if api_version_location == "custom_header":
211
215
  self._api_version_manager = HeaderVersionManager(api_version_parameter_name=api_version_parameter_name)
212
216
  self._api_version_fastapi_depends_class = fastapi.Header
@@ -465,6 +469,8 @@ class Cadwyn(FastAPI):
465
469
  default_value=version,
466
470
  fastapi_depends_class=self._api_version_fastapi_depends_class,
467
471
  validation_data_type=self.api_version_validation_data_type,
472
+ title=self.api_version_title,
473
+ description=self.api_version_description,
468
474
  )
469
475
  )
470
476
  ],
cadwyn/middleware.py CHANGED
@@ -5,7 +5,7 @@ import inspect
5
5
  import re
6
6
  from collections.abc import Awaitable, Callable
7
7
  from contextvars import ContextVar
8
- from typing import Annotated, Any, Literal, Protocol, Union
8
+ from typing import Annotated, Any, Literal, Optional, Protocol, Union
9
9
 
10
10
  import fastapi
11
11
  from fastapi import Request
@@ -58,6 +58,8 @@ def _generate_api_version_dependency(
58
58
  default_value: str,
59
59
  fastapi_depends_class: Callable[..., Any],
60
60
  validation_data_type: Any,
61
+ title: Optional[str] = None,
62
+ description: Optional[str] = None,
61
63
  ):
62
64
  def api_version_dependency(**kwargs: Any):
63
65
  # TODO: What do I return?
@@ -69,7 +71,12 @@ def _generate_api_version_dependency(
69
71
  api_version_pythonic_parameter_name,
70
72
  inspect.Parameter.KEYWORD_ONLY,
71
73
  annotation=Annotated[
72
- validation_data_type, fastapi_depends_class(openapi_examples={"default": {"value": default_value}})
74
+ validation_data_type,
75
+ fastapi_depends_class(
76
+ openapi_examples={"default": {"value": default_value}},
77
+ title=title,
78
+ description=description,
79
+ ),
73
80
  ],
74
81
  # Path-based parameters do not support a default value in FastAPI :(
75
82
  default=default_value if fastapi_depends_class != fastapi.Path else inspect.Signature.empty,
@@ -528,6 +528,8 @@ class VersionBundle:
528
528
  status_code=raised_exception.status_code,
529
529
  headers=raised_exception.headers,
530
530
  )
531
+ if (raised_exception.headers or {}).get("content-length") is None: # pragma: no branch
532
+ del response_or_response_body.headers["content-length"]
531
533
  api_version = self.api_version_var.get()
532
534
  if api_version is None:
533
535
  return response_or_response_body
@@ -579,6 +581,7 @@ class VersionBundle:
579
581
  head_route.response_model,
580
582
  head_route,
581
583
  )
584
+
582
585
  if isinstance(response_or_response_body, FastapiResponse):
583
586
  # a webserver (uvicorn for instance) calculates the body at the endpoint level.
584
587
  # if an endpoint returns no "body", its content-length will be set to 0
@@ -605,9 +608,10 @@ class VersionBundle:
605
608
  indent=None,
606
609
  separators=(",", ":"),
607
610
  ).encode("utf-8")
608
- # It makes sense to re-calculate content length because the previously calculated one
609
- # might slightly differ. If it differs -- uvicorn will break.
610
- response_info.headers["content-length"] = str(len(response_info._response.body))
611
+ if response_info.headers.get("content-length") is not None:
612
+ # It makes sense to re-calculate content length because the previously calculated one
613
+ # might slightly differ. If it differs -- uvicorn will break.
614
+ response_info.headers["content-length"] = str(len(response_info._response.body))
611
615
 
612
616
  if raised_exception is not None and response_info.status_code >= 400:
613
617
  if isinstance(response_info.body, dict) and "detail" in response_info.body:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cadwyn
3
- Version: 5.2.2
3
+ Version: 5.3.1
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
@@ -71,7 +71,7 @@ Production-ready community-driven modern [Stripe-like](https://stripe.com/blog/a
71
71
 
72
72
  ## Who is this for?
73
73
 
74
- Cadwyn 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.
74
+ Cadwyn allows you to maintain the implementation just for your newest API version and get all the older versions generated automatically. You keep API versioning encapsulated in small and independent "version change" modules while your business logic stays simple and knows nothing about versioning.
75
75
 
76
76
  Its [approach](https://docs.cadwyn.dev/theory/how_we_got_here/#ii-migration-based-response-building) will be useful if you want to:
77
77
 
@@ -4,11 +4,11 @@ cadwyn/_asts.py,sha256=QvqZmDdwH8U-Ocpj9vYR6MRrIANF8ugk9oZgAo76qLs,5223
4
4
  cadwyn/_importer.py,sha256=QV6HqODCG9K2oL4Vc15fAqL2-plMvUWw_cgaj4Ln4C8,1075
5
5
  cadwyn/_render.py,sha256=VAY2Twd_MfKaC8_X22AMIQd72_UHy87icdAbKL8hd90,5526
6
6
  cadwyn/_utils.py,sha256=q_mTtMKTNTDzqCza67XST-jaPSfuTgnFLmOe0dlGeYY,2295
7
- cadwyn/applications.py,sha256=xE-r96qSIWji6-mrpRhQVGTLHEvayfMDi0cRaIVPkds,20777
7
+ cadwyn/applications.py,sha256=sHfsgjy1ofotIPyLmL4FCAXyuzpjRtYLTQPR1ds471w,21133
8
8
  cadwyn/changelogs.py,sha256=aBTlsZ8PQpw9t4sSyezNTYDs6CMPtzIGulgAHA1ELPs,19622
9
9
  cadwyn/dependencies.py,sha256=phUJ4Fy3UTegpOfDfHMjxsvASWo-1NQgwqphNnPdoVQ,241
10
10
  cadwyn/exceptions.py,sha256=8D1G7ewLrMF5jq7leald1g0ulcH9zQl8ufEK3b7HHAE,1749
11
- cadwyn/middleware.py,sha256=jWhuISMEMo7kYLMJ8y4wzso1SNSpaW7Zkxocqi9MLEA,4617
11
+ cadwyn/middleware.py,sha256=4Ziq1ysnc8j5KmeZpsr9VJKllEFC8uYwXnG01I2FPR4,4853
12
12
  cadwyn/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  cadwyn/route_generation.py,sha256=RTZYfml03oKaNm_-SJX8N6PnafFXdsPpN0qEapHSzTw,27181
14
14
  cadwyn/routing.py,sha256=Ii6Qbgm9lGks1IAk-kDuIu_dX3FXsA77KSfGOFmLbgc,7604
@@ -23,9 +23,9 @@ cadwyn/structure/data.py,sha256=NWURVnP_84VI2ugp9ppo0Ofyve3pVYjymF9K82Jh-SA,7791
23
23
  cadwyn/structure/endpoints.py,sha256=zUgzglNhBPnmWdJ03A8pFT4zPs_lj8nQ7c7Uo2d-ejU,6246
24
24
  cadwyn/structure/enums.py,sha256=4FCc9aniLE3VuWAVIacrNP_FWxTIUm9JkeeHA_zZdwQ,1254
25
25
  cadwyn/structure/schemas.py,sha256=O9yNw1OB0Qz-PvNB0FYlQm34gQsjyG2l9gg9x-RnJIY,10781
26
- cadwyn/structure/versions.py,sha256=FNHhgqCVe9Q5TO5ZMOSJgR846mli4ubGLvNDUERyPYs,34447
27
- cadwyn-5.2.2.dist-info/METADATA,sha256=MDSfUMPASu62fS_-FeTMsisY57qGkVS98CcaRQ6u5CI,4529
28
- cadwyn-5.2.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
29
- cadwyn-5.2.2.dist-info/entry_points.txt,sha256=mGX8wl-Xfhpr5M93SUmkykaqinUaYAvW9rtDSX54gx0,47
30
- cadwyn-5.2.2.dist-info/licenses/LICENSE,sha256=KeCWewiDQYpmSnzF-p_0YpoWiyDcUPaCuG8OWQs4ig4,1072
31
- cadwyn-5.2.2.dist-info/RECORD,,
26
+ cadwyn/structure/versions.py,sha256=yOZ-x24Rb0itcZvQBe-92x9BiCLZK4cMqo0iX0DVN2k,34708
27
+ cadwyn-5.3.1.dist-info/METADATA,sha256=0iD1r46nUtL9fpEsyjb0d4dZn57JQ6qE-EUlSceSVYQ,4543
28
+ cadwyn-5.3.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
29
+ cadwyn-5.3.1.dist-info/entry_points.txt,sha256=mGX8wl-Xfhpr5M93SUmkykaqinUaYAvW9rtDSX54gx0,47
30
+ cadwyn-5.3.1.dist-info/licenses/LICENSE,sha256=KeCWewiDQYpmSnzF-p_0YpoWiyDcUPaCuG8OWQs4ig4,1072
31
+ cadwyn-5.3.1.dist-info/RECORD,,
File without changes