-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathfunction_template.jinja2
More file actions
68 lines (57 loc) · 2.67 KB
/
Copy pathfunction_template.jinja2
File metadata and controls
68 lines (57 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
def {{ operation }}(self{% if function_definition|length > 0 %}{{ function_definition }}{% endif %}):
"""
**{{ description }}**
{{ doc_url }}
{% for d in descriptions %}
- {{ d }}
{% endfor %}
"""
{% if kwarg_line|length > 0 %}
{{ kwarg_line }}
{% if renamed_params|length > 0 %}
{% for safe, orig in renamed_params.items() %}
if "{{ safe }}" in kwargs:
kwargs["{{ orig }}"] = kwargs.pop("{{ safe }}")
{% endfor %}
{% endif %}
{% endif %}
{% if assert_blocks|length > 0 %}
{% for param, values, nullable in assert_blocks %}
if "{{ param }}" in kwargs{% if nullable %} and kwargs["{{ param }}"] is not None{% endif %}:
options = {{ values }}
assert kwargs["{{ param }}"] in options, f'''"{{ param }}" cannot be "{kwargs['{{ param }}']}", & must be set to one of: {options}'''
{% endfor %}
{% endif %}
metadata = {
"tags": {{ tags|to_double_quote_list }},
"operation": "{{ operation }}",
}
{% for param in path_params %}
{{ param }} = urllib.parse.quote(str({{ param }}), safe="")
{% endfor %}
resource = f"{{ resource }}"
{% if query_params|length > 0 %}
query_params = [{% for param in query_params %}"{{ param }}", {% endfor %}]
params = {k.strip(): v for k, v in kwargs.items() if k.strip() in query_params}
{% endif %}
{% if array_params|length > 0 %}
array_params = [{% for param in array_params %}"{{ param }}", {% endfor %}]
for k, v in kwargs.items():
if k.strip() in array_params:
params[f"{k.strip()}[]"] = kwargs[f"{k}"]
params.pop(k.strip())
{% endif %}
{% if body_params|length > 0 %}
body_params = [{% for param in body_params %}"{{ param }}", {% endfor %}]
payload = {k.strip(): v for k, v in kwargs.items() if k.strip() in body_params}
{% endif %}
{% if query_params|length > 0 or body_params|length > 0 %}
if self._session._validate_kwargs:
all_params = {% if query_params|length > 0 %}query_params{% else %}[]{% endif %}{% if array_params|length > 0 %} + array_params{% endif %}{% if body_params|length > 0 %} + body_params{% endif %}
invalid = [k for k in kwargs if k.strip() not in all_params and k != "self"]
if invalid and self._session._logger:
self._session._logger.warning(
f"{{ operation }}: ignoring unrecognized kwargs: {invalid}"
)
{% endif %}
{{ call_line }}