contentgrid-extension-helpers 0.0.3__py3-none-any.whl → 0.0.4__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.
- contentgrid_extension_helpers/responses/hal.py +13 -7
- {contentgrid_extension_helpers-0.0.3.dist-info → contentgrid_extension_helpers-0.0.4.dist-info}/METADATA +1 -1
- {contentgrid_extension_helpers-0.0.3.dist-info → contentgrid_extension_helpers-0.0.4.dist-info}/RECORD +6 -6
- {contentgrid_extension_helpers-0.0.3.dist-info → contentgrid_extension_helpers-0.0.4.dist-info}/WHEEL +1 -1
- {contentgrid_extension_helpers-0.0.3.dist-info → contentgrid_extension_helpers-0.0.4.dist-info}/licenses/LICENSE +0 -0
- {contentgrid_extension_helpers-0.0.3.dist-info → contentgrid_extension_helpers-0.0.4.dist-info}/top_level.txt +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from enum import Enum
|
|
1
2
|
from urllib.parse import urlencode
|
|
2
3
|
from fastapi import FastAPI
|
|
3
4
|
from fastapi.routing import APIRoute
|
|
@@ -9,13 +10,17 @@ from contentgrid_hal_client.hal import HALShape, HALLink
|
|
|
9
10
|
from contentgrid_hal_client.hal_forms import HALFormsTemplate, HALFormsMethod, HALFormsPropertyType, HALFormsProperty
|
|
10
11
|
import uri_template
|
|
11
12
|
|
|
12
|
-
def get_route_from_app(app: FastAPI, endpoint_function: str) -> APIRoute:
|
|
13
|
+
def get_route_from_app(app: FastAPI, endpoint_function: str, tags : Optional[List[str | Enum]] = None) -> APIRoute:
|
|
13
14
|
for route in app.routes:
|
|
14
15
|
if isinstance(route, APIRoute) and route.name == endpoint_function:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
if tags is None:
|
|
17
|
+
return route
|
|
18
|
+
else:
|
|
19
|
+
for tag in route.tags:
|
|
20
|
+
if tag in tags:
|
|
21
|
+
return route
|
|
22
|
+
error_message = f"No route found for endpoint {endpoint_function}"
|
|
23
|
+
raise ValueError(error_message)
|
|
19
24
|
|
|
20
25
|
def _add_params(url : str, params: Optional[Dict[str, str]] = None) -> str:
|
|
21
26
|
if params:
|
|
@@ -66,6 +71,7 @@ def extract_hal_forms_properties_from_pydantic_base_model(
|
|
|
66
71
|
|
|
67
72
|
class LinkForType(BaseModel):
|
|
68
73
|
endpoint_function_name: str
|
|
74
|
+
tags: Optional[List[str | Enum]] = None
|
|
69
75
|
templated: bool = False
|
|
70
76
|
path_params: Union[dict[str, str], Callable[["FastAPIHALResponse"], dict[str, str]]] = Field(default_factory=dict)
|
|
71
77
|
params: Union[dict[str, Union[str, int, float]], Callable[["FastAPIHALResponse"], dict[str, Union[str, int, float]]]] = Field(default_factory=dict)
|
|
@@ -111,7 +117,7 @@ class FastAPIHALResponse(HALShape):
|
|
|
111
117
|
return None
|
|
112
118
|
|
|
113
119
|
if hasattr(self.__class__, '_app') and self.__class__._app:
|
|
114
|
-
route = get_route_from_app(self.__class__._app, link.endpoint_function_name)
|
|
120
|
+
route = get_route_from_app(self.__class__._app, link.endpoint_function_name, tags=link.tags)
|
|
115
121
|
|
|
116
122
|
if hasattr(self.__class__, '_server_url'):
|
|
117
123
|
uri = f"{self.__class__._server_url}{route.path}"
|
|
@@ -164,7 +170,7 @@ class FastAPIHALResponse(HALShape):
|
|
|
164
170
|
continue
|
|
165
171
|
|
|
166
172
|
uri = hallink.uri
|
|
167
|
-
route = get_route_from_app(self.__class__._app, template_value.endpoint_function_name)
|
|
173
|
+
route = get_route_from_app(self.__class__._app, template_value.endpoint_function_name, tags=template_value.tags)
|
|
168
174
|
body_model, default_data = get_body_from_route(route=route)
|
|
169
175
|
if body_model is None:
|
|
170
176
|
properties = []
|
|
@@ -21,10 +21,10 @@ contentgrid_extension_helpers/logging/__init__.py,sha256=15tz-g0fLdBjJto8kWcjCYh
|
|
|
21
21
|
contentgrid_extension_helpers/logging/json_logging.py,sha256=NrzoBfEUAwQT7mmCHK0GoFJv5t9rrgjomDTXzZ-vgFI,3112
|
|
22
22
|
contentgrid_extension_helpers/middleware/exception_middleware.py,sha256=6mP7IQ7vPZ6-1_QESnAPZNQ5vA0MTTTzpovdszGp964,4467
|
|
23
23
|
contentgrid_extension_helpers/responses/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
24
|
-
contentgrid_extension_helpers/responses/hal.py,sha256=
|
|
24
|
+
contentgrid_extension_helpers/responses/hal.py,sha256=MkXzht6sXiRSGaohRiH8-cqKJuOJHmAMpYRz6LcCODQ,9529
|
|
25
25
|
contentgrid_extension_helpers/structured_output/model_deny.py,sha256=n2sEls0kyhvL8hHUKeo3_JQ_ZssyknIbIoDAOUvMVxc,1748
|
|
26
|
-
contentgrid_extension_helpers-0.0.
|
|
27
|
-
contentgrid_extension_helpers-0.0.
|
|
28
|
-
contentgrid_extension_helpers-0.0.
|
|
29
|
-
contentgrid_extension_helpers-0.0.
|
|
30
|
-
contentgrid_extension_helpers-0.0.
|
|
26
|
+
contentgrid_extension_helpers-0.0.4.dist-info/licenses/LICENSE,sha256=tk6n-p8lEmzLJg-O4052CkMgfUtt1q2Zoh1QLAyL7S8,555
|
|
27
|
+
contentgrid_extension_helpers-0.0.4.dist-info/METADATA,sha256=6b8zCBQwzWNlc1wbrZQCaqtSQJde8KS5M2xJ4pmFAW8,1574
|
|
28
|
+
contentgrid_extension_helpers-0.0.4.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
29
|
+
contentgrid_extension_helpers-0.0.4.dist-info/top_level.txt,sha256=yJGGofrNVsl5psVGO0vLFHO1610ob88GtB9zpvS8iIk,30
|
|
30
|
+
contentgrid_extension_helpers-0.0.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|