Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/clients/python/CHANGELOG.md.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### [{{packageVersion}}](https://{{gitHost}}/{{gitUserId}}/{{gitRepoId}}/compare/v0.9.4...{{packageVersion}}) (2025-07-09)

- fix: aiohttp.ClientResponse.data should be awaited (#197) - thanks @cmbernard333
- feat: allow per-request custom headers via `options["headers"]`

### [0.9.4](https://{{gitHost}}/{{gitUserId}}/{{gitRepoId}}/compare/v0.9.3...0.9.4) (2025-04-30)

Expand Down
3 changes: 1 addition & 2 deletions config/clients/python/template/src/api_client.py.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ class ApiClient:
start = float(time.time())

# header parameters
header_params = header_params or {}
header_params.update(self.default_headers)
header_params = {**self.default_headers, **(header_params or {})}
if self.cookie:
header_params['Cookie'] = self.cookie
if header_params:
Expand Down
72 changes: 36 additions & 36 deletions config/clients/python/template/src/client/client.py.mustache

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ class ApiClient:
start = float(time.time())

# header parameters
header_params = header_params or {}
header_params.update(self.default_headers)
header_params = {**self.default_headers, **(header_params or {})}
if self.cookie:
header_params['Cookie'] = self.cookie
if header_params:
Expand Down
72 changes: 36 additions & 36 deletions config/clients/python/template/src/sync/client/client.py.mustache

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions config/clients/python/template/test/api_test.py.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,60 @@ class TestOpenFgaApi(IsolatedAsyncioTestCase):
_request_timeout=None,
)

@patch.object(rest.RESTClientObject, "request")
async def test_check_override_default_header(self, mock_request):
"""Test case for overriding default header

Ensure per-request headers override default headers
"""

response_body = '{"allowed": true}'
mock_request.return_value = mock_response(response_body, 200)

configuration = self.configuration
configuration.store_id = store_id
async with {{packageName}}.ApiClient(configuration) as api_client:
api_client.set_default_header("Custom Header", "default value")
api_instance = open_fga_api.OpenFgaApi(api_client)
body = CheckRequest(
tuple_key=TupleKey(
object="document:2021-budget",
relation="reader",
user="user:81684243-9356-4421-8fbf-a4f8d36aa31b",
),
)
options = {"headers": {"Custom Header": "override value"}}
api_response = await api_instance.check(
body=body,
options=options,
)
self.assertIsInstance(api_response, CheckResponse)
self.assertTrue(api_response.allowed)
expected_headers = urllib3.response.HTTPHeaderDict(
{
"Accept": "application/json",
"Content-Type": "application/json",
"User-Agent": "openfga-sdk python/{{packageVersion}}",
"Custom Header": "override value",
}
)
mock_request.assert_called_once_with(
"POST",
"http://api.fga.example/stores/01H0H015178Y2V4CX10C2KGHF4/check",
headers=expected_headers,
query_params=[],
post_params=[],
body={
"tuple_key": {
"object": "document:2021-budget",
"relation": "reader",
"user": "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
}
},
_preload_content=ANY,
_request_timeout=None,
)

@patch.object(rest.RESTClientObject, "request")
async def test_check_custom_header(self, mock_request):
"""Test case for custom header
Expand Down
54 changes: 54 additions & 0 deletions config/clients/python/template/test/sync/api_test.py.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,60 @@ class TestOpenFgaApiSync(IsolatedAsyncioTestCase):
_request_timeout=None,
)

@patch.object(rest.RESTClientObject, "request")
def test_check_override_default_header(self, mock_request):
"""Test case for overriding default header

Ensure per-request headers override default headers
"""

response_body = '{"allowed": true}'
mock_request.return_value = mock_response(response_body, 200)

configuration = self.configuration
configuration.store_id = store_id
with ApiClient(configuration) as api_client:
api_client.set_default_header("Custom Header", "default value")
api_instance = open_fga_api.OpenFgaApi(api_client)
body = CheckRequest(
tuple_key=TupleKey(
object="document:2021-budget",
relation="reader",
user="user:81684243-9356-4421-8fbf-a4f8d36aa31b",
),
)
options = {"headers": {"Custom Header": "override value"}}
api_response = api_instance.check(
body=body,
options=options,
)
self.assertIsInstance(api_response, CheckResponse)
self.assertTrue(api_response.allowed)
expected_headers = urllib3.response.HTTPHeaderDict(
{
"Accept": "application/json",
"Content-Type": "application/json",
"User-Agent": "openfga-sdk python/{{packageVersion}}",
"Custom Header": "override value",
}
)
mock_request.assert_called_once_with(
"POST",
"http://api.fga.example/stores/01H0H015178Y2V4CX10C2KGHF4/check",
headers=expected_headers,
query_params=[],
post_params=[],
body={
"tuple_key": {
"object": "document:2021-budget",
"relation": "reader",
"user": "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
}
},
_preload_content=ANY,
_request_timeout=None,
)

@patch.object(rest.RESTClientObject, "request")
def test_check_custom_header(self, mock_request):
"""Test case for custom header
Expand Down
Loading