Skip to content

Commit bdf2507

Browse files
committed
replace uuid with regex
1 parent 9dfd4b8 commit bdf2507

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

ninja/router.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from typing import (
23
TYPE_CHECKING,
34
Any,
@@ -320,12 +321,11 @@ def add_api_operation(
320321
include_in_schema: bool = True,
321322
openapi_extra: Optional[Dict[str, Any]] = None,
322323
) -> None:
323-
if "{uuid:" in path:
324-
# django by default convert strings to UUIDs
325-
# but we want to keep them as strings to let pydantic handle conversion/validation
326-
# if user whants UUID object
327-
# uuidstr is custom registered converter
328-
path = path.replace("{uuid:", "{uuidstr:")
324+
path = re.sub(r"\{uuid:(\w+)\}", r"{uuidstr:\1}", path, flags=re.IGNORECASE)
325+
# django by default convert strings to UUIDs
326+
# but we want to keep them as strings to let pydantic handle conversion/validation
327+
# if user whants UUID object
328+
# uuidstr is custom registered converter
329329

330330
if path not in self.path_operations:
331331
path_view = PathView()

0 commit comments

Comments
 (0)