From 6b0d17b2237eb1f67a65066b4832a7564aff3a80 Mon Sep 17 00:00:00 2001 From: Chris Edwards <7331206+chrised@users.noreply.github.com> Date: Thu, 18 Feb 2021 13:40:13 +0000 Subject: [PATCH] format path variables atomically Python's String format method (`format`) does not allow for partial operation. Strings must be formatted with all required variables present. --- openapi3/paths.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/openapi3/paths.py b/openapi3/paths.py index 1d298ed..8c063f3 100644 --- a/openapi3/paths.py +++ b/openapi3/paths.py @@ -154,6 +154,7 @@ def _request_handle_secschemes(self, security_requirement, value): def _request_handle_parameters(self, parameters={}): # Parameters + path_parameters = {} accepted_parameters = {} p = self.parameters + self._root.paths[self.path[-2]].parameters @@ -172,7 +173,10 @@ def _request_handle_parameters(self, parameters={}): continue if spec.in_ == 'path': - self._request.url = self._request.url.format(**{name: value}) + # The string method `format` is incapable of partial updates, + # as such we need to collect all the path parameters before + # applying them to the format string. + path_parameters[name] = value if spec.in_ == 'query': self._request.params[name] = value @@ -183,6 +187,8 @@ def _request_handle_parameters(self, parameters={}): if spec.in_ == 'cookie': self._request.cookies[name] = value + self._request.url = self._request.url.format(**path_parameters) + def _request_handle_body(self, data): if 'application/json' in self.requestBody.content: if isinstance(data, dict) or isinstance(data, list):