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 %} {% 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 query_params|length > 0 %} if params: resource += f"?{httpx.QueryParams(params)}" {% endif %} {% if body_params|length > 0 and batch_operation != 'destroy' %} 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 %} action = { "resource": resource, "operation": "{{ batch_operation }}", {% if body_params|length > 0 and batch_operation != 'destroy'%} "body": payload, {% endif %} } {{ call_line }}