Skip to content

Commit

Permalink
format path variables atomically
Browse files Browse the repository at this point in the history
Python's String format method (`format`) does not allow for partial
operation. Strings must be formatted with all required variables
present.
  • Loading branch information
chrised committed Feb 18, 2021
1 parent 4a24f36 commit 6b0d17b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion openapi3/paths.py
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit 6b0d17b

Please sign in to comment.