in samtranslator/open_api/open_api.py [0:0]
def add_path_parameters_to_method(self, api, path, method_name, path_parameters): # type: ignore[no-untyped-def]
"""
Adds path parameters to this path + method
:param dict api: Reference to the related Api's properties as defined in the template.
:param string path: Path name
:param string method_name: Method name
:param list path_parameters: list of strings of path parameters
"""
for method_definition in self.iter_on_method_definitions_for_path_at_method(path, method_name):
# create path parameter list
# add it here if it doesn't exist, merge with existing otherwise.
parameters = method_definition.setdefault("parameters", [])
for param in path_parameters:
# find an existing parameter with this name if it exists
existing_parameter = next(
(
existing_parameter
for existing_parameter in parameters
if existing_parameter.get("name") == param
),
None,
)
if existing_parameter:
# overwrite parameter values for existing path parameter
existing_parameter["in"] = "path"
existing_parameter["required"] = True
else:
# create as Py27Dict and insert keys one by one to preserve input order
parameter = Py27Dict()
parameter["name"] = Py27UniStr(param) if isinstance(param, str) else param
parameter["in"] = "path"
parameter["required"] = True
parameters.append(parameter)