summaryrefslogtreecommitdiff
path: root/venv/lib/python3.11/site-packages/litestar/_openapi/utils.py
diff options
context:
space:
mode:
authorcyfraeviolae <cyfraeviolae>2024-04-03 03:10:44 -0400
committercyfraeviolae <cyfraeviolae>2024-04-03 03:10:44 -0400
commit6d7ba58f880be618ade07f8ea080fe8c4bf8a896 (patch)
treeb1c931051ffcebd2bd9d61d98d6233ffa289bbce /venv/lib/python3.11/site-packages/litestar/_openapi/utils.py
parent4f884c9abc32990b4061a1bb6997b4b37e58ea0b (diff)
venv
Diffstat (limited to 'venv/lib/python3.11/site-packages/litestar/_openapi/utils.py')
-rw-r--r--venv/lib/python3.11/site-packages/litestar/_openapi/utils.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/venv/lib/python3.11/site-packages/litestar/_openapi/utils.py b/venv/lib/python3.11/site-packages/litestar/_openapi/utils.py
new file mode 100644
index 0000000..b1950fa
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/litestar/_openapi/utils.py
@@ -0,0 +1,46 @@
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING
+
+from litestar.types.internal_types import PathParameterDefinition
+
+if TYPE_CHECKING:
+ from litestar.handlers.http_handlers import HTTPRouteHandler
+ from litestar.types import Method
+
+
+__all__ = ("default_operation_id_creator", "SEPARATORS_CLEANUP_PATTERN")
+
+SEPARATORS_CLEANUP_PATTERN = re.compile(r"[!#$%&'*+\-.^_`|~:]+")
+
+
+def default_operation_id_creator(
+ route_handler: HTTPRouteHandler,
+ http_method: Method,
+ path_components: list[str | PathParameterDefinition],
+) -> str:
+ """Create a unique 'operationId' for an OpenAPI PathItem entry.
+
+ Args:
+ route_handler: The HTTP Route Handler instance.
+ http_method: The HTTP method for the given PathItem.
+ path_components: A list of path components.
+
+ Returns:
+ A camelCased operationId created from the handler function name,
+ http method and path components.
+ """
+
+ handler_namespace = (
+ http_method.title() + route_handler.handler_name.title()
+ if len(route_handler.http_methods) > 1
+ else route_handler.handler_name.title()
+ )
+
+ components_namespace = ""
+ for component in (c.name if isinstance(c, PathParameterDefinition) else c for c in path_components):
+ if component.title() not in components_namespace:
+ components_namespace += component.title()
+
+ return SEPARATORS_CLEANUP_PATTERN.sub("", components_namespace + handler_namespace)