Skip to content

Commit 0b4fc6b

Browse files
committed
Changed incoming path parameters validation logic
1 parent 015c7e8 commit 0b4fc6b

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/murfey/util/api.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,19 @@ def url_path_for(
106106
route_path: str = route_info["path"]
107107
path_params: list[dict[str, str]] = route_info["path_params"]
108108

109-
# Validate the kwargs provided
110-
for param, value in kwargs.items():
111-
# Check if the name is not a match
112-
if param not in [p["name"] for p in path_params] and path_params:
113-
message = f"Unknown path parameter provided: {param}"
114-
logger.error(message)
115-
raise KeyError(message)
109+
# Validate the stored path params against the ones provided
110+
if path_params:
116111
for path_param in path_params:
117-
if (
118-
path_param["name"] == param
119-
and type(value).__name__ != path_param["type"]
120-
):
112+
param_name = path_param["name"]
113+
param_type = path_param["type"]
114+
if param_name not in kwargs.keys():
115+
message = f"Path param {param_name!r} was not provided"
116+
logger.error(message)
117+
raise KeyError(message)
118+
if type(kwargs[param_name]).__name__ != param_type:
121119
message = (
122-
f"'{param}' must be {path_param['type']!r}; "
123-
f"received {type(value).__name__!r}"
120+
f"{param_name!r} must be {param_type!r}; "
121+
f"received {type(kwargs[param_name]).__name__!r}"
124122
)
125123
logger.error(message)
126124
raise TypeError(message)
@@ -132,7 +130,9 @@ def url_path_for(
132130
if __name__ == "__main__":
133131
# Run test on some existing routes
134132
url_path = url_path_for(
135-
"bootstrap.pypi",
136-
"get_pypi_index",
133+
"workflow.tomo_router",
134+
"register_tilt",
135+
visit_name="nt15587-15",
136+
session_id=2,
137137
)
138138
print(url_path)

0 commit comments

Comments
 (0)