{%  if async_client %}async {% endif %}def {{ operation_id }}({{ params }} api_config_override : APIConfig | None = None) -> {% if return_type.type is none or return_type.type.converted_type is none %}None{% else %}{{ return_type.type.converted_type}}{% endif %}:
    api_config = api_config_override if api_config_override else APIConfig()

    base_path = api_config.base_path
    path = f'{{ path_name }}'
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': f'Bearer { api_config.get_access_token() }',
        {{ header_params | join(',\n') | safe }}
    }
    query_params : Dict[str,Any] = {
    {% if query_params|length > 0 %}
        {{ query_params | join(',\n') | safe }}
    {% endif %}
    }

    query_params = {key:value for (key,value) in query_params.items() if value is not None}

    {% if async_client %}
async with httpx.AsyncClient(base_url=base_path, verify=APIConfig.verify) as client:
        response = await client.request(
    {% else %}
with httpx.Client(base_url=base_path, verify=api_config.verify) as client:
        response = client.request(
    {% endif %}
        '{{ method }}',
        httpx.URL(path),
        headers=headers,
        params=query_params,
        {% if body_param %}
        {% if use_orjson %}
        content=orjson.dumps({{ body_param }})
        {% else %}
        json = json.dumps({{ body_param }})
        {% endif %}
        {% endif %}
    )

    if response.status_code != {{ return_type.status_code }}:
        raise HTTPException(response.status_code, f'{{ operationId }} failed with status code: {response.status_code}')

{% if return_type.type is none or return_type.type.converted_type is none %}
    return None
{% elif return_type.complex_type %}
    {%- if return_type.list_type is none %}
    return {{ return_type.type.converted_type }}(**response.json()) if response.json() is not None else {{ return_type.type.converted_type }}()
    {%- else %}
    return [{{ return_type.list_type }}(**item) for item in response.json()]
    {%- endif %}
{% else %}
    return response.json()
{% endif %}
