Skip to content

Commit e318e15

Browse files
author
Evan Sims
committed
feat: further type hinting improvements
1 parent 355c6eb commit e318e15

20 files changed

+810
-1221
lines changed

openfga_sdk/api/open_fga_api.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,22 @@ class OpenFgaApi:
2424
Do not edit the class manually.
2525
"""
2626

27-
def __init__(self, api_client=None):
27+
def __init__(
28+
self,
29+
api_client: ApiClient | None = None,
30+
):
2831
if api_client is None:
2932
api_client = ApiClient()
33+
3034
self.api_client: ApiClient = api_client
3135

3236
self._oauth2_client = None
37+
3338
if api_client.configuration is not None:
3439
credentials = api_client.configuration.credentials
40+
3541
if credentials is not None and credentials.method == "client_credentials":
36-
self._oauth2_client = OAuth2Client(
37-
credentials, api_client.configuration
38-
)
42+
self._oauth2_client = OAuth2Client(credentials)
3943

4044
self._telemetry = Telemetry()
4145

openfga_sdk/api_client.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,9 @@ async def __call_api(
169169
_request_auth=None,
170170
_retry_params=None,
171171
_oauth2_client=None,
172-
_telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float]
173-
| None = None,
172+
_telemetry_attributes: (
173+
dict[TelemetryAttribute, str | bool | int | float] | None
174+
) = None,
174175
_streaming: bool = False,
175176
):
176177
self.configuration.is_valid()
@@ -193,10 +194,9 @@ async def __call_api(
193194
path_params = self.sanitize_for_serialization(path_params)
194195
path_params = self.parameters_to_tuples(path_params, collection_formats)
195196
for k, v in path_params:
196-
# specified safe chars, encode everything
197-
_k = urllib.parse.quote(str(k), safe=config.safe_chars_for_path_param)
198-
_v = urllib.parse.quote(str(v), safe=config.safe_chars_for_path_param)
199-
resource_path = resource_path.replace("{" + str(k) + "}", _v)
197+
_k = urllib.parse.quote(str(k))
198+
_v = urllib.parse.quote(str(v))
199+
resource_path = resource_path.replace("{" + str(k) + "}", str(_v))
200200

201201
# query parameters
202202
if query_params:
@@ -223,19 +223,7 @@ async def __call_api(
223223
body = self.sanitize_for_serialization(body)
224224

225225
# request url
226-
if _host is None:
227-
if self.configuration.api_url is not None:
228-
url = self.configuration.api_url + resource_path
229-
else:
230-
url = (
231-
self.configuration.api_scheme
232-
+ "://"
233-
+ self.configuration.api_host
234-
+ resource_path
235-
)
236-
else:
237-
# use server/host defined in path or operation instead
238-
url = self.configuration.api_scheme + "://" + _host + resource_path
226+
url = self.configuration.api_url + resource_path
239227

240228
max_retry = (
241229
self.configuration.retry_params.max_retry
@@ -514,8 +502,9 @@ async def call_api(
514502
_request_auth=None,
515503
_retry_params=None,
516504
_oauth2_client=None,
517-
_telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float]
518-
| None = None,
505+
_telemetry_attributes: (
506+
dict[TelemetryAttribute, str | bool | int | float] | None
507+
) = None,
519508
_streaming: bool = False,
520509
):
521510
"""Makes the HTTP request (synchronous) and returns deserialized data.

openfga_sdk/client/client.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,22 @@ def _get_authorization_model_id(
177177
Otherwise, return the authorization model ID stored in the client's configuration
178178
"""
179179
authorization_model_id = self._client_configuration.authorization_model_id
180-
if options is not None and "authorization_model_id" in options:
180+
181+
if (
182+
options is not None
183+
and "authorization_model_id" in options
184+
and type(options["authorization_model_id"]) is str
185+
):
181186
authorization_model_id = options["authorization_model_id"]
187+
182188
if authorization_model_id is None or authorization_model_id == "":
183189
return None
190+
184191
if is_well_formed_ulid_string(authorization_model_id) is False:
185192
raise FgaValidationException(
186193
f"authorization_model_id ('{authorization_model_id}') is not in a valid ulid format"
187194
)
195+
188196
return authorization_model_id
189197

190198
def _get_consistency(

openfga_sdk/client/configuration.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT.
1111
"""
1212

13-
from openfga_sdk.configuration import Configuration
13+
import os
14+
15+
from openfga_sdk.configuration import Configuration, RetryParams
16+
from openfga_sdk.credentials import CredentialConfiguration
1417
from openfga_sdk.exceptions import FgaValidationException
1518
from openfga_sdk.validation import is_well_formed_ulid_string
1619

@@ -20,28 +23,27 @@ class ClientConfiguration(Configuration):
2023
OpenFGA client configuration
2124
"""
2225

26+
_authorization_model_id: str | None = None
27+
2328
def __init__(
2429
self,
25-
api_scheme="https",
26-
api_host=None,
27-
store_id=None,
28-
credentials=None,
29-
retry_params=None,
30-
authorization_model_id=None,
31-
ssl_ca_cert=None,
32-
api_url=None, # TODO: restructure when removing api_scheme/api_host
33-
timeout_millisec: int | None = None,
30+
api_url: str,
31+
store_id: str | None = None,
32+
credentials: CredentialConfiguration | None = None,
33+
retry_params: RetryParams | None = None,
34+
authorization_model_id: str | None = None,
35+
ssl_ca_cert: str | bytes | os.PathLike | None = None,
36+
timeout_millisec: int = 300000,
3437
):
3538
super().__init__(
36-
api_scheme,
37-
api_host,
38-
store_id,
39-
credentials,
40-
retry_params,
41-
ssl_ca_cert=ssl_ca_cert,
4239
api_url=api_url,
40+
store_id=store_id,
41+
credentials=credentials,
42+
retry_params=retry_params,
43+
ssl_ca_cert=ssl_ca_cert,
4344
timeout_millisec=timeout_millisec,
4445
)
46+
4547
self._authorization_model_id = authorization_model_id
4648

4749
def is_valid(self):
@@ -57,9 +59,9 @@ def is_valid(self):
5759
)
5860

5961
@property
60-
def authorization_model_id(self):
62+
def authorization_model_id(self) -> str | None:
6163
return self._authorization_model_id
6264

6365
@authorization_model_id.setter
64-
def authorization_model_id(self, value):
66+
def authorization_model_id(self, value: str | None) -> None:
6567
self._authorization_model_id = value

0 commit comments

Comments
 (0)