mirror of
https://github.com/langgenius/dify.git
synced 2026-11-13 06:41:07 +08:00
# Conflicts: # api/controllers/web/app.py # api/services/app_definition_query_service.py # api/services/workflow/tool_credentials.py # api/tests/unit_tests/controllers/console/explore/test_trial.py # api/tests/unit_tests/controllers/web/test_wraps.py # api/tests/unit_tests/services/end_user_connections/test_runtime.py # api/tests/unit_tests/services/test_app_definition_query_service.py # api/tests/unit_tests/services/test_app_generate_service.py
39 lines
932 B
Python
39 lines
932 B
Python
"""UUID validation types without framework or persistence dependencies."""
|
|
|
|
import uuid
|
|
from typing import Annotated
|
|
from uuid import UUID
|
|
|
|
from pydantic import AfterValidator, WithJsonSchema
|
|
|
|
|
|
def uuid_value(value: str | UUID) -> str:
|
|
if isinstance(value, UUID):
|
|
return str(value)
|
|
|
|
if value == "":
|
|
return str(value)
|
|
|
|
try:
|
|
uuid_obj = uuid.UUID(value)
|
|
return str(uuid_obj)
|
|
except ValueError as caught_error:
|
|
error = f"{value} is not a valid uuid."
|
|
raise ValueError(error) from caught_error
|
|
|
|
|
|
def _strict_uuid(value: str | UUID) -> str:
|
|
if not value:
|
|
raise ValueError("must be a non-empty valid UUID")
|
|
try:
|
|
return uuid_value(value)
|
|
except ValueError as exc:
|
|
raise ValueError("must be a valid UUID") from exc
|
|
|
|
|
|
UUIDStr = Annotated[
|
|
str,
|
|
AfterValidator(_strict_uuid),
|
|
WithJsonSchema({"format": "uuid", "type": "string"}),
|
|
]
|