Skip to content

Commit 759afd0

Browse files
rhamzehCopilot
andauthored
chore: reduce generated code (#236)
* chore: add constants file * chore: fix test nesting * chore: remove autogenerated code headers from files no longer generated * chore: regenerate and lint cleanup * chore: fix constants file being ignored * chore: fix typo Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 6f06c2f commit 759afd0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+285
-964
lines changed

.openapi-generator-ignore

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
git_push.sh
22
test/*
3-
!test/__init__.py
4-
!test/test_open_fga_api.py
5-
!test/test_configuration.py
6-
!test/test_credentials.py
7-
!test/test_client.py
8-
!test/test_client_sync.py
9-
!test/test_open_fga_api_sync.py
10-
!test/test_validation.py
11-
!test/test_oauth2.py
12-
!test/test_oauth2_sync.py
133
.github/workflows/python.yml
144
.gitlab-ci.yml
155
.travis.yml
166
tox.ini
177
setup.cfg
188
setup.py
199
requirements.txt
20-
test-requirements.txt
10+
test-requirements.txt
11+
openfga_sdk/__init__.py
12+
openfga_sdk/api/__init__.py
13+
openfga_sdk/api/open_fga_api
14+
openfga_sdk/sync/open_fga_api.py
15+
openfga_sdk/api_client.py
16+
openfga_sdk/configuration.py
17+
openfga_sdk/exceptions.py
18+
openfga_sdk/rest.py

.openapi-generator/FILES

Lines changed: 1 addition & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
.codecov.yml
2-
.fossa.yml
32
.github/CODEOWNERS
43
.github/ISSUE_TEMPLATE/bug_report.yaml
54
.github/ISSUE_TEMPLATE/config.yaml
65
.github/ISSUE_TEMPLATE/feature_request.yaml
76
.gitignore
8-
.snyk
9-
CHANGELOG.md
107
CONTRIBUTING.md
118
LICENSE
129
README.md
@@ -100,53 +97,8 @@ docs/WriteAuthorizationModelResponse.md
10097
docs/WriteRequest.md
10198
docs/WriteRequestDeletes.md
10299
docs/WriteRequestWrites.md
103-
docs/opentelemetry.md
104-
example/Makefile
105-
example/README.md
106-
example/example1/example1.py
107-
example/example1/requirements.txt
108-
example/example1/setup.cfg
109-
example/example1/setup.py
110-
example/opentelemetry/.env.example
111-
example/opentelemetry/.gitignore
112-
example/opentelemetry/README.md
113-
example/opentelemetry/main.py
114-
example/opentelemetry/requirements.txt
115-
example/opentelemetry/setup.cfg
116-
example/opentelemetry/setup.py
117-
example/streamed-list-objects/README.md
118-
example/streamed-list-objects/example.py
119-
example/streamed-list-objects/model.json
120-
openfga_sdk/__init__.py
121-
openfga_sdk/api/__init__.py
122100
openfga_sdk/api/open_fga_api.py
123-
openfga_sdk/api/open_fga_api_sync.py
124-
openfga_sdk/api_client.py
125-
openfga_sdk/client/__init__.py
126-
openfga_sdk/client/client.py
127-
openfga_sdk/client/configuration.py
128-
openfga_sdk/client/models/__init__.py
129-
openfga_sdk/client/models/assertion.py
130-
openfga_sdk/client/models/batch_check_item.py
131-
openfga_sdk/client/models/batch_check_request.py
132-
openfga_sdk/client/models/batch_check_response.py
133-
openfga_sdk/client/models/batch_check_single_response.py
134-
openfga_sdk/client/models/check_request.py
135-
openfga_sdk/client/models/client_batch_check_response.py
136-
openfga_sdk/client/models/expand_request.py
137-
openfga_sdk/client/models/list_objects_request.py
138-
openfga_sdk/client/models/list_relations_request.py
139-
openfga_sdk/client/models/list_users_request.py
140-
openfga_sdk/client/models/read_changes_request.py
141-
openfga_sdk/client/models/tuple.py
142-
openfga_sdk/client/models/write_request.py
143-
openfga_sdk/client/models/write_response.py
144-
openfga_sdk/client/models/write_single_response.py
145-
openfga_sdk/client/models/write_transaction_opts.py
146-
openfga_sdk/configuration.py
147-
openfga_sdk/credentials.py
148-
openfga_sdk/exceptions.py
149-
openfga_sdk/help.py
101+
openfga_sdk/constants.py
150102
openfga_sdk/models/__init__.py
151103
openfga_sdk/models/aborted_message_response.py
152104
openfga_sdk/models/any.py
@@ -236,42 +188,3 @@ openfga_sdk/models/write_authorization_model_response.py
236188
openfga_sdk/models/write_request.py
237189
openfga_sdk/models/write_request_deletes.py
238190
openfga_sdk/models/write_request_writes.py
239-
openfga_sdk/oauth2.py
240-
openfga_sdk/rest.py
241-
openfga_sdk/sync/__init__.py
242-
openfga_sdk/sync/api_client.py
243-
openfga_sdk/sync/client/__init__.py
244-
openfga_sdk/sync/client/client.py
245-
openfga_sdk/sync/oauth2.py
246-
openfga_sdk/sync/rest.py
247-
openfga_sdk/telemetry/__init__.py
248-
openfga_sdk/telemetry/attributes.py
249-
openfga_sdk/telemetry/configuration.py
250-
openfga_sdk/telemetry/counters.py
251-
openfga_sdk/telemetry/histograms.py
252-
openfga_sdk/telemetry/metrics.py
253-
openfga_sdk/telemetry/telemetry.py
254-
openfga_sdk/validation.py
255-
pyproject.toml
256-
test/_/configuration_test.py
257-
test/_/credentials_test.py
258-
test/_/oauth2_test.py
259-
test/_/rest_test.py
260-
test/_/validation_test.py
261-
test/__init__.py
262-
test/api/__init__.py
263-
test/client/__init__.py
264-
test/client/client_test.py
265-
test/sync/__init__.py
266-
test/sync/client/__init__.py
267-
test/sync/client/client_test.py
268-
test/sync/oauth2_test.py
269-
test/sync/open_fga_api_test.py
270-
test/sync/rest_test.py
271-
test/telemetry/attributes_test.py
272-
test/telemetry/configuration_test.py
273-
test/telemetry/counters_test.py
274-
test/telemetry/histograms_test.py
275-
test/telemetry/metrics_test.py
276-
test/telemetry/telemetry_test.py
277-
test/test_open_fga_api.py

CONTRIBUTING.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,23 @@ By participating and contributing to this project, you are expected to uphold ou
2323

2424
### Making Changes
2525

26-
When contributing to a repository, the first step is to open an issue on [sdk-generator](https://github.com/openfga/sdk-generator) to discuss the change you wish to make before making them.
26+
When contributing to a repository, the first step is to open [an issue](https://github.com/openfga/python-sdk/issues) to discuss the change you wish to make before making them.
2727

2828
### Opening Issues
2929

3030
Before you submit a new issue please make sure to search all open and closed issues. It is possible your feature request/issue has already been answered. Make sure to also check the [OpenFGA discussions](https://github.com/orgs/openfga/discussions).
3131

32-
That repo includes an issue template that will walk through all the places to check before submitting your issue here. Please follow the instructions there to make sure this is not a duplicate issue and that we have everything we need to research and reproduce this problem.
32+
The repo includes an issue template that will walk through all the places to check before submitting your issue here. Please follow the instructions there to make sure this is not a duplicate issue and that we have everything we need to research and reproduce this problem.
33+
34+
If you have found a bug or if you have a feature request, please report them in the [repo issues](https://github.com/openfga/python-sdk/issues). Cross-SDK bugs and feature requests can be additionally reported in the [sdk-generator repo](https://github.com/openfga/sdk-generator/issues) issues section, where the individual SDK issue is then linked.
35+
36+
**Please do not report security vulnerabilities on the public GitHub issue tracker.**
3337

3438
### Submitting Pull Requests
3539

36-
While we accept Pull Requests on this repository, the SDKs are autogenerated so please consider additionally submitting your Pull Requests to the [sdk-generator](https://github.com/openfga/sdk-generator) and linking the two PRs together and to the corresponding issue. This will greatly assist the OpenFGA team in being able to give timely reviews as well as deploying fixes and updates to our other SDKs as well.
40+
Feel free to submit a Pull Request against this repository. Please make sure to follow the existing code style and include tests where applicable.
41+
42+
Some files in this repository are autogenerated. These files have a comment at the top indicating that they are autogenerated and should not be modified directly - the files are usually identified by a header marking them as such, or by their inclusion in [`.openapi-generator/FILES`](./.openapi-generator/FILES). Changes to these files should be made in the [sdk-generator](https://github.com/openfga/sdk-generator) repository in tandem, so please consider additionally submitting your Pull Requests to the [sdk-generator](https://github.com/openfga/sdk-generator) and linking the two PRs together and to the corresponding issue. This will greatly assist the OpenFGA team in being able to give timely reviews as well as deploying fixes and updates to our other SDKs as well.
3743

3844
## Getting in touch
3945

README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ This is an autogenerated python SDK for OpenFGA. It provides a wrapper around th
1818
- [Installation](#installation)
1919
- [Getting Started](#getting-started)
2020
- [Initializing the API Client](#initializing-the-api-client)
21+
- [Custom Headers](#custom-headers)
2122
- [Get your Store ID](#get-your-store-id)
2223
- [Calling the API](#calling-the-api)
2324
- [Stores](#stores)
@@ -1365,13 +1366,7 @@ This SDK supports producing metrics that can be consumed as part of an [OpenTele
13651366

13661367
## Contributing
13671368

1368-
### Issues
1369-
1370-
If you have found a bug or if you have a feature request, please report them on the [sdk-generator repo](https://github.com/openfga/sdk-generator/issues) issues section. Please do not report security vulnerabilities on the public GitHub issue tracker.
1371-
1372-
### Pull Requests
1373-
1374-
While we accept Pull Requests on this repository, the SDKs are autogenerated so please consider additionally submitting your Pull Requests to the [sdk-generator](https://github.com/openfga/sdk-generator) and linking the two PRs together and to the corresponding issue. This will greatly assist the OpenFGA team in being able to give timely reviews as well as deploying fixes and updates to our other SDKs as well.
1369+
See [CONTRIBUTING](./CONTRIBUTING.md) for details.
13751370

13761371
## Author
13771372

openfga_sdk/__init__.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
1-
"""
2-
Python SDK for OpenFGA
3-
4-
API version: 1.x
5-
Website: https://openfga.dev
6-
Documentation: https://openfga.dev/docs
7-
Support: https://openfga.dev/community
8-
License: [Apache-2.0](https://github.com/openfga/python-sdk/blob/main/LICENSE)
9-
10-
NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT.
11-
"""
12-
13-
__version__ = "0.9.7"
14-
151
from openfga_sdk.api.open_fga_api import OpenFgaApi
162
from openfga_sdk.api_client import ApiClient
173
from openfga_sdk.client.client import OpenFgaClient
184
from openfga_sdk.client.configuration import ClientConfiguration
195
from openfga_sdk.configuration import Configuration
6+
from openfga_sdk.constants import SDK_VERSION
207
from openfga_sdk.exceptions import (
218
ApiAttributeError,
229
ApiException,
@@ -144,6 +131,8 @@
144131
)
145132

146133

134+
__version__ = SDK_VERSION
135+
147136
__all__ = [
148137
"OpenFgaClient",
149138
"ClientConfiguration",

openfga_sdk/api_client.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
"""
2-
Python SDK for OpenFGA
3-
4-
API version: 1.x
5-
Website: https://openfga.dev
6-
Documentation: https://openfga.dev/docs
7-
Support: https://openfga.dev/community
8-
License: [Apache-2.0](https://github.com/openfga/python-sdk/blob/main/LICENSE)
9-
10-
NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT.
11-
"""
12-
131
import asyncio
142
import atexit
153
import datetime
@@ -28,6 +16,11 @@
2816

2917
from openfga_sdk import oauth2, rest
3018
from openfga_sdk.configuration import Configuration
19+
from openfga_sdk.constants import (
20+
MAX_BACKOFF_TIME_IN_SEC,
21+
RETRY_HEADER_MAX_ALLOWABLE_DURATION_IN_SEC,
22+
)
23+
from openfga_sdk.constants import USER_AGENT as DEFAULT_USER_AGENT
3124
from openfga_sdk.exceptions import (
3225
ApiException,
3326
ApiValueError,
@@ -39,9 +32,6 @@
3932
from openfga_sdk.telemetry.attributes import TelemetryAttribute, TelemetryAttributes
4033

4134

42-
DEFAULT_USER_AGENT = "openfga-sdk python/0.9.7"
43-
44-
4535
def random_time(loop_count, min_wait_in_ms) -> float:
4636
"""
4737
Helper function to return the time (in s) to wait before retry
@@ -258,7 +248,7 @@ async def __call_api(
258248
self.configuration.retry_params is not None
259249
and self.configuration.retry_params.max_wait_in_sec is not None
260250
)
261-
else 120
251+
else MAX_BACKOFF_TIME_IN_SEC
262252
)
263253
if _retry_params is not None:
264254
if _retry_params.max_retry is not None:
@@ -425,7 +415,10 @@ def _parse_retry_after_header(self, headers) -> int:
425415
except ApiException:
426416
wait_time_in_sec = int(retry_after_header)
427417

428-
if wait_time_in_sec > 1800 or wait_time_in_sec < 1:
418+
if (
419+
wait_time_in_sec > RETRY_HEADER_MAX_ALLOWABLE_DURATION_IN_SEC
420+
or wait_time_in_sec < 1
421+
):
429422
raise ValueError("Retry-After header is invalid")
430423

431424
return math.ceil(wait_time_in_sec)

openfga_sdk/client/__init__.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
"""
2-
Python SDK for OpenFGA
3-
4-
API version: 1.x
5-
Website: https://openfga.dev
6-
Documentation: https://openfga.dev/docs
7-
Support: https://openfga.dev/community
8-
License: [Apache-2.0](https://github.com/openfga/python-sdk/blob/main/LICENSE)
9-
10-
NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT.
11-
"""
12-
131
from openfga_sdk.client.client import OpenFgaClient
142
from openfga_sdk.client.configuration import ClientConfiguration
153
from openfga_sdk.client.models.check_request import ClientCheckRequest

openfga_sdk/client/client.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
"""
2-
Python SDK for OpenFGA
3-
4-
API version: 1.x
5-
Website: https://openfga.dev
6-
Documentation: https://openfga.dev/docs
7-
Support: https://openfga.dev/community
8-
License: [Apache-2.0](https://github.com/openfga/python-sdk/blob/main/LICENSE)
9-
10-
NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT.
11-
"""
12-
131
import asyncio
142
import uuid
153

@@ -45,6 +33,12 @@
4533
construct_write_single_response,
4634
)
4735
from openfga_sdk.client.models.write_transaction_opts import WriteTransactionOpts
36+
from openfga_sdk.constants import (
37+
CLIENT_BULK_REQUEST_ID_HEADER,
38+
CLIENT_MAX_BATCH_SIZE,
39+
CLIENT_MAX_METHOD_PARALLEL_REQUESTS,
40+
CLIENT_METHOD_HEADER,
41+
)
4842
from openfga_sdk.exceptions import (
4943
AuthenticationError,
5044
FgaValidationException,
@@ -76,10 +70,6 @@
7670
from openfga_sdk.validation import is_well_formed_ulid_string
7771

7872

79-
CLIENT_METHOD_HEADER = "X-OpenFGA-Client-Method"
80-
CLIENT_BULK_REQUEST_ID_HEADER = "X-OpenFGA-Client-Bulk-Request-Id"
81-
82-
8373
def _chuck_array(array, max_size):
8474
"""
8575
Helper function to chuck array into arrays of max_size
@@ -714,7 +704,7 @@ async def client_batch_check(
714704
options, CLIENT_BULK_REQUEST_ID_HEADER, str(uuid.uuid4())
715705
)
716706

717-
max_parallel_requests = 10
707+
max_parallel_requests = CLIENT_MAX_METHOD_PARALLEL_REQUESTS
718708
if options is not None and "max_parallel_requests" in options:
719709
if (
720710
isinstance(options["max_parallel_requests"], str)
@@ -773,7 +763,7 @@ async def batch_check(
773763
options, CLIENT_BULK_REQUEST_ID_HEADER, str(uuid.uuid4())
774764
)
775765

776-
max_parallel_requests = 10
766+
max_parallel_requests = CLIENT_MAX_METHOD_PARALLEL_REQUESTS
777767
if options is not None and "max_parallel_requests" in options:
778768
if (
779769
isinstance(options["max_parallel_requests"], str)
@@ -783,7 +773,7 @@ async def batch_check(
783773
elif isinstance(options["max_parallel_requests"], int):
784774
max_parallel_requests = options["max_parallel_requests"]
785775

786-
max_batch_size = 50
776+
max_batch_size = CLIENT_MAX_BATCH_SIZE
787777
if options is not None and "max_batch_size" in options:
788778
if (
789779
isinstance(options["max_batch_size"], str)

openfga_sdk/client/configuration.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
"""
2-
Python SDK for OpenFGA
3-
4-
API version: 1.x
5-
Website: https://openfga.dev
6-
Documentation: https://openfga.dev/docs
7-
Support: https://openfga.dev/community
8-
License: [Apache-2.0](https://github.com/openfga/python-sdk/blob/main/LICENSE)
9-
10-
NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT.
11-
"""
12-
131
from openfga_sdk.configuration import Configuration
142
from openfga_sdk.exceptions import FgaValidationException
153
from openfga_sdk.telemetry.attributes import TelemetryAttribute

openfga_sdk/client/models/__init__.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
"""
2-
Python SDK for OpenFGA
3-
4-
API version: 1.x
5-
Website: https://openfga.dev
6-
Documentation: https://openfga.dev/docs
7-
Support: https://openfga.dev/community
8-
License: [Apache-2.0](https://github.com/openfga/python-sdk/blob/main/LICENSE)
9-
10-
NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT.
11-
"""
12-
131
from openfga_sdk.client.models.assertion import ClientAssertion
142
from openfga_sdk.client.models.batch_check_item import ClientBatchCheckItem
153
from openfga_sdk.client.models.batch_check_request import ClientBatchCheckRequest

0 commit comments

Comments
 (0)