diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c64672..602722d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## [Unreleased](https://github.com/openfga/python-sdk/compare/v0.9.9...HEAD) +- feat: add `execute_api_request` and `execute_streamed_api_request` methods to `OpenFgaClient` and `OpenFgaApi` for making arbitrary HTTP requests to any OpenFGA API endpoint with full auth, retry, and telemetry support (#252) - thanks @kcbiradar + +### Breaking Changes + +- The `_return_http_data_only`, `_preload_content`, `_request_auth`, `async_req`, and `_request_timeout` kwargs have been removed from all `OpenFgaApi` and `SyncOpenFgaApi` endpoint methods. These were internal implementation details not intended for external use. `_return_http_data_only` is now hardcoded to `True`; all endpoint methods return the deserialized response object directly. Users relying on `_with_http_info` methods returning a `(data, status, headers)` tuple should use `execute_api_request` instead. + ### [0.9.9](https://github.com/openfga/python-sdk/compare/v0.9.8...v0.9.9) (2025-12-09) - feat: improve error messaging (#245) diff --git a/README.md b/README.md index 696878f..62c6158 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ This is an autogenerated python SDK for OpenFGA. It provides a wrapper around th - [Read Assertions](#read-assertions) - [Write Assertions](#write-assertions) - [Retries](#retries) + - [Calling Other Endpoints](#calling-other-endpoints) - [API Endpoints](#api-endpoints) - [Models](#models) - [OpenTelemetry](#opentelemetry) @@ -1260,6 +1261,96 @@ body = [ClientAssertion( response = await fga_client.write_assertions(body, options) ``` +### Calling Other Endpoints + +In certain cases you may want to call other APIs not yet wrapped by the SDK. You can do so by using the `execute_api_request` method available on the `OpenFgaClient`. It allows you to make raw HTTP calls to any OpenFGA endpoint by specifying the HTTP method, path, body, query parameters, and path parameters, while still honoring the client configuration (authentication, telemetry, retries, and error handling). + +For streaming endpoints (e.g. `streamed-list-objects`), use `execute_streamed_api_request` instead. It returns an `AsyncIterator` (or `Iterator` in the sync client) that yields one parsed JSON object per chunk. + +This is useful when: +- You want to call a new endpoint that is not yet supported by the SDK +- You are using an earlier version of the SDK that doesn't yet support a particular endpoint +- You have a custom endpoint deployed that extends the OpenFGA API + +#### Example: Calling a Custom Endpoint with POST + +```python +# Call a custom endpoint using path parameters +response = await fga_client.execute_api_request( + operation_name="CustomEndpoint", # For telemetry/logging + method="POST", + path="/stores/{store_id}/custom-endpoint", + path_params={"store_id": FGA_STORE_ID}, + body={ + "user": "user:bob", + "action": "custom_action", + "resource": "resource:123", + }, + query_params={ + "page_size": 20, + }, +) + +# Access the response data +if response.status == 200: + result = response.json() + print(f"Response: {result}") +``` + +#### Example: Calling an existing endpoint with GET + +```python +# Get a list of stores with query parameters +stores_response = await fga_client.execute_api_request( + operation_name="ListStores", + method="GET", + path="/stores", + query_params={ + "page_size": 10, + "continuation_token": "eyJwayI6...", + }, +) + +stores = stores_response.json() +print("Stores:", stores) +``` + +#### Example: Calling a Streaming Endpoint + +```python +# Stream objects visible to a user +async for chunk in fga_client.execute_streamed_api_request( + operation_name="StreamedListObjects", + method="POST", + path="/stores/{store_id}/streamed-list-objects", + path_params={"store_id": FGA_STORE_ID}, + body={ + "type": "document", + "relation": "viewer", + "user": "user:anne", + "authorization_model_id": FGA_MODEL_ID, + }, +): + # Each chunk has the shape {"result": {"object": "..."}} or {"error": {...}} + if "result" in chunk: + print(chunk["result"]["object"]) # e.g. "document:roadmap" +``` + +#### Example: Using Path Parameters + +Path parameters are specified in the path using `{param_name}` syntax and must all be provided explicitly via `path_params` (URL-encoded automatically): + +```python +response = await fga_client.execute_api_request( + operation_name="GetAuthorizationModel", + method="GET", + path="/stores/{store_id}/authorization-models/{model_id}", + path_params={ + "store_id": "your-store-id", + "model_id": "your-model-id", + }, +) +``` ### Retries diff --git a/example/execute-api-request/execute_api_request_example.py b/example/execute-api-request/execute_api_request_example.py new file mode 100644 index 0000000..632c50d --- /dev/null +++ b/example/execute-api-request/execute_api_request_example.py @@ -0,0 +1,273 @@ +# ruff: noqa: E402 + +""" +execute_api_request example — calls real OpenFGA endpoints and compares +the results with the regular SDK methods to verify correctness. + +Requires a running OpenFGA server (default: http://localhost:8080). + export FGA_API_URL=http://localhost:8080 # optional, this is the default + python3 execute_api_request_example.py +""" + +import asyncio +import os +import sys + + +sdk_path = os.path.realpath(os.path.join(os.path.abspath(__file__), "..", "..", "..")) +sys.path.insert(0, sdk_path) + +from openfga_sdk import ( + ClientConfiguration, + CreateStoreRequest, + Metadata, + ObjectRelation, + OpenFgaClient, + RelationMetadata, + RelationReference, + TypeDefinition, + Userset, + Usersets, + WriteAuthorizationModelRequest, +) +from openfga_sdk.client.models import ( + ClientCheckRequest, + ClientTuple, + ClientWriteRequest, +) +from openfga_sdk.credentials import Credentials + + +async def main(): + api_url = os.getenv("FGA_API_URL", "http://localhost:8080") + + configuration = ClientConfiguration( + api_url=api_url, + credentials=Credentials(), + ) + + async with OpenFgaClient(configuration) as fga_client: + print("=== Setup ===") + + # Create a test store via the SDK + store = await fga_client.create_store( + CreateStoreRequest(name="execute_api_request_test") + ) + fga_client.set_store_id(store.id) + print(f"Created store: {store.id}") + + # Write an authorization model + model_resp = await fga_client.write_authorization_model( + WriteAuthorizationModelRequest( + schema_version="1.1", + type_definitions=[ + TypeDefinition(type="user"), + TypeDefinition( + type="document", + relations=dict( + writer=Userset(this=dict()), + viewer=Userset( + union=Usersets( + child=[ + Userset(this=dict()), + Userset( + computed_userset=ObjectRelation( + object="", relation="writer" + ) + ), + ] + ) + ), + ), + metadata=Metadata( + relations=dict( + writer=RelationMetadata( + directly_related_user_types=[ + RelationReference(type="user"), + ] + ), + viewer=RelationMetadata( + directly_related_user_types=[ + RelationReference(type="user"), + ] + ), + ) + ), + ), + ], + ) + ) + auth_model_id = model_resp.authorization_model_id + fga_client.set_authorization_model_id(auth_model_id) + print(f"Created model: {auth_model_id}") + + # Write a tuple + await fga_client.write( + ClientWriteRequest( + writes=[ + ClientTuple( + user="user:anne", + relation="writer", + object="document:roadmap", + ), + ] + ) + ) + print("Wrote tuple: user:anne → writer → document:roadmap") + + print("\n=== execute_api_request ===\n") + + print("1. ListStores (GET /stores)") + raw = await fga_client.execute_api_request( + operation_name="ListStores", + method="GET", + path="/stores", + query_params={"page_size": 100}, + ) + sdk = await fga_client.list_stores() + body = raw.json() + assert raw.status == 200, f"Expected 200, got {raw.status}" + assert "stores" in body + assert len(body["stores"]) == len(sdk.stores), ( + f"Count mismatch: {len(body['stores'])} vs {len(sdk.stores)}" + ) + print(f" ✅ {len(body['stores'])} stores (status {raw.status})") + + print("2. GetStore (GET /stores/{store_id})") + raw = await fga_client.execute_api_request( + operation_name="GetStore", + method="GET", + path="/stores/{store_id}", + path_params={"store_id": store.id}, + ) + sdk = await fga_client.get_store() + body = raw.json() + assert raw.status == 200 + assert body["id"] == sdk.id + assert body["name"] == sdk.name + print(f" ✅ id={body['id']}, name={body['name']}") + + print( + "3. ReadAuthorizationModels (GET /stores/{store_id}/authorization-models)" + ) + raw = await fga_client.execute_api_request( + operation_name="ReadAuthorizationModels", + method="GET", + path="/stores/{store_id}/authorization-models", + path_params={"store_id": store.id}, + ) + sdk = await fga_client.read_authorization_models() + body = raw.json() + assert raw.status == 200 + assert len(body["authorization_models"]) == len(sdk.authorization_models) + print(f" ✅ {len(body['authorization_models'])} models") + + print("4. Check (POST /stores/{store_id}/check)") + raw = await fga_client.execute_api_request( + operation_name="Check", + method="POST", + path="/stores/{store_id}/check", + path_params={"store_id": store.id}, + body={ + "tuple_key": { + "user": "user:anne", + "relation": "viewer", + "object": "document:roadmap", + }, + "authorization_model_id": auth_model_id, + }, + ) + sdk = await fga_client.check( + ClientCheckRequest( + user="user:anne", + relation="viewer", + object="document:roadmap", + ) + ) + body = raw.json() + assert raw.status == 200 + assert body["allowed"] == sdk.allowed + print(f" ✅ allowed={body['allowed']}") + + print("5. Read (POST /stores/{store_id}/read)") + raw = await fga_client.execute_api_request( + operation_name="Read", + method="POST", + path="/stores/{store_id}/read", + path_params={"store_id": store.id}, + body={ + "tuple_key": { + "user": "user:anne", + "object": "document:", + }, + }, + ) + body = raw.json() + assert raw.status == 200 + assert "tuples" in body + assert len(body["tuples"]) >= 1 + print(f" ✅ {len(body['tuples'])} tuples returned") + + print("6. CreateStore (POST /stores)") + raw = await fga_client.execute_api_request( + operation_name="CreateStore", + method="POST", + path="/stores", + body={"name": "raw_request_test_store"}, + ) + body = raw.json() + assert raw.status == 201, f"Expected 201, got {raw.status}" + assert "id" in body + new_store_id = body["id"] + print(f" ✅ created store: {new_store_id}") + + print("7. DeleteStore (DELETE /stores/{store_id})") + raw = await fga_client.execute_api_request( + operation_name="DeleteStore", + method="DELETE", + path="/stores/{store_id}", + path_params={"store_id": new_store_id}, + ) + assert raw.status == 204, f"Expected 204, got {raw.status}" + print(f" ✅ deleted store: {new_store_id} (status 204 No Content)") + + print("8. Custom headers (GET /stores/{store_id})") + raw = await fga_client.execute_api_request( + operation_name="GetStoreWithHeaders", + method="GET", + path="/stores/{store_id}", + path_params={"store_id": store.id}, + headers={"X-Custom-Header": "test-value"}, + ) + assert raw.status == 200 + print(f" ✅ custom headers accepted (status {raw.status})") + + print("9. StreamedListObjects (POST /stores/{store_id}/streamed-list-objects)") + chunks = [] + async for chunk in fga_client.execute_streamed_api_request( + operation_name="StreamedListObjects", + method="POST", + path="/stores/{store_id}/streamed-list-objects", + path_params={"store_id": store.id}, + body={ + "type": "document", + "relation": "viewer", + "user": "user:anne", + "authorization_model_id": auth_model_id, + }, + ): + chunks.append(chunk) + assert len(chunks) >= 1, f"Expected at least 1 chunk, got {len(chunks)}" + # Each chunk has the shape {"result": {"object": "..."}} or {"error": {...}} + objects = [c["result"]["object"] for c in chunks if "result" in c] + assert "document:roadmap" in objects, f"Expected document:roadmap in {objects}" + print(f" ✅ {len(chunks)} chunks, objects={objects}") + + print("\n=== Cleanup ===") + await fga_client.delete_store() + print(f"Deleted test store: {store.id}") + + print("\nAll execute_api_request examples completed successfully.\n") + + +asyncio.run(main()) diff --git a/openfga_sdk/__init__.py b/openfga_sdk/__init__.py index b4e6080..2c99928 100644 --- a/openfga_sdk/__init__.py +++ b/openfga_sdk/__init__.py @@ -2,6 +2,7 @@ from openfga_sdk.api_client import ApiClient from openfga_sdk.client.client import OpenFgaClient from openfga_sdk.client.configuration import ClientConfiguration +from openfga_sdk.client.models.raw_response import RawResponse from openfga_sdk.configuration import Configuration from openfga_sdk.constants import SDK_VERSION from openfga_sdk.exceptions import ( @@ -136,6 +137,7 @@ __all__ = [ "OpenFgaClient", "ClientConfiguration", + "RawResponse", "OpenFgaApi", "ApiClient", "Configuration", diff --git a/openfga_sdk/api/open_fga_api.py b/openfga_sdk/api/open_fga_api.py index 84637f4..29924e8 100644 --- a/openfga_sdk/api/open_fga_api.py +++ b/openfga_sdk/api/open_fga_api.py @@ -10,7 +10,16 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ +from __future__ import annotations + +from collections.abc import AsyncIterator +from typing import TYPE_CHECKING, Any + from openfga_sdk.api_client import ApiClient + + +if TYPE_CHECKING: + from openfga_sdk.client.models.raw_response import RawResponse from openfga_sdk.exceptions import ApiValueError, FgaValidationException from openfga_sdk.oauth2 import OAuth2Client from openfga_sdk.telemetry import Telemetry @@ -24,6 +33,24 @@ class OpenFgaApi: Do not edit the class manually. """ + _COMMON_PARAMS = [ + "async_req", + "_request_timeout", + "_headers", + "_retry_params", + "_streaming", + ] + + _COMMON_ERROR_RESPONSE_TYPES = { + 400: "ValidationErrorMessageResponse", + 401: "UnauthenticatedResponse", + 403: "ForbiddenResponse", + 404: "PathUnknownErrorMessageResponse", + 409: "AbortedMessageResponse", + 422: "UnprocessableContentMessageResponse", + 500: "InternalErrorMessageResponse", + } + def __init__(self, api_client=None): if api_client is None: api_client = ApiClient() @@ -48,6 +75,261 @@ async def __aexit__(self, exc_type, exc_value, traceback): async def close(self): await self.api_client.close() + async def _execute( + self, + method: str, + path: str, + operation_name: str, + response_types_map: dict, + body=None, + query_params=None, + headers: dict | None = None, + options: dict | None = None, + ) -> Any: + """Shared executor for all API endpoint methods.""" + if options is None: + options = {} + + header_params = dict(headers or {}) + header_params["Accept"] = self.api_client.select_header_accept( + ["application/json"] + ) + if body is not None: + content_type = self.api_client.select_header_content_type( + ["application/json"], method, body + ) + if content_type: + header_params["Content-Type"] = content_type + + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { + TelemetryAttributes.fga_client_request_method: operation_name, + TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), + TelemetryAttributes.fga_client_request_model_id: options.get( + "authorization_model_id", "" + ), + } + telemetry_attributes = TelemetryAttributes.fromBody( + body=body, attributes=telemetry_attributes + ) + + merged_response_types_map = { + **self._COMMON_ERROR_RESPONSE_TYPES, + **response_types_map, + } + + return await self.api_client.call_api( + path, + method, + {}, + query_params or [], + header_params, + body=body, + post_params=[], + files={}, + response_types_map=merged_response_types_map, + auth_settings=[], + async_req=options.get("async_req"), + _return_http_data_only=True, + _preload_content=True, + _request_timeout=options.get("_request_timeout"), + _retry_params=options.get("_retry_params"), + collection_formats={}, + _oauth2_client=self._oauth2_client, + _telemetry_attributes=telemetry_attributes, + _streaming=options.get("_streaming", False), + ) + + async def execute_api_request( + self, + *, + operation_name: str, + method: str, + path: str, + path_params: dict[str, str] | None = None, + body: dict[str, Any] | list[Any] | str | bytes | None = None, + query_params: dict[str, str | int | list[str | int]] | None = None, + headers: dict[str, str] | None = None, + options: dict[str, Any] | None = None, + ) -> RawResponse: + """ + Execute an arbitrary HTTP request to any OpenFGA API endpoint. + + Useful for calling endpoints not yet wrapped by the SDK while + still getting authentication, retries, and error handling. + + :param operation_name: Operation name for telemetry (e.g., "CustomCheck") + :param method: HTTP method (GET, POST, PUT, DELETE, PATCH) + :param path: API path, e.g. "/stores/{store_id}/my-endpoint". + :param path_params: Path parameter substitutions (URL-encoded automatically). + All path parameters, including store_id, must be provided explicitly. + :param body: Request body for POST/PUT/PATCH + :param query_params: Query string parameters + :param headers: Custom headers (SDK enforces Content-Type and Accept) + :param options: Extra options e.g. {"retry_params": RetryParams(max_retry=3)} + :return: RawResponse with status, headers, and body + """ + return await self._execute_api_request_internal( + operation_name=operation_name, + method=method, + path=path, + path_params=path_params, + body=body, + query_params=query_params, + headers=headers, + options=options, + ) + + async def execute_streamed_api_request( + self, + *, + operation_name: str, + method: str, + path: str, + path_params: dict[str, str] | None = None, + body: dict[str, Any] | list[Any] | str | bytes | None = None, + query_params: dict[str, str | int | list[str | int]] | None = None, + headers: dict[str, str] | None = None, + options: dict[str, Any] | None = None, + ) -> AsyncIterator[dict[str, Any]]: + """ + Execute an arbitrary HTTP request to a streaming OpenFGA API endpoint. + + Yields parsed JSON objects as they arrive. Use with async for: + + async for chunk in api.execute_streamed_api_request(...): + process(chunk) + + :param operation_name: Operation name for telemetry (e.g., "StreamedListObjects") + :param method: HTTP method (GET, POST, PUT, DELETE, PATCH) + :param path: API path, e.g. "/stores/{store_id}/streamed-list-objects". + :param path_params: Path parameter substitutions (URL-encoded automatically). + All path parameters, including store_id, must be provided explicitly. + :param body: Request body for POST/PUT/PATCH + :param query_params: Query string parameters + :param headers: Custom headers (SDK enforces Content-Type and Accept) + :param options: Extra options e.g. {"retry_params": RetryParams(max_retry=3)} + """ + from openfga_sdk.client.execute_api_request_builder import ( + ExecuteApiRequestBuilder, + ) + + builder = ExecuteApiRequestBuilder( + operation_name=operation_name, + method=method, + path=path, + path_params=path_params, + body=body, + query_params=query_params, + headers=headers, + ) + builder.validate() + + resource_path = builder.build_path() + query_params_list = builder.build_query_params_list() + final_headers = builder.build_headers() + + retry_params = options.get("retry_params") if options else None + + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { + TelemetryAttributes.fga_client_request_method: operation_name.lower(), + } + if self.api_client.get_store_id(): + telemetry_attributes[TelemetryAttributes.fga_client_request_store_id] = ( + self.api_client.get_store_id() + ) + + stream = await self.api_client.call_api( + resource_path=resource_path, + method=method.upper(), + query_params=query_params_list if query_params_list else None, + header_params=final_headers, + body=body, + response_types_map={}, + auth_settings=[], + _return_http_data_only=True, + _preload_content=True, + _retry_params=retry_params, + _oauth2_client=self._oauth2_client, + _telemetry_attributes=telemetry_attributes, + _streaming=True, + ) + + async for chunk in stream: + yield chunk + + async def _execute_api_request_internal( + self, + *, + operation_name: str, + method: str, + path: str, + path_params: dict[str, str] | None = None, + body: dict[str, Any] | list[Any] | str | bytes | None = None, + query_params: dict[str, str | int | list[str | int]] | None = None, + headers: dict[str, str] | None = None, + options: dict[str, Any] | None = None, + ) -> RawResponse: + """Implementation for execute_api_request.""" + from openfga_sdk.client.execute_api_request_builder import ( + ExecuteApiRequestBuilder, + ResponseParser, + ) + from openfga_sdk.client.models.raw_response import RawResponse + + builder = ExecuteApiRequestBuilder( + operation_name=operation_name, + method=method, + path=path, + path_params=path_params, + body=body, + query_params=query_params, + headers=headers, + ) + builder.validate() + + resource_path = builder.build_path() + query_params_list = builder.build_query_params_list() + final_headers = builder.build_headers() + + retry_params = options.get("retry_params") if options else None + + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { + TelemetryAttributes.fga_client_request_method: operation_name.lower(), + } + if self.api_client.get_store_id(): + telemetry_attributes[TelemetryAttributes.fga_client_request_store_id] = ( + self.api_client.get_store_id() + ) + + await self.api_client.call_api( + resource_path=resource_path, + method=method.upper(), + query_params=query_params_list if query_params_list else None, + header_params=final_headers, + body=body, + response_types_map={}, + auth_settings=[], + _return_http_data_only=True, + _preload_content=True, + _retry_params=retry_params, + _oauth2_client=self._oauth2_client, + _telemetry_attributes=telemetry_attributes, + _streaming=False, + ) + + rest_response = getattr(self.api_client, "last_response", None) + if rest_response is None: + raise RuntimeError( + f"No response for {method.upper()} {resource_path} " + f"(operation: {operation_name})" + ) + + return RawResponse( + status=rest_response.status, + headers=dict(rest_response.getheaders()), + body=ResponseParser.parse_body(rest_response.data), + ) + async def batch_check(self, body, **kwargs): """Send a list of `check` operations in a single request @@ -72,7 +354,6 @@ async def batch_check(self, body, **kwargs): returns the request thread. :rtype: BatchCheckResponse """ - kwargs["_return_http_data_only"] = True return await self.batch_check_with_http_info(body, **kwargs) async def batch_check_with_http_info(self, body, **kwargs): @@ -112,19 +393,7 @@ async def batch_check_with_http_info(self, body, **kwargs): local_var_params = locals() all_params = ["body"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -133,7 +402,6 @@ async def batch_check_with_http_info(self, body, **kwargs): ) local_var_params[key] = val del local_var_params["kwargs"] - # verify the required parameter 'body' is set if ( self.api_client.client_side_validation and local_var_params.get("body") is None @@ -141,92 +409,19 @@ async def batch_check_with_http_info(self, body, **kwargs): raise ApiValueError( "Missing the required parameter `body` when calling `batch_check`" ) - - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `batch_check`" ) store_id = self.api_client._get_store_id() - - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - if "body" in local_var_params: - body_params = local_var_params["body"] - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # HTTP header `Content-Type` - content_types_list = local_var_params.get( - "_content_type", - self.api_client.select_header_content_type( - ["application/json"], "POST", body_params - ), - ) - if content_types_list: - header_params["Content-Type"] = content_types_list - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "BatchCheckResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "batch_check", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return await self.api_client.call_api( - "/stores/{store_id}/batch-check".replace("{store_id}", store_id), - "POST", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return await self._execute( + method="POST", + path=f"/stores/{store_id}/batch-check", + operation_name="batch_check", + response_types_map={200: "BatchCheckResponse"}, + body=local_var_params.get("body"), + headers=local_var_params.get("_headers"), + options=local_var_params, ) async def check(self, body, **kwargs): @@ -253,7 +448,6 @@ async def check(self, body, **kwargs): returns the request thread. :rtype: CheckResponse """ - kwargs["_return_http_data_only"] = True return await self.check_with_http_info(body, **kwargs) async def check_with_http_info(self, body, **kwargs): @@ -293,19 +487,7 @@ async def check_with_http_info(self, body, **kwargs): local_var_params = locals() all_params = ["body"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -314,7 +496,6 @@ async def check_with_http_info(self, body, **kwargs): ) local_var_params[key] = val del local_var_params["kwargs"] - # verify the required parameter 'body' is set if ( self.api_client.client_side_validation and local_var_params.get("body") is None @@ -322,92 +503,19 @@ async def check_with_http_info(self, body, **kwargs): raise ApiValueError( "Missing the required parameter `body` when calling `check`" ) - - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `check`" ) store_id = self.api_client._get_store_id() - - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - if "body" in local_var_params: - body_params = local_var_params["body"] - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # HTTP header `Content-Type` - content_types_list = local_var_params.get( - "_content_type", - self.api_client.select_header_content_type( - ["application/json"], "POST", body_params - ), - ) - if content_types_list: - header_params["Content-Type"] = content_types_list - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "CheckResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "check", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return await self.api_client.call_api( - "/stores/{store_id}/check".replace("{store_id}", store_id), - "POST", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return await self._execute( + method="POST", + path=f"/stores/{store_id}/check", + operation_name="check", + response_types_map={200: "CheckResponse"}, + body=local_var_params.get("body"), + headers=local_var_params.get("_headers"), + options=local_var_params, ) async def create_store(self, body, **kwargs): @@ -434,7 +542,6 @@ async def create_store(self, body, **kwargs): returns the request thread. :rtype: CreateStoreResponse """ - kwargs["_return_http_data_only"] = True return await self.create_store_with_http_info(body, **kwargs) async def create_store_with_http_info(self, body, **kwargs): @@ -474,19 +581,7 @@ async def create_store_with_http_info(self, body, **kwargs): local_var_params = locals() all_params = ["body"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -495,86 +590,14 @@ async def create_store_with_http_info(self, body, **kwargs): ) local_var_params[key] = val del local_var_params["kwargs"] - - collection_formats = {} - - path_params = {} - - store_id = None - - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - if "body" in local_var_params: - body_params = local_var_params["body"] - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # HTTP header `Content-Type` - content_types_list = local_var_params.get( - "_content_type", - self.api_client.select_header_content_type( - ["application/json"], "POST", body_params - ), - ) - if content_types_list: - header_params["Content-Type"] = content_types_list - - # Authentication setting - auth_settings = [] - - response_types_map = { - 201: "CreateStoreResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "create_store", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return await self.api_client.call_api( - "/stores", - "POST", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return await self._execute( + method="POST", + path="/stores", + operation_name="create_store", + response_types_map={201: "CreateStoreResponse"}, + body=local_var_params.get("body"), + headers=local_var_params.get("_headers"), + options=local_var_params, ) async def delete_store(self, **kwargs): @@ -599,7 +622,6 @@ async def delete_store(self, **kwargs): returns the request thread. :rtype: None """ - kwargs["_return_http_data_only"] = True return await self.delete_store_with_http_info(**kwargs) async def delete_store_with_http_info(self, **kwargs): @@ -637,19 +659,7 @@ async def delete_store_with_http_info(self, **kwargs): local_var_params = locals() all_params = [] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -658,71 +668,18 @@ async def delete_store_with_http_info(self, **kwargs): ) local_var_params[key] = val del local_var_params["kwargs"] - - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `delete_store`" ) store_id = self.api_client._get_store_id() - - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # Authentication setting - auth_settings = [] - - response_types_map = {} - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "delete_store", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return await self.api_client.call_api( - "/stores/{store_id}".replace("{store_id}", store_id), - "DELETE", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return await self._execute( + method="DELETE", + path=f"/stores/{store_id}", + operation_name="delete_store", + response_types_map={}, + headers=local_var_params.get("_headers"), + options=local_var_params, ) async def expand(self, body, **kwargs): @@ -749,7 +706,6 @@ async def expand(self, body, **kwargs): returns the request thread. :rtype: ExpandResponse """ - kwargs["_return_http_data_only"] = True return await self.expand_with_http_info(body, **kwargs) async def expand_with_http_info(self, body, **kwargs): @@ -789,19 +745,7 @@ async def expand_with_http_info(self, body, **kwargs): local_var_params = locals() all_params = ["body"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -810,7 +754,6 @@ async def expand_with_http_info(self, body, **kwargs): ) local_var_params[key] = val del local_var_params["kwargs"] - # verify the required parameter 'body' is set if ( self.api_client.client_side_validation and local_var_params.get("body") is None @@ -818,92 +761,19 @@ async def expand_with_http_info(self, body, **kwargs): raise ApiValueError( "Missing the required parameter `body` when calling `expand`" ) - - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `expand`" ) store_id = self.api_client._get_store_id() - - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - if "body" in local_var_params: - body_params = local_var_params["body"] - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # HTTP header `Content-Type` - content_types_list = local_var_params.get( - "_content_type", - self.api_client.select_header_content_type( - ["application/json"], "POST", body_params - ), - ) - if content_types_list: - header_params["Content-Type"] = content_types_list - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "ExpandResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "expand", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return await self.api_client.call_api( - "/stores/{store_id}/expand".replace("{store_id}", store_id), - "POST", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return await self._execute( + method="POST", + path=f"/stores/{store_id}/expand", + operation_name="expand", + response_types_map={200: "ExpandResponse"}, + body=local_var_params.get("body"), + headers=local_var_params.get("_headers"), + options=local_var_params, ) async def get_store(self, **kwargs): @@ -928,7 +798,6 @@ async def get_store(self, **kwargs): returns the request thread. :rtype: GetStoreResponse """ - kwargs["_return_http_data_only"] = True return await self.get_store_with_http_info(**kwargs) async def get_store_with_http_info(self, **kwargs): @@ -966,19 +835,7 @@ async def get_store_with_http_info(self, **kwargs): local_var_params = locals() all_params = [] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -987,80 +844,18 @@ async def get_store_with_http_info(self, **kwargs): ) local_var_params[key] = val del local_var_params["kwargs"] - - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `get_store`" ) store_id = self.api_client._get_store_id() - - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "GetStoreResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "get_store", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return await self.api_client.call_api( - "/stores/{store_id}".replace("{store_id}", store_id), - "GET", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return await self._execute( + method="GET", + path=f"/stores/{store_id}", + operation_name="get_store", + response_types_map={200: "GetStoreResponse"}, + headers=local_var_params.get("_headers"), + options=local_var_params, ) async def list_objects(self, body, **kwargs): @@ -1087,7 +882,6 @@ async def list_objects(self, body, **kwargs): returns the request thread. :rtype: ListObjectsResponse """ - kwargs["_return_http_data_only"] = True return await self.list_objects_with_http_info(body, **kwargs) async def list_objects_with_http_info(self, body, **kwargs): @@ -1127,19 +921,7 @@ async def list_objects_with_http_info(self, body, **kwargs): local_var_params = locals() all_params = ["body"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -1148,7 +930,6 @@ async def list_objects_with_http_info(self, body, **kwargs): ) local_var_params[key] = val del local_var_params["kwargs"] - # verify the required parameter 'body' is set if ( self.api_client.client_side_validation and local_var_params.get("body") is None @@ -1156,92 +937,19 @@ async def list_objects_with_http_info(self, body, **kwargs): raise ApiValueError( "Missing the required parameter `body` when calling `list_objects`" ) - - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `list_objects`" ) store_id = self.api_client._get_store_id() - - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - if "body" in local_var_params: - body_params = local_var_params["body"] - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # HTTP header `Content-Type` - content_types_list = local_var_params.get( - "_content_type", - self.api_client.select_header_content_type( - ["application/json"], "POST", body_params - ), - ) - if content_types_list: - header_params["Content-Type"] = content_types_list - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "ListObjectsResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "list_objects", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return await self.api_client.call_api( - "/stores/{store_id}/list-objects".replace("{store_id}", store_id), - "POST", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return await self._execute( + method="POST", + path=f"/stores/{store_id}/list-objects", + operation_name="list_objects", + response_types_map={200: "ListObjectsResponse"}, + body=local_var_params.get("body"), + headers=local_var_params.get("_headers"), + options=local_var_params, ) async def list_stores(self, **kwargs): @@ -1272,7 +980,6 @@ async def list_stores(self, **kwargs): returns the request thread. :rtype: ListStoresResponse """ - kwargs["_return_http_data_only"] = True return await self.list_stores_with_http_info(**kwargs) async def list_stores_with_http_info(self, **kwargs): @@ -1316,19 +1023,7 @@ async def list_stores_with_http_info(self, **kwargs): local_var_params = locals() all_params = ["page_size", "continuation_token", "name"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -1337,13 +1032,6 @@ async def list_stores_with_http_info(self, **kwargs): ) local_var_params[key] = val del local_var_params["kwargs"] - - collection_formats = {} - - path_params = {} - - store_id = None - query_params = [] if local_var_params.get("page_size") is not None: query_params.append(("page_size", local_var_params["page_size"])) @@ -1353,66 +1041,14 @@ async def list_stores_with_http_info(self, **kwargs): ) if local_var_params.get("name") is not None: query_params.append(("name", local_var_params["name"])) - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "ListStoresResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "list_stores", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return await self.api_client.call_api( - "/stores", - "GET", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return await self._execute( + method="GET", + path="/stores", + operation_name="list_stores", + response_types_map={200: "ListStoresResponse"}, + query_params=query_params, + headers=local_var_params.get("_headers"), + options=local_var_params, ) async def list_users(self, body, **kwargs): @@ -1439,7 +1075,6 @@ async def list_users(self, body, **kwargs): returns the request thread. :rtype: ListUsersResponse """ - kwargs["_return_http_data_only"] = True return await self.list_users_with_http_info(body, **kwargs) async def list_users_with_http_info(self, body, **kwargs): @@ -1479,19 +1114,7 @@ async def list_users_with_http_info(self, body, **kwargs): local_var_params = locals() all_params = ["body"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -1500,7 +1123,6 @@ async def list_users_with_http_info(self, body, **kwargs): ) local_var_params[key] = val del local_var_params["kwargs"] - # verify the required parameter 'body' is set if ( self.api_client.client_side_validation and local_var_params.get("body") is None @@ -1508,92 +1130,19 @@ async def list_users_with_http_info(self, body, **kwargs): raise ApiValueError( "Missing the required parameter `body` when calling `list_users`" ) - - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `list_users`" ) store_id = self.api_client._get_store_id() - - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - if "body" in local_var_params: - body_params = local_var_params["body"] - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # HTTP header `Content-Type` - content_types_list = local_var_params.get( - "_content_type", - self.api_client.select_header_content_type( - ["application/json"], "POST", body_params - ), - ) - if content_types_list: - header_params["Content-Type"] = content_types_list - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "ListUsersResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "list_users", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return await self.api_client.call_api( - "/stores/{store_id}/list-users".replace("{store_id}", store_id), - "POST", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return await self._execute( + method="POST", + path=f"/stores/{store_id}/list-users", + operation_name="list_users", + response_types_map={200: "ListUsersResponse"}, + body=local_var_params.get("body"), + headers=local_var_params.get("_headers"), + options=local_var_params, ) async def read(self, body, **kwargs): @@ -1620,7 +1169,6 @@ async def read(self, body, **kwargs): returns the request thread. :rtype: ReadResponse """ - kwargs["_return_http_data_only"] = True return await self.read_with_http_info(body, **kwargs) async def read_with_http_info(self, body, **kwargs): @@ -1660,19 +1208,7 @@ async def read_with_http_info(self, body, **kwargs): local_var_params = locals() all_params = ["body"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -1681,100 +1217,26 @@ async def read_with_http_info(self, body, **kwargs): ) local_var_params[key] = val del local_var_params["kwargs"] - # verify the required parameter 'body' is set if ( - self.api_client.client_side_validation - and local_var_params.get("body") is None - ): - raise ApiValueError( - "Missing the required parameter `body` when calling `read`" - ) - - collection_formats = {} - - path_params = {} - - store_id = None - - if self.api_client._get_store_id() is None: - raise ApiValueError( - "Store ID expected in api_client's configuration when calling `read`" - ) - store_id = self.api_client._get_store_id() - - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - if "body" in local_var_params: - body_params = local_var_params["body"] - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # HTTP header `Content-Type` - content_types_list = local_var_params.get( - "_content_type", - self.api_client.select_header_content_type( - ["application/json"], "POST", body_params - ), - ) - if content_types_list: - header_params["Content-Type"] = content_types_list - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "ReadResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "read", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return await self.api_client.call_api( - "/stores/{store_id}/read".replace("{store_id}", store_id), - "POST", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + self.api_client.client_side_validation + and local_var_params.get("body") is None + ): + raise ApiValueError( + "Missing the required parameter `body` when calling `read`" + ) + if self.api_client._get_store_id() is None: + raise ApiValueError( + "Store ID expected in api_client's configuration when calling `read`" + ) + store_id = self.api_client._get_store_id() + return await self._execute( + method="POST", + path=f"/stores/{store_id}/read", + operation_name="read", + response_types_map={200: "ReadResponse"}, + body=local_var_params.get("body"), + headers=local_var_params.get("_headers"), + options=local_var_params, ) async def read_assertions(self, authorization_model_id, **kwargs): @@ -1801,7 +1263,6 @@ async def read_assertions(self, authorization_model_id, **kwargs): returns the request thread. :rtype: ReadAssertionsResponse """ - kwargs["_return_http_data_only"] = True return await self.read_assertions_with_http_info( authorization_model_id, **kwargs ) @@ -1843,19 +1304,7 @@ async def read_assertions_with_http_info(self, authorization_model_id, **kwargs) local_var_params = locals() all_params = ["authorization_model_id"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -1864,7 +1313,6 @@ async def read_assertions_with_http_info(self, authorization_model_id, **kwargs) ) local_var_params[key] = val del local_var_params["kwargs"] - # verify the required parameter 'authorization_model_id' is set if ( self.api_client.client_side_validation and local_var_params.get("authorization_model_id") is None @@ -1872,87 +1320,18 @@ async def read_assertions_with_http_info(self, authorization_model_id, **kwargs) raise ApiValueError( "Missing the required parameter `authorization_model_id` when calling `read_assertions`" ) - - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `read_assertions`" ) store_id = self.api_client._get_store_id() - - if "authorization_model_id" in local_var_params: - path_params["authorization_model_id"] = local_var_params[ - "authorization_model_id" - ] - - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "ReadAssertionsResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "read_assertions", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return await self.api_client.call_api( - "/stores/{store_id}/assertions/{authorization_model_id}".replace( - "{store_id}", store_id - ), - "GET", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return await self._execute( + method="GET", + path=f"/stores/{store_id}/assertions/{authorization_model_id}", + operation_name="read_assertions", + response_types_map={200: "ReadAssertionsResponse"}, + headers=local_var_params.get("_headers"), + options=local_var_params, ) async def read_authorization_model(self, id, **kwargs): @@ -1979,7 +1358,6 @@ async def read_authorization_model(self, id, **kwargs): returns the request thread. :rtype: ReadAuthorizationModelResponse """ - kwargs["_return_http_data_only"] = True return await self.read_authorization_model_with_http_info(id, **kwargs) async def read_authorization_model_with_http_info(self, id, **kwargs): @@ -2019,19 +1397,7 @@ async def read_authorization_model_with_http_info(self, id, **kwargs): local_var_params = locals() all_params = ["id"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -2040,7 +1406,6 @@ async def read_authorization_model_with_http_info(self, id, **kwargs): ) local_var_params[key] = val del local_var_params["kwargs"] - # verify the required parameter 'id' is set if ( self.api_client.client_side_validation and local_var_params.get("id") is None @@ -2048,85 +1413,18 @@ async def read_authorization_model_with_http_info(self, id, **kwargs): raise ApiValueError( "Missing the required parameter `id` when calling `read_authorization_model`" ) - - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `read_authorization_model`" ) store_id = self.api_client._get_store_id() - - if "id" in local_var_params: - path_params["id"] = local_var_params["id"] - - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "ReadAuthorizationModelResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "read_authorization_model", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return await self.api_client.call_api( - "/stores/{store_id}/authorization-models/{id}".replace( - "{store_id}", store_id - ), - "GET", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return await self._execute( + method="GET", + path=f"/stores/{store_id}/authorization-models/{id}", + operation_name="read_authorization_model", + response_types_map={200: "ReadAuthorizationModelResponse"}, + headers=local_var_params.get("_headers"), + options=local_var_params, ) async def read_authorization_models(self, **kwargs): @@ -2155,7 +1453,6 @@ async def read_authorization_models(self, **kwargs): returns the request thread. :rtype: ReadAuthorizationModelsResponse """ - kwargs["_return_http_data_only"] = True return await self.read_authorization_models_with_http_info(**kwargs) async def read_authorization_models_with_http_info(self, **kwargs): @@ -2197,19 +1494,7 @@ async def read_authorization_models_with_http_info(self, **kwargs): local_var_params = locals() all_params = ["page_size", "continuation_token"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -2218,19 +1503,11 @@ async def read_authorization_models_with_http_info(self, **kwargs): ) local_var_params[key] = val del local_var_params["kwargs"] - - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `read_authorization_models`" ) store_id = self.api_client._get_store_id() - query_params = [] if local_var_params.get("page_size") is not None: query_params.append(("page_size", local_var_params["page_size"])) @@ -2238,66 +1515,14 @@ async def read_authorization_models_with_http_info(self, **kwargs): query_params.append( ("continuation_token", local_var_params["continuation_token"]) ) - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "ReadAuthorizationModelsResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "read_authorization_models", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return await self.api_client.call_api( - "/stores/{store_id}/authorization-models".replace("{store_id}", store_id), - "GET", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return await self._execute( + method="GET", + path=f"/stores/{store_id}/authorization-models", + operation_name="read_authorization_models", + response_types_map={200: "ReadAuthorizationModelsResponse"}, + query_params=query_params, + headers=local_var_params.get("_headers"), + options=local_var_params, ) async def read_changes(self, **kwargs): @@ -2330,7 +1555,6 @@ async def read_changes(self, **kwargs): returns the request thread. :rtype: ReadChangesResponse """ - kwargs["_return_http_data_only"] = True return await self.read_changes_with_http_info(**kwargs) async def read_changes_with_http_info(self, **kwargs): @@ -2376,19 +1600,7 @@ async def read_changes_with_http_info(self, **kwargs): local_var_params = locals() all_params = ["type", "page_size", "continuation_token", "start_time"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -2397,19 +1609,11 @@ async def read_changes_with_http_info(self, **kwargs): ) local_var_params[key] = val del local_var_params["kwargs"] - - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `read_changes`" ) store_id = self.api_client._get_store_id() - query_params = [] if local_var_params.get("type") is not None: query_params.append(("type", local_var_params["type"])) @@ -2421,66 +1625,14 @@ async def read_changes_with_http_info(self, **kwargs): ) if local_var_params.get("start_time") is not None: query_params.append(("start_time", local_var_params["start_time"])) - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "ReadChangesResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "read_changes", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return await self.api_client.call_api( - "/stores/{store_id}/changes".replace("{store_id}", store_id), - "GET", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return await self._execute( + method="GET", + path=f"/stores/{store_id}/changes", + operation_name="read_changes", + response_types_map={200: "ReadChangesResponse"}, + query_params=query_params, + headers=local_var_params.get("_headers"), + options=local_var_params, ) async def streamed_list_objects(self, body, **kwargs): @@ -2507,7 +1659,6 @@ async def streamed_list_objects(self, body, **kwargs): returns the request thread. :rtype: StreamResultOfStreamedListObjectsResponse """ - kwargs["_return_http_data_only"] = True return await self.streamed_list_objects_with_http_info(body, **kwargs) async def streamed_list_objects_with_http_info(self, body, **kwargs): @@ -2547,19 +1698,7 @@ async def streamed_list_objects_with_http_info(self, body, **kwargs): local_var_params = locals() all_params = ["body"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -2568,7 +1707,6 @@ async def streamed_list_objects_with_http_info(self, body, **kwargs): ) local_var_params[key] = val del local_var_params["kwargs"] - # verify the required parameter 'body' is set if ( self.api_client.client_side_validation and local_var_params.get("body") is None @@ -2576,92 +1714,19 @@ async def streamed_list_objects_with_http_info(self, body, **kwargs): raise ApiValueError( "Missing the required parameter `body` when calling `streamed_list_objects`" ) - - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `streamed_list_objects`" ) store_id = self.api_client._get_store_id() - - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - if "body" in local_var_params: - body_params = local_var_params["body"] - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # HTTP header `Content-Type` - content_types_list = local_var_params.get( - "_content_type", - self.api_client.select_header_content_type( - ["application/json"], "POST", body_params - ), - ) - if content_types_list: - header_params["Content-Type"] = content_types_list - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "StreamResultOfStreamedListObjectsResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "streamed_list_objects", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return await self.api_client.call_api( - "/stores/{store_id}/streamed-list-objects".replace("{store_id}", store_id), - "POST", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return await self._execute( + method="POST", + path=f"/stores/{store_id}/streamed-list-objects", + operation_name="streamed_list_objects", + response_types_map={200: "StreamResultOfStreamedListObjectsResponse"}, + body=local_var_params.get("body"), + headers=local_var_params.get("_headers"), + options=local_var_params, ) async def write(self, body, **kwargs): @@ -2688,7 +1753,6 @@ async def write(self, body, **kwargs): returns the request thread. :rtype: object """ - kwargs["_return_http_data_only"] = True return await self.write_with_http_info(body, **kwargs) async def write_with_http_info(self, body, **kwargs): @@ -2728,19 +1792,7 @@ async def write_with_http_info(self, body, **kwargs): local_var_params = locals() all_params = ["body"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -2749,7 +1801,6 @@ async def write_with_http_info(self, body, **kwargs): ) local_var_params[key] = val del local_var_params["kwargs"] - # verify the required parameter 'body' is set if ( self.api_client.client_side_validation and local_var_params.get("body") is None @@ -2757,92 +1808,19 @@ async def write_with_http_info(self, body, **kwargs): raise ApiValueError( "Missing the required parameter `body` when calling `write`" ) - - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `write`" ) store_id = self.api_client._get_store_id() - - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - if "body" in local_var_params: - body_params = local_var_params["body"] - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # HTTP header `Content-Type` - content_types_list = local_var_params.get( - "_content_type", - self.api_client.select_header_content_type( - ["application/json"], "POST", body_params - ), - ) - if content_types_list: - header_params["Content-Type"] = content_types_list - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "object", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "write", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return await self.api_client.call_api( - "/stores/{store_id}/write".replace("{store_id}", store_id), - "POST", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return await self._execute( + method="POST", + path=f"/stores/{store_id}/write", + operation_name="write", + response_types_map={200: "object"}, + body=local_var_params.get("body"), + headers=local_var_params.get("_headers"), + options=local_var_params, ) async def write_assertions(self, authorization_model_id, body, **kwargs): @@ -2871,7 +1849,6 @@ async def write_assertions(self, authorization_model_id, body, **kwargs): returns the request thread. :rtype: None """ - kwargs["_return_http_data_only"] = True return await self.write_assertions_with_http_info( authorization_model_id, body, **kwargs ) @@ -2917,19 +1894,7 @@ async def write_assertions_with_http_info( local_var_params = locals() all_params = ["authorization_model_id", "body"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -2938,7 +1903,6 @@ async def write_assertions_with_http_info( ) local_var_params[key] = val del local_var_params["kwargs"] - # verify the required parameter 'authorization_model_id' is set if ( self.api_client.client_side_validation and local_var_params.get("authorization_model_id") is None @@ -2946,7 +1910,6 @@ async def write_assertions_with_http_info( raise ApiValueError( "Missing the required parameter `authorization_model_id` when calling `write_assertions`" ) - # verify the required parameter 'body' is set if ( self.api_client.client_side_validation and local_var_params.get("body") is None @@ -2954,90 +1917,19 @@ async def write_assertions_with_http_info( raise ApiValueError( "Missing the required parameter `body` when calling `write_assertions`" ) - - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `write_assertions`" ) store_id = self.api_client._get_store_id() - - if "authorization_model_id" in local_var_params: - path_params["authorization_model_id"] = local_var_params[ - "authorization_model_id" - ] - - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - if "body" in local_var_params: - body_params = local_var_params["body"] - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # HTTP header `Content-Type` - content_types_list = local_var_params.get( - "_content_type", - self.api_client.select_header_content_type( - ["application/json"], "PUT", body_params - ), - ) - if content_types_list: - header_params["Content-Type"] = content_types_list - - # Authentication setting - auth_settings = [] - - response_types_map = {} - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "write_assertions", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return await self.api_client.call_api( - "/stores/{store_id}/assertions/{authorization_model_id}".replace( - "{store_id}", store_id - ), - "PUT", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return await self._execute( + method="PUT", + path=f"/stores/{store_id}/assertions/{authorization_model_id}", + operation_name="write_assertions", + response_types_map={}, + body=local_var_params.get("body"), + headers=local_var_params.get("_headers"), + options=local_var_params, ) async def write_authorization_model(self, body, **kwargs): @@ -3064,7 +1956,6 @@ async def write_authorization_model(self, body, **kwargs): returns the request thread. :rtype: WriteAuthorizationModelResponse """ - kwargs["_return_http_data_only"] = True return await self.write_authorization_model_with_http_info(body, **kwargs) async def write_authorization_model_with_http_info(self, body, **kwargs): @@ -3104,19 +1995,7 @@ async def write_authorization_model_with_http_info(self, body, **kwargs): local_var_params = locals() all_params = ["body"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -3125,7 +2004,6 @@ async def write_authorization_model_with_http_info(self, body, **kwargs): ) local_var_params[key] = val del local_var_params["kwargs"] - # verify the required parameter 'body' is set if ( self.api_client.client_side_validation and local_var_params.get("body") is None @@ -3133,90 +2011,17 @@ async def write_authorization_model_with_http_info(self, body, **kwargs): raise ApiValueError( "Missing the required parameter `body` when calling `write_authorization_model`" ) - - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `write_authorization_model`" ) store_id = self.api_client._get_store_id() - - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - if "body" in local_var_params: - body_params = local_var_params["body"] - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # HTTP header `Content-Type` - content_types_list = local_var_params.get( - "_content_type", - self.api_client.select_header_content_type( - ["application/json"], "POST", body_params - ), - ) - if content_types_list: - header_params["Content-Type"] = content_types_list - - # Authentication setting - auth_settings = [] - - response_types_map = { - 201: "WriteAuthorizationModelResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "write_authorization_model", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return await self.api_client.call_api( - "/stores/{store_id}/authorization-models".replace("{store_id}", store_id), - "POST", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return await self._execute( + method="POST", + path=f"/stores/{store_id}/authorization-models", + operation_name="write_authorization_model", + response_types_map={201: "WriteAuthorizationModelResponse"}, + body=local_var_params.get("body"), + headers=local_var_params.get("_headers"), + options=local_var_params, ) diff --git a/openfga_sdk/client/client.py b/openfga_sdk/client/client.py index aba8943..b48a3ec 100644 --- a/openfga_sdk/client/client.py +++ b/openfga_sdk/client/client.py @@ -1,6 +1,9 @@ import asyncio import uuid +from collections.abc import AsyncIterator +from typing import Any + from openfga_sdk.api.open_fga_api import OpenFgaApi from openfga_sdk.api_client import ApiClient from openfga_sdk.client.configuration import ClientConfiguration @@ -25,6 +28,7 @@ from openfga_sdk.client.models.list_objects_request import ClientListObjectsRequest from openfga_sdk.client.models.list_relations_request import ClientListRelationsRequest from openfga_sdk.client.models.list_users_request import ClientListUsersRequest +from openfga_sdk.client.models.raw_response import RawResponse from openfga_sdk.client.models.read_changes_request import ClientReadChangesRequest from openfga_sdk.client.models.tuple import ClientTuple, convert_tuple_keys from openfga_sdk.client.models.write_request import ClientWriteRequest @@ -1096,3 +1100,78 @@ def map_to_assertion(client_assertion: ClientAssertion): authorization_model_id, api_request_body, **kwargs ) return api_response + + ####################### + # Execute API Request + ####################### + async def execute_api_request( + self, + *, + operation_name: str, + method: str, + path: str, + path_params: dict[str, str] | None = None, + body: dict[str, Any] | list[Any] | str | bytes | None = None, + query_params: dict[str, str | int | list[str | int]] | None = None, + headers: dict[str, str] | None = None, + options: dict[str, Any] | None = None, + ) -> RawResponse: + """ + Execute an arbitrary HTTP request to any OpenFGA API endpoint. + + Useful for calling endpoints not yet wrapped by the SDK while + still getting authentication, retries, and error handling. + + :param operation_name: Operation name for telemetry (e.g., "CustomCheck") + :param method: HTTP method (GET, POST, PUT, DELETE, PATCH) + :param path: API path, e.g. "/stores/{store_id}/my-endpoint". + :param path_params: Path parameter substitutions (URL-encoded automatically). + All path parameters, including store_id, must be provided explicitly. + :param body: Request body for POST/PUT/PATCH + :param query_params: Query string parameters + :param headers: Custom headers (SDK enforces Content-Type and Accept) + :param options: Extra options e.g. {"retry_params": RetryParams(max_retry=3)} + :return: RawResponse with status, headers, and body + """ + return await self._api.execute_api_request( + operation_name=operation_name, + method=method, + path=path, + path_params=path_params, + body=body, + query_params=query_params, + headers=headers, + options=options, + ) + + async def execute_streamed_api_request( + self, + *, + operation_name: str, + method: str, + path: str, + path_params: dict[str, str] | None = None, + body: dict[str, Any] | list[Any] | str | bytes | None = None, + query_params: dict[str, str | int | list[str | int]] | None = None, + headers: dict[str, str] | None = None, + options: dict[str, Any] | None = None, + ) -> AsyncIterator[dict[str, Any]]: + """ + Execute an arbitrary HTTP request to a streaming OpenFGA API endpoint. + + Same interface as execute_api_request but for streaming endpoints. + See execute_api_request for full parameter documentation. + + :return: AsyncIterator yielding parsed JSON chunks from the streaming response. + """ + async for chunk in self._api.execute_streamed_api_request( + operation_name=operation_name, + method=method, + path=path, + path_params=path_params, + body=body, + query_params=query_params, + headers=headers, + options=options, + ): + yield chunk diff --git a/openfga_sdk/client/execute_api_request_builder.py b/openfga_sdk/client/execute_api_request_builder.py new file mode 100644 index 0000000..f8ef3d1 --- /dev/null +++ b/openfga_sdk/client/execute_api_request_builder.py @@ -0,0 +1,131 @@ +"""Utilities for execute_api_request: request building, header management, response parsing.""" + +import json +import re +import urllib.parse + +from typing import Any + +from openfga_sdk.exceptions import FgaValidationException + + +class ExecuteApiRequestBuilder: + """Builds and validates parameters for execute_api_request calls.""" + + def __init__( + self, + *, + operation_name: str, + method: str, + path: str, + path_params: dict[str, str] | None = None, + body: dict[str, Any] | list[Any] | str | bytes | None = None, + query_params: dict[str, str | int | list[str | int]] | None = None, + headers: dict[str, str] | None = None, + ): + """Initialize builder with request parameters.""" + self.operation_name = operation_name + self.method = method + self.path = path + self.path_params = path_params + self.body = body + self.query_params = query_params + self.headers = headers + + def validate(self) -> None: + """Validate that all required parameters are present.""" + if not self.operation_name: + raise FgaValidationException( + "operation_name is required for execute_api_request" + ) + if not self.method: + raise FgaValidationException("method is required for execute_api_request") + if not self.path: + raise FgaValidationException("path is required for execute_api_request") + + def build_path(self) -> str: + """Build resource path with parameter substitution from path_params.""" + path = self.path + params = dict(self.path_params) if self.path_params else {} + + result = path + for key, value in params.items(): + placeholder = f"{{{key}}}" + if placeholder in result: + encoded = urllib.parse.quote(str(value), safe="") + result = result.replace(placeholder, encoded) + + # Validate no unresolved params remain + if "{" in result and "}" in result: + match = re.search(r"\{([^}]+)\}", result) + if match: + raise FgaValidationException( + f"Path parameter '{match.group(1)}' not provided for path: {path}. " + "All path parameters must be supplied via path_params." + ) + return result + + def build_query_params_list(self) -> list[tuple[str, str]]: + """Convert query_params dict to list of (key, value) tuples. Expands lists, filters None.""" + if not self.query_params: + return [] + + result = [] + for key, value in self.query_params.items(): + if value is None: + continue + if isinstance(value, list): + result.extend((key, str(item)) for item in value if item is not None) + else: + result.append((key, str(value))) + return result + + def build_headers( + self, + options_headers: dict[str, str] | None = None, + ) -> dict[str, str]: + """ + Merge request headers, options headers, and SDK-enforced defaults. + + SDK always enforces Content-Type and Accept as application/json. + """ + result = dict(self.headers) if self.headers else {} + if options_headers: + result.update(options_headers) + # SDK always enforces these for consistent behavior + result["Content-Type"] = "application/json" + result["Accept"] = "application/json" + return result + + +class ResponseParser: + """Parse raw REST responses into Python types.""" + + @staticmethod + def parse_body( + data: bytes | str | dict[str, Any] | None, + ) -> bytes | str | dict[str, Any] | None: + """Parse response data, attempting JSON deserialization.""" + if data is None: + return None + + if isinstance(data, dict): + return data + + if isinstance(data, str): + try: + return json.loads(data) + except (json.JSONDecodeError, ValueError): + return data + + if isinstance(data, bytes): + try: + decoded = data.decode("utf-8") + try: + return json.loads(decoded) + except (json.JSONDecodeError, ValueError): + return decoded + except UnicodeDecodeError: + return data + + return data diff --git a/openfga_sdk/client/models/__init__.py b/openfga_sdk/client/models/__init__.py index 528d527..2d3cde1 100644 --- a/openfga_sdk/client/models/__init__.py +++ b/openfga_sdk/client/models/__init__.py @@ -12,6 +12,7 @@ from openfga_sdk.client.models.expand_request import ClientExpandRequest from openfga_sdk.client.models.list_objects_request import ClientListObjectsRequest from openfga_sdk.client.models.list_relations_request import ClientListRelationsRequest +from openfga_sdk.client.models.raw_response import RawResponse from openfga_sdk.client.models.read_changes_request import ClientReadChangesRequest from openfga_sdk.client.models.tuple import ClientTuple from openfga_sdk.client.models.write_conflict_opts import ( @@ -45,4 +46,5 @@ "ClientWriteRequestOnMissingDeletes", "ConflictOptions", "ClientWriteOptions", + "RawResponse", ] diff --git a/openfga_sdk/client/models/raw_response.py b/openfga_sdk/client/models/raw_response.py new file mode 100644 index 0000000..e05d47b --- /dev/null +++ b/openfga_sdk/client/models/raw_response.py @@ -0,0 +1,58 @@ +"""Response wrapper for execute_api_request.""" + +import json + +from dataclasses import dataclass +from typing import Any + + +@dataclass +class RawResponse: + """ + Response from execute_api_request / execute_streamed_api_request. + + The body is automatically parsed as JSON if possible, + otherwise returned as a string or bytes. + """ + + status: int + """HTTP status code""" + + headers: dict[str, str] + """Response headers""" + + body: bytes | str | dict[str, Any] | None = None + """Response body (dict if JSON, otherwise str or bytes)""" + + def json(self) -> dict[str, Any] | None: + """ + Return the response body as a parsed JSON dictionary. + + :return: Parsed dict or None + """ + if isinstance(self.body, dict): + return self.body + return None + + def text(self) -> str | None: + """ + Return the response body as a string. + + :return: Body as string, or None + """ + if self.body is None: + return None + + if isinstance(self.body, str): + return self.body + + if isinstance(self.body, bytes): + try: + return self.body.decode("utf-8") + except UnicodeDecodeError: + return self.body.decode("utf-8", errors="replace") + + if isinstance(self.body, dict): + return json.dumps(self.body) + + return str(self.body) diff --git a/openfga_sdk/sync/client/client.py b/openfga_sdk/sync/client/client.py index 1efa33f..c736dae 100644 --- a/openfga_sdk/sync/client/client.py +++ b/openfga_sdk/sync/client/client.py @@ -1,6 +1,8 @@ import uuid +from collections.abc import Iterator from concurrent.futures import ThreadPoolExecutor +from typing import Any from openfga_sdk.client.configuration import ClientConfiguration from openfga_sdk.client.models.assertion import ClientAssertion @@ -24,6 +26,7 @@ from openfga_sdk.client.models.list_objects_request import ClientListObjectsRequest from openfga_sdk.client.models.list_relations_request import ClientListRelationsRequest from openfga_sdk.client.models.list_users_request import ClientListUsersRequest +from openfga_sdk.client.models.raw_response import RawResponse from openfga_sdk.client.models.read_changes_request import ClientReadChangesRequest from openfga_sdk.client.models.tuple import ClientTuple, convert_tuple_keys from openfga_sdk.client.models.write_request import ClientWriteRequest @@ -1095,3 +1098,77 @@ def map_to_assertion(client_assertion: ClientAssertion) -> Assertion: authorization_model_id, api_request_body, **kwargs ) return api_response + + ####################### + # Execute API Request + ####################### + def execute_api_request( + self, + *, + operation_name: str, + method: str, + path: str, + path_params: dict[str, str] | None = None, + body: dict[str, Any] | list[Any] | str | bytes | None = None, + query_params: dict[str, str | int | list[str | int]] | None = None, + headers: dict[str, str] | None = None, + options: dict[str, Any] | None = None, + ) -> RawResponse: + """ + Execute an arbitrary HTTP request to any OpenFGA API endpoint. + + Useful for calling endpoints not yet wrapped by the SDK while + still getting authentication, retries, and error handling. + + :param operation_name: Operation name for telemetry (e.g., "CustomCheck") + :param method: HTTP method (GET, POST, PUT, DELETE, PATCH) + :param path: API path, e.g. "/stores/{store_id}/my-endpoint". + :param path_params: Path parameter substitutions (URL-encoded automatically). + All path parameters, including store_id, must be provided explicitly. + :param body: Request body for POST/PUT/PATCH + :param query_params: Query string parameters + :param headers: Custom headers (SDK enforces Content-Type and Accept) + :param options: Extra options e.g. {"retry_params": RetryParams(max_retry=3)} + :return: RawResponse with status, headers, and body + """ + return self._api.execute_api_request( + operation_name=operation_name, + method=method, + path=path, + path_params=path_params, + body=body, + query_params=query_params, + headers=headers, + options=options, + ) + + def execute_streamed_api_request( + self, + *, + operation_name: str, + method: str, + path: str, + path_params: dict[str, str] | None = None, + body: dict[str, Any] | list[Any] | str | bytes | None = None, + query_params: dict[str, str | int | list[str | int]] | None = None, + headers: dict[str, str] | None = None, + options: dict[str, Any] | None = None, + ) -> Iterator[dict[str, Any]]: + """ + Execute an arbitrary HTTP request to a streaming OpenFGA API endpoint. + + Same interface as execute_api_request but for streaming endpoints. + See execute_api_request for full parameter documentation. + + :return: Iterator yielding parsed JSON chunks from the streaming response. + """ + yield from self._api.execute_streamed_api_request( + operation_name=operation_name, + method=method, + path=path, + path_params=path_params, + body=body, + query_params=query_params, + headers=headers, + options=options, + ) diff --git a/openfga_sdk/sync/client/execute_api_request_builder.py b/openfga_sdk/sync/client/execute_api_request_builder.py new file mode 100644 index 0000000..1da312b --- /dev/null +++ b/openfga_sdk/sync/client/execute_api_request_builder.py @@ -0,0 +1,12 @@ +"""Re-export for sync client.""" + +from openfga_sdk.client.execute_api_request_builder import ( + ExecuteApiRequestBuilder, + ResponseParser, +) + + +__all__ = [ + "ExecuteApiRequestBuilder", + "ResponseParser", +] diff --git a/openfga_sdk/sync/open_fga_api.py b/openfga_sdk/sync/open_fga_api.py index 73b4f80..4244192 100644 --- a/openfga_sdk/sync/open_fga_api.py +++ b/openfga_sdk/sync/open_fga_api.py @@ -10,7 +10,18 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ +from __future__ import annotations + +import urllib.parse + +from collections.abc import Iterator +from typing import TYPE_CHECKING, Any + from openfga_sdk.exceptions import ApiValueError, FgaValidationException + + +if TYPE_CHECKING: + from openfga_sdk.client.models.raw_response import RawResponse from openfga_sdk.sync.api_client import ApiClient from openfga_sdk.sync.oauth2 import OAuth2Client from openfga_sdk.telemetry import Telemetry @@ -24,6 +35,24 @@ class OpenFgaApi: Do not edit the class manually. """ + _COMMON_PARAMS = [ + "async_req", + "_request_timeout", + "_headers", + "_retry_params", + "_streaming", + ] + + _COMMON_ERROR_RESPONSE_TYPES = { + 400: "ValidationErrorMessageResponse", + 401: "UnauthenticatedResponse", + 403: "ForbiddenResponse", + 404: "PathUnknownErrorMessageResponse", + 409: "AbortedMessageResponse", + 422: "UnprocessableContentMessageResponse", + 500: "InternalErrorMessageResponse", + } + def __init__(self, api_client=None): if api_client is None: api_client = ApiClient() @@ -46,6 +75,260 @@ def __exit__(self): def close(self): self.api_client.close() + def _execute( + self, + method: str, + path: str, + operation_name: str, + response_types_map: dict, + body=None, + query_params=None, + headers: dict | None = None, + options: dict | None = None, + ) -> Any: + """Shared executor for all API endpoint methods.""" + if options is None: + options = {} + + header_params = dict(headers or {}) + header_params["Accept"] = self.api_client.select_header_accept( + ["application/json"] + ) + if body is not None: + content_type = self.api_client.select_header_content_type( + ["application/json"], method, body + ) + if content_type: + header_params["Content-Type"] = content_type + + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { + TelemetryAttributes.fga_client_request_method: operation_name, + TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), + TelemetryAttributes.fga_client_request_model_id: options.get( + "authorization_model_id", "" + ), + } + telemetry_attributes = TelemetryAttributes.fromBody( + body=body, attributes=telemetry_attributes + ) + + merged_response_types_map = { + **self._COMMON_ERROR_RESPONSE_TYPES, + **response_types_map, + } + + return self.api_client.call_api( + path, + method, + {}, + query_params or [], + header_params, + body=body, + post_params=[], + files={}, + response_types_map=merged_response_types_map, + auth_settings=[], + async_req=options.get("async_req"), + _return_http_data_only=True, + _preload_content=True, + _request_timeout=options.get("_request_timeout"), + _retry_params=options.get("_retry_params"), + collection_formats={}, + _oauth2_client=self._oauth2_client, + _telemetry_attributes=telemetry_attributes, + _streaming=options.get("_streaming", False), + ) + + def execute_api_request( + self, + *, + operation_name: str, + method: str, + path: str, + path_params: dict[str, str] | None = None, + body: dict[str, Any] | list[Any] | str | bytes | None = None, + query_params: dict[str, str | int | list[str | int]] | None = None, + headers: dict[str, str] | None = None, + options: dict[str, Any] | None = None, + ) -> RawResponse: + """ + Execute an arbitrary HTTP request to any OpenFGA API endpoint. + + Useful for calling endpoints not yet wrapped by the SDK while + still getting authentication, retries, and error handling. + + :param operation_name: Operation name for telemetry (e.g., "CustomCheck") + :param method: HTTP method (GET, POST, PUT, DELETE, PATCH) + :param path: API path, e.g. "/stores/{store_id}/my-endpoint". + :param path_params: Path parameter substitutions (URL-encoded automatically). + All path parameters, including store_id, must be provided explicitly. + :param body: Request body for POST/PUT/PATCH + :param query_params: Query string parameters + :param headers: Custom headers (SDK enforces Content-Type and Accept) + :param options: Extra options e.g. {"retry_params": RetryParams(max_retry=3)} + :return: RawResponse with status, headers, and body + """ + return self._execute_api_request_internal( + operation_name=operation_name, + method=method, + path=path, + path_params=path_params, + body=body, + query_params=query_params, + headers=headers, + options=options, + ) + + def execute_streamed_api_request( + self, + *, + operation_name: str, + method: str, + path: str, + path_params: dict[str, str] | None = None, + body: dict[str, Any] | list[Any] | str | bytes | None = None, + query_params: dict[str, str | int | list[str | int]] | None = None, + headers: dict[str, str] | None = None, + options: dict[str, Any] | None = None, + ) -> Iterator[dict[str, Any]]: + """ + Execute an arbitrary HTTP request to a streaming OpenFGA API endpoint. + + Yields parsed JSON objects as they arrive. Use with for: + + for chunk in api.execute_streamed_api_request(...): + process(chunk) + + :param operation_name: Operation name for telemetry (e.g., "StreamedListObjects") + :param method: HTTP method (GET, POST, PUT, DELETE, PATCH) + :param path: API path, e.g. "/stores/{store_id}/streamed-list-objects". + :param path_params: Path parameter substitutions (URL-encoded automatically). + All path parameters, including store_id, must be provided explicitly. + :param body: Request body for POST/PUT/PATCH + :param query_params: Query string parameters + :param headers: Custom headers (SDK enforces Content-Type and Accept) + :param options: Extra options e.g. {"retry_params": RetryParams(max_retry=3)} + """ + from openfga_sdk.client.execute_api_request_builder import ( + ExecuteApiRequestBuilder, + ) + + builder = ExecuteApiRequestBuilder( + operation_name=operation_name, + method=method, + path=path, + path_params=path_params, + body=body, + query_params=query_params, + headers=headers, + ) + builder.validate() + + resource_path = builder.build_path() + query_params_list = builder.build_query_params_list() + final_headers = builder.build_headers() + + retry_params = options.get("retry_params") if options else None + + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { + TelemetryAttributes.fga_client_request_method: operation_name.lower(), + } + if self.api_client.get_store_id(): + telemetry_attributes[TelemetryAttributes.fga_client_request_store_id] = ( + self.api_client.get_store_id() + ) + + stream = self.api_client.call_api( + resource_path=resource_path, + method=method.upper(), + query_params=query_params_list if query_params_list else None, + header_params=final_headers, + body=body, + response_types_map={}, + auth_settings=[], + _return_http_data_only=True, + _preload_content=True, + _retry_params=retry_params, + _oauth2_client=self._oauth2_client, + _telemetry_attributes=telemetry_attributes, + _streaming=True, + ) + + yield from stream + + def _execute_api_request_internal( + self, + *, + operation_name: str, + method: str, + path: str, + path_params: dict[str, str] | None = None, + body: dict[str, Any] | list[Any] | str | bytes | None = None, + query_params: dict[str, str | int | list[str | int]] | None = None, + headers: dict[str, str] | None = None, + options: dict[str, Any] | None = None, + ) -> RawResponse: + """Implementation for execute_api_request.""" + from openfga_sdk.client.execute_api_request_builder import ( + ExecuteApiRequestBuilder, + ResponseParser, + ) + from openfga_sdk.client.models.raw_response import RawResponse + + builder = ExecuteApiRequestBuilder( + operation_name=operation_name, + method=method, + path=path, + path_params=path_params, + body=body, + query_params=query_params, + headers=headers, + ) + builder.validate() + + resource_path = builder.build_path() + query_params_list = builder.build_query_params_list() + final_headers = builder.build_headers() + + retry_params = options.get("retry_params") if options else None + + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { + TelemetryAttributes.fga_client_request_method: operation_name.lower(), + } + if self.api_client.get_store_id(): + telemetry_attributes[TelemetryAttributes.fga_client_request_store_id] = ( + self.api_client.get_store_id() + ) + + self.api_client.call_api( + resource_path=resource_path, + method=method.upper(), + query_params=query_params_list if query_params_list else None, + header_params=final_headers, + body=body, + response_types_map={}, + auth_settings=[], + _return_http_data_only=True, + _preload_content=True, + _retry_params=retry_params, + _oauth2_client=self._oauth2_client, + _telemetry_attributes=telemetry_attributes, + _streaming=False, + ) + + rest_response = getattr(self.api_client, "last_response", None) + if rest_response is None: + raise RuntimeError( + f"No response for {method.upper()} {resource_path} " + f"(operation: {operation_name})" + ) + + return RawResponse( + status=rest_response.status, + headers=dict(rest_response.getheaders()), + body=ResponseParser.parse_body(rest_response.data), + ) + def batch_check(self, body, **kwargs): """Send a list of `check` operations in a single request @@ -70,7 +353,6 @@ def batch_check(self, body, **kwargs): returns the request thread. :rtype: BatchCheckResponse """ - kwargs["_return_http_data_only"] = True return self.batch_check_with_http_info(body, **kwargs) def batch_check_with_http_info(self, body, **kwargs): @@ -110,19 +392,7 @@ def batch_check_with_http_info(self, body, **kwargs): local_var_params = locals() all_params = ["body"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -140,91 +410,20 @@ def batch_check_with_http_info(self, body, **kwargs): "Missing the required parameter `body` when calling `batch_check`" ) - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `batch_check`" ) store_id = self.api_client._get_store_id() - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - if "body" in local_var_params: - body_params = local_var_params["body"] - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # HTTP header `Content-Type` - content_types_list = local_var_params.get( - "_content_type", - self.api_client.select_header_content_type( - ["application/json"], "POST", body_params - ), - ) - if content_types_list: - header_params["Content-Type"] = content_types_list - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "BatchCheckResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "batch_check", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return self.api_client.call_api( - "/stores/{store_id}/batch-check".replace("{store_id}", store_id), - "POST", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return self._execute( + method="POST", + path=f"/stores/{store_id}/batch-check", + operation_name="batch_check", + response_types_map={200: "BatchCheckResponse"}, + body=local_var_params.get("body"), + headers=local_var_params.get("_headers"), + options=local_var_params, ) def check(self, body, **kwargs): @@ -251,7 +450,6 @@ def check(self, body, **kwargs): returns the request thread. :rtype: CheckResponse """ - kwargs["_return_http_data_only"] = True return self.check_with_http_info(body, **kwargs) def check_with_http_info(self, body, **kwargs): @@ -291,19 +489,7 @@ def check_with_http_info(self, body, **kwargs): local_var_params = locals() all_params = ["body"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -321,91 +507,20 @@ def check_with_http_info(self, body, **kwargs): "Missing the required parameter `body` when calling `check`" ) - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `check`" ) store_id = self.api_client._get_store_id() - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - if "body" in local_var_params: - body_params = local_var_params["body"] - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # HTTP header `Content-Type` - content_types_list = local_var_params.get( - "_content_type", - self.api_client.select_header_content_type( - ["application/json"], "POST", body_params - ), - ) - if content_types_list: - header_params["Content-Type"] = content_types_list - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "CheckResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "check", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return self.api_client.call_api( - "/stores/{store_id}/check".replace("{store_id}", store_id), - "POST", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return self._execute( + method="POST", + path=f"/stores/{store_id}/check", + operation_name="check", + response_types_map={200: "CheckResponse"}, + body=local_var_params.get("body"), + headers=local_var_params.get("_headers"), + options=local_var_params, ) def create_store(self, body, **kwargs): @@ -432,7 +547,6 @@ def create_store(self, body, **kwargs): returns the request thread. :rtype: CreateStoreResponse """ - kwargs["_return_http_data_only"] = True return self.create_store_with_http_info(body, **kwargs) def create_store_with_http_info(self, body, **kwargs): @@ -472,19 +586,7 @@ def create_store_with_http_info(self, body, **kwargs): local_var_params = locals() all_params = ["body"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -494,85 +596,14 @@ def create_store_with_http_info(self, body, **kwargs): local_var_params[key] = val del local_var_params["kwargs"] - collection_formats = {} - - path_params = {} - - store_id = None - - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - if "body" in local_var_params: - body_params = local_var_params["body"] - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # HTTP header `Content-Type` - content_types_list = local_var_params.get( - "_content_type", - self.api_client.select_header_content_type( - ["application/json"], "POST", body_params - ), - ) - if content_types_list: - header_params["Content-Type"] = content_types_list - - # Authentication setting - auth_settings = [] - - response_types_map = { - 201: "CreateStoreResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "create_store", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return self.api_client.call_api( - "/stores", - "POST", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return self._execute( + method="POST", + path="/stores", + operation_name="create_store", + response_types_map={201: "CreateStoreResponse"}, + body=local_var_params.get("body"), + headers=local_var_params.get("_headers"), + options=local_var_params, ) def delete_store(self, **kwargs): @@ -597,7 +628,6 @@ def delete_store(self, **kwargs): returns the request thread. :rtype: None """ - kwargs["_return_http_data_only"] = True return self.delete_store_with_http_info(**kwargs) def delete_store_with_http_info(self, **kwargs): @@ -635,19 +665,7 @@ def delete_store_with_http_info(self, **kwargs): local_var_params = locals() all_params = [] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -657,70 +675,19 @@ def delete_store_with_http_info(self, **kwargs): local_var_params[key] = val del local_var_params["kwargs"] - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `delete_store`" ) store_id = self.api_client._get_store_id() - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # Authentication setting - auth_settings = [] - - response_types_map = {} - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "delete_store", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return self.api_client.call_api( - "/stores/{store_id}".replace("{store_id}", store_id), - "DELETE", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return self._execute( + method="DELETE", + path=f"/stores/{store_id}", + operation_name="delete_store", + response_types_map={}, + headers=local_var_params.get("_headers"), + options=local_var_params, ) def expand(self, body, **kwargs): @@ -747,7 +714,6 @@ def expand(self, body, **kwargs): returns the request thread. :rtype: ExpandResponse """ - kwargs["_return_http_data_only"] = True return self.expand_with_http_info(body, **kwargs) def expand_with_http_info(self, body, **kwargs): @@ -787,19 +753,7 @@ def expand_with_http_info(self, body, **kwargs): local_var_params = locals() all_params = ["body"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -817,91 +771,20 @@ def expand_with_http_info(self, body, **kwargs): "Missing the required parameter `body` when calling `expand`" ) - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `expand`" ) store_id = self.api_client._get_store_id() - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - if "body" in local_var_params: - body_params = local_var_params["body"] - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # HTTP header `Content-Type` - content_types_list = local_var_params.get( - "_content_type", - self.api_client.select_header_content_type( - ["application/json"], "POST", body_params - ), - ) - if content_types_list: - header_params["Content-Type"] = content_types_list - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "ExpandResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "expand", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return self.api_client.call_api( - "/stores/{store_id}/expand".replace("{store_id}", store_id), - "POST", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return self._execute( + method="POST", + path=f"/stores/{store_id}/expand", + operation_name="expand", + response_types_map={200: "ExpandResponse"}, + body=local_var_params.get("body"), + headers=local_var_params.get("_headers"), + options=local_var_params, ) def get_store(self, **kwargs): @@ -926,7 +809,6 @@ def get_store(self, **kwargs): returns the request thread. :rtype: GetStoreResponse """ - kwargs["_return_http_data_only"] = True return self.get_store_with_http_info(**kwargs) def get_store_with_http_info(self, **kwargs): @@ -964,19 +846,7 @@ def get_store_with_http_info(self, **kwargs): local_var_params = locals() all_params = [] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -986,79 +856,19 @@ def get_store_with_http_info(self, **kwargs): local_var_params[key] = val del local_var_params["kwargs"] - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `get_store`" ) store_id = self.api_client._get_store_id() - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "GetStoreResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "get_store", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return self.api_client.call_api( - "/stores/{store_id}".replace("{store_id}", store_id), - "GET", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return self._execute( + method="GET", + path=f"/stores/{store_id}", + operation_name="get_store", + response_types_map={200: "GetStoreResponse"}, + headers=local_var_params.get("_headers"), + options=local_var_params, ) def list_objects(self, body, **kwargs): @@ -1085,7 +895,6 @@ def list_objects(self, body, **kwargs): returns the request thread. :rtype: ListObjectsResponse """ - kwargs["_return_http_data_only"] = True return self.list_objects_with_http_info(body, **kwargs) def list_objects_with_http_info(self, body, **kwargs): @@ -1125,19 +934,7 @@ def list_objects_with_http_info(self, body, **kwargs): local_var_params = locals() all_params = ["body"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -1155,91 +952,20 @@ def list_objects_with_http_info(self, body, **kwargs): "Missing the required parameter `body` when calling `list_objects`" ) - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `list_objects`" ) store_id = self.api_client._get_store_id() - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - if "body" in local_var_params: - body_params = local_var_params["body"] - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # HTTP header `Content-Type` - content_types_list = local_var_params.get( - "_content_type", - self.api_client.select_header_content_type( - ["application/json"], "POST", body_params - ), - ) - if content_types_list: - header_params["Content-Type"] = content_types_list - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "ListObjectsResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "list_objects", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return self.api_client.call_api( - "/stores/{store_id}/list-objects".replace("{store_id}", store_id), - "POST", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return self._execute( + method="POST", + path=f"/stores/{store_id}/list-objects", + operation_name="list_objects", + response_types_map={200: "ListObjectsResponse"}, + body=local_var_params.get("body"), + headers=local_var_params.get("_headers"), + options=local_var_params, ) def list_stores(self, **kwargs): @@ -1270,7 +996,6 @@ def list_stores(self, **kwargs): returns the request thread. :rtype: ListStoresResponse """ - kwargs["_return_http_data_only"] = True return self.list_stores_with_http_info(**kwargs) def list_stores_with_http_info(self, **kwargs): @@ -1314,19 +1039,7 @@ def list_stores_with_http_info(self, **kwargs): local_var_params = locals() all_params = ["page_size", "continuation_token", "name"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -1336,12 +1049,6 @@ def list_stores_with_http_info(self, **kwargs): local_var_params[key] = val del local_var_params["kwargs"] - collection_formats = {} - - path_params = {} - - store_id = None - query_params = [] if local_var_params.get("page_size") is not None: query_params.append(("page_size", local_var_params["page_size"])) @@ -1352,65 +1059,14 @@ def list_stores_with_http_info(self, **kwargs): if local_var_params.get("name") is not None: query_params.append(("name", local_var_params["name"])) - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "ListStoresResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "list_stores", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return self.api_client.call_api( - "/stores", - "GET", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return self._execute( + method="GET", + path="/stores", + operation_name="list_stores", + response_types_map={200: "ListStoresResponse"}, + query_params=query_params, + headers=local_var_params.get("_headers"), + options=local_var_params, ) def list_users(self, body, **kwargs): @@ -1437,7 +1093,6 @@ def list_users(self, body, **kwargs): returns the request thread. :rtype: ListUsersResponse """ - kwargs["_return_http_data_only"] = True return self.list_users_with_http_info(body, **kwargs) def list_users_with_http_info(self, body, **kwargs): @@ -1477,19 +1132,7 @@ def list_users_with_http_info(self, body, **kwargs): local_var_params = locals() all_params = ["body"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -1507,91 +1150,20 @@ def list_users_with_http_info(self, body, **kwargs): "Missing the required parameter `body` when calling `list_users`" ) - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `list_users`" ) - store_id = self.api_client._get_store_id() - - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - if "body" in local_var_params: - body_params = local_var_params["body"] - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # HTTP header `Content-Type` - content_types_list = local_var_params.get( - "_content_type", - self.api_client.select_header_content_type( - ["application/json"], "POST", body_params - ), - ) - if content_types_list: - header_params["Content-Type"] = content_types_list - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "ListUsersResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "list_users", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return self.api_client.call_api( - "/stores/{store_id}/list-users".replace("{store_id}", store_id), - "POST", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + store_id = self.api_client._get_store_id() + + return self._execute( + method="POST", + path=f"/stores/{store_id}/list-users", + operation_name="list_users", + response_types_map={200: "ListUsersResponse"}, + body=local_var_params.get("body"), + headers=local_var_params.get("_headers"), + options=local_var_params, ) def read(self, body, **kwargs): @@ -1618,7 +1190,6 @@ def read(self, body, **kwargs): returns the request thread. :rtype: ReadResponse """ - kwargs["_return_http_data_only"] = True return self.read_with_http_info(body, **kwargs) def read_with_http_info(self, body, **kwargs): @@ -1658,19 +1229,7 @@ def read_with_http_info(self, body, **kwargs): local_var_params = locals() all_params = ["body"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -1688,91 +1247,20 @@ def read_with_http_info(self, body, **kwargs): "Missing the required parameter `body` when calling `read`" ) - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `read`" ) store_id = self.api_client._get_store_id() - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - if "body" in local_var_params: - body_params = local_var_params["body"] - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # HTTP header `Content-Type` - content_types_list = local_var_params.get( - "_content_type", - self.api_client.select_header_content_type( - ["application/json"], "POST", body_params - ), - ) - if content_types_list: - header_params["Content-Type"] = content_types_list - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "ReadResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "read", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return self.api_client.call_api( - "/stores/{store_id}/read".replace("{store_id}", store_id), - "POST", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return self._execute( + method="POST", + path=f"/stores/{store_id}/read", + operation_name="read", + response_types_map={200: "ReadResponse"}, + body=local_var_params.get("body"), + headers=local_var_params.get("_headers"), + options=local_var_params, ) def read_assertions(self, authorization_model_id, **kwargs): @@ -1799,7 +1287,6 @@ def read_assertions(self, authorization_model_id, **kwargs): returns the request thread. :rtype: ReadAssertionsResponse """ - kwargs["_return_http_data_only"] = True return self.read_assertions_with_http_info(authorization_model_id, **kwargs) def read_assertions_with_http_info(self, authorization_model_id, **kwargs): @@ -1839,19 +1326,7 @@ def read_assertions_with_http_info(self, authorization_model_id, **kwargs): local_var_params = locals() all_params = ["authorization_model_id"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -1869,86 +1344,22 @@ def read_assertions_with_http_info(self, authorization_model_id, **kwargs): "Missing the required parameter `authorization_model_id` when calling `read_assertions`" ) - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `read_assertions`" ) store_id = self.api_client._get_store_id() - - if "authorization_model_id" in local_var_params: - path_params["authorization_model_id"] = local_var_params[ - "authorization_model_id" - ] - - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "ReadAssertionsResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "read_assertions", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, + auth_model_id = urllib.parse.quote( + str(local_var_params["authorization_model_id"]), safe="" ) - return self.api_client.call_api( - "/stores/{store_id}/assertions/{authorization_model_id}".replace( - "{store_id}", store_id - ), - "GET", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return self._execute( + method="GET", + path=f"/stores/{store_id}/assertions/{auth_model_id}", + operation_name="read_assertions", + response_types_map={200: "ReadAssertionsResponse"}, + headers=local_var_params.get("_headers"), + options=local_var_params, ) def read_authorization_model(self, id, **kwargs): @@ -1975,7 +1386,6 @@ def read_authorization_model(self, id, **kwargs): returns the request thread. :rtype: ReadAuthorizationModelResponse """ - kwargs["_return_http_data_only"] = True return self.read_authorization_model_with_http_info(id, **kwargs) def read_authorization_model_with_http_info(self, id, **kwargs): @@ -2015,19 +1425,7 @@ def read_authorization_model_with_http_info(self, id, **kwargs): local_var_params = locals() all_params = ["id"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -2045,84 +1443,20 @@ def read_authorization_model_with_http_info(self, id, **kwargs): "Missing the required parameter `id` when calling `read_authorization_model`" ) - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `read_authorization_model`" ) store_id = self.api_client._get_store_id() + model_id = urllib.parse.quote(str(local_var_params["id"]), safe="") - if "id" in local_var_params: - path_params["id"] = local_var_params["id"] - - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "ReadAuthorizationModelResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "read_authorization_model", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return self.api_client.call_api( - "/stores/{store_id}/authorization-models/{id}".replace( - "{store_id}", store_id - ), - "GET", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return self._execute( + method="GET", + path=f"/stores/{store_id}/authorization-models/{model_id}", + operation_name="read_authorization_model", + response_types_map={200: "ReadAuthorizationModelResponse"}, + headers=local_var_params.get("_headers"), + options=local_var_params, ) def read_authorization_models(self, **kwargs): @@ -2151,7 +1485,6 @@ def read_authorization_models(self, **kwargs): returns the request thread. :rtype: ReadAuthorizationModelsResponse """ - kwargs["_return_http_data_only"] = True return self.read_authorization_models_with_http_info(**kwargs) def read_authorization_models_with_http_info(self, **kwargs): @@ -2193,19 +1526,7 @@ def read_authorization_models_with_http_info(self, **kwargs): local_var_params = locals() all_params = ["page_size", "continuation_token"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -2215,12 +1536,6 @@ def read_authorization_models_with_http_info(self, **kwargs): local_var_params[key] = val del local_var_params["kwargs"] - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `read_authorization_models`" @@ -2235,65 +1550,14 @@ def read_authorization_models_with_http_info(self, **kwargs): ("continuation_token", local_var_params["continuation_token"]) ) - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "ReadAuthorizationModelsResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "read_authorization_models", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return self.api_client.call_api( - "/stores/{store_id}/authorization-models".replace("{store_id}", store_id), - "GET", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return self._execute( + method="GET", + path=f"/stores/{store_id}/authorization-models", + operation_name="read_authorization_models", + response_types_map={200: "ReadAuthorizationModelsResponse"}, + query_params=query_params, + headers=local_var_params.get("_headers"), + options=local_var_params, ) def read_changes(self, **kwargs): @@ -2326,7 +1590,6 @@ def read_changes(self, **kwargs): returns the request thread. :rtype: ReadChangesResponse """ - kwargs["_return_http_data_only"] = True return self.read_changes_with_http_info(**kwargs) def read_changes_with_http_info(self, **kwargs): @@ -2372,19 +1635,7 @@ def read_changes_with_http_info(self, **kwargs): local_var_params = locals() all_params = ["type", "page_size", "continuation_token", "start_time"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -2394,12 +1645,6 @@ def read_changes_with_http_info(self, **kwargs): local_var_params[key] = val del local_var_params["kwargs"] - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `read_changes`" @@ -2418,65 +1663,14 @@ def read_changes_with_http_info(self, **kwargs): if local_var_params.get("start_time") is not None: query_params.append(("start_time", local_var_params["start_time"])) - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "ReadChangesResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "read_changes", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return self.api_client.call_api( - "/stores/{store_id}/changes".replace("{store_id}", store_id), - "GET", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return self._execute( + method="GET", + path=f"/stores/{store_id}/changes", + operation_name="read_changes", + response_types_map={200: "ReadChangesResponse"}, + query_params=query_params, + headers=local_var_params.get("_headers"), + options=local_var_params, ) def streamed_list_objects(self, body, **kwargs): @@ -2503,7 +1697,6 @@ def streamed_list_objects(self, body, **kwargs): returns the request thread. :rtype: StreamResultOfStreamedListObjectsResponse """ - kwargs["_return_http_data_only"] = True return self.streamed_list_objects_with_http_info(body, **kwargs) def streamed_list_objects_with_http_info(self, body, **kwargs): @@ -2543,19 +1736,7 @@ def streamed_list_objects_with_http_info(self, body, **kwargs): local_var_params = locals() all_params = ["body"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -2573,91 +1754,20 @@ def streamed_list_objects_with_http_info(self, body, **kwargs): "Missing the required parameter `body` when calling `streamed_list_objects`" ) - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `streamed_list_objects`" ) store_id = self.api_client._get_store_id() - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - if "body" in local_var_params: - body_params = local_var_params["body"] - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # HTTP header `Content-Type` - content_types_list = local_var_params.get( - "_content_type", - self.api_client.select_header_content_type( - ["application/json"], "POST", body_params - ), - ) - if content_types_list: - header_params["Content-Type"] = content_types_list - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "StreamResultOfStreamedListObjectsResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "streamed_list_objects", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return self.api_client.call_api( - "/stores/{store_id}/streamed-list-objects".replace("{store_id}", store_id), - "POST", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return self._execute( + method="POST", + path=f"/stores/{store_id}/streamed-list-objects", + operation_name="streamed_list_objects", + response_types_map={200: "StreamResultOfStreamedListObjectsResponse"}, + body=local_var_params.get("body"), + headers=local_var_params.get("_headers"), + options=local_var_params, ) def write(self, body, **kwargs): @@ -2684,7 +1794,6 @@ def write(self, body, **kwargs): returns the request thread. :rtype: object """ - kwargs["_return_http_data_only"] = True return self.write_with_http_info(body, **kwargs) def write_with_http_info(self, body, **kwargs): @@ -2724,19 +1833,7 @@ def write_with_http_info(self, body, **kwargs): local_var_params = locals() all_params = ["body"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -2754,91 +1851,20 @@ def write_with_http_info(self, body, **kwargs): "Missing the required parameter `body` when calling `write`" ) - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `write`" ) store_id = self.api_client._get_store_id() - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - if "body" in local_var_params: - body_params = local_var_params["body"] - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # HTTP header `Content-Type` - content_types_list = local_var_params.get( - "_content_type", - self.api_client.select_header_content_type( - ["application/json"], "POST", body_params - ), - ) - if content_types_list: - header_params["Content-Type"] = content_types_list - - # Authentication setting - auth_settings = [] - - response_types_map = { - 200: "object", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "write", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return self.api_client.call_api( - "/stores/{store_id}/write".replace("{store_id}", store_id), - "POST", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return self._execute( + method="POST", + path=f"/stores/{store_id}/write", + operation_name="write", + response_types_map={200: "object"}, + body=local_var_params.get("body"), + headers=local_var_params.get("_headers"), + options=local_var_params, ) def write_assertions(self, authorization_model_id, body, **kwargs): @@ -2867,7 +1893,6 @@ def write_assertions(self, authorization_model_id, body, **kwargs): returns the request thread. :rtype: None """ - kwargs["_return_http_data_only"] = True return self.write_assertions_with_http_info( authorization_model_id, body, **kwargs ) @@ -2911,19 +1936,7 @@ def write_assertions_with_http_info(self, authorization_model_id, body, **kwargs local_var_params = locals() all_params = ["authorization_model_id", "body"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -2949,89 +1962,23 @@ def write_assertions_with_http_info(self, authorization_model_id, body, **kwargs "Missing the required parameter `body` when calling `write_assertions`" ) - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `write_assertions`" ) store_id = self.api_client._get_store_id() - - if "authorization_model_id" in local_var_params: - path_params["authorization_model_id"] = local_var_params[ - "authorization_model_id" - ] - - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - if "body" in local_var_params: - body_params = local_var_params["body"] - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] + auth_model_id = urllib.parse.quote( + str(local_var_params["authorization_model_id"]), safe="" ) - # HTTP header `Content-Type` - content_types_list = local_var_params.get( - "_content_type", - self.api_client.select_header_content_type( - ["application/json"], "PUT", body_params - ), - ) - if content_types_list: - header_params["Content-Type"] = content_types_list - - # Authentication setting - auth_settings = [] - - response_types_map = {} - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "write_assertions", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return self.api_client.call_api( - "/stores/{store_id}/assertions/{authorization_model_id}".replace( - "{store_id}", store_id - ), - "PUT", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return self._execute( + method="PUT", + path=f"/stores/{store_id}/assertions/{auth_model_id}", + operation_name="write_assertions", + response_types_map={}, + body=local_var_params.get("body"), + headers=local_var_params.get("_headers"), + options=local_var_params, ) def write_authorization_model(self, body, **kwargs): @@ -3058,7 +2005,6 @@ def write_authorization_model(self, body, **kwargs): returns the request thread. :rtype: WriteAuthorizationModelResponse """ - kwargs["_return_http_data_only"] = True return self.write_authorization_model_with_http_info(body, **kwargs) def write_authorization_model_with_http_info(self, body, **kwargs): @@ -3098,19 +2044,7 @@ def write_authorization_model_with_http_info(self, body, **kwargs): local_var_params = locals() all_params = ["body"] - all_params.extend( - [ - "async_req", - "_return_http_data_only", - "_preload_content", - "_request_timeout", - "_request_auth", - "_content_type", - "_headers", - "_retry_params", - "_streaming", - ] - ) + all_params.extend(self._COMMON_PARAMS) for key, val in local_var_params["kwargs"].items(): if key not in all_params: @@ -3128,89 +2062,18 @@ def write_authorization_model_with_http_info(self, body, **kwargs): "Missing the required parameter `body` when calling `write_authorization_model`" ) - collection_formats = {} - - path_params = {} - - store_id = None - if self.api_client._get_store_id() is None: raise ApiValueError( "Store ID expected in api_client's configuration when calling `write_authorization_model`" ) store_id = self.api_client._get_store_id() - query_params = [] - - header_params = dict(local_var_params.get("_headers", {})) - - form_params = [] - local_var_files = {} - - body_params = None - if "body" in local_var_params: - body_params = local_var_params["body"] - # HTTP header `Accept` - header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] - ) - - # HTTP header `Content-Type` - content_types_list = local_var_params.get( - "_content_type", - self.api_client.select_header_content_type( - ["application/json"], "POST", body_params - ), - ) - if content_types_list: - header_params["Content-Type"] = content_types_list - - # Authentication setting - auth_settings = [] - - response_types_map = { - 201: "WriteAuthorizationModelResponse", - 400: "ValidationErrorMessageResponse", - 401: "UnauthenticatedResponse", - 403: "ForbiddenResponse", - 404: "PathUnknownErrorMessageResponse", - 409: "AbortedMessageResponse", - 422: "UnprocessableContentMessageResponse", - 500: "InternalErrorMessageResponse", - } - - telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { - TelemetryAttributes.fga_client_request_method: "write_authorization_model", - TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), - TelemetryAttributes.fga_client_request_model_id: local_var_params.get( - "authorization_model_id", "" - ), - } - - telemetry_attributes = TelemetryAttributes.fromBody( - body=body_params, - attributes=telemetry_attributes, - ) - - return self.api_client.call_api( - "/stores/{store_id}/authorization-models".replace("{store_id}", store_id), - "POST", - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_types_map=response_types_map, - auth_settings=auth_settings, - async_req=local_var_params.get("async_req"), - _return_http_data_only=local_var_params.get("_return_http_data_only"), - _preload_content=local_var_params.get("_preload_content", True), - _request_timeout=local_var_params.get("_request_timeout"), - _retry_params=local_var_params.get("_retry_params"), - collection_formats=collection_formats, - _request_auth=local_var_params.get("_request_auth"), - _oauth2_client=self._oauth2_client, - _telemetry_attributes=telemetry_attributes, - _streaming=local_var_params.get("_streaming", False), + return self._execute( + method="POST", + path=f"/stores/{store_id}/authorization-models", + operation_name="write_authorization_model", + response_types_map={201: "WriteAuthorizationModelResponse"}, + body=local_var_params.get("body"), + headers=local_var_params.get("_headers"), + options=local_var_params, ) diff --git a/test/client/client_test.py b/test/client/client_test.py index 947134d..5174423 100644 --- a/test/client/client_test.py +++ b/test/client/client_test.py @@ -20,6 +20,7 @@ from openfga_sdk.client.models.list_objects_request import ClientListObjectsRequest from openfga_sdk.client.models.list_relations_request import ClientListRelationsRequest from openfga_sdk.client.models.list_users_request import ClientListUsersRequest +from openfga_sdk.client.models.raw_response import RawResponse from openfga_sdk.client.models.read_changes_request import ClientReadChangesRequest from openfga_sdk.client.models.tuple import ClientTuple from openfga_sdk.client.models.write_request import ClientWriteRequest @@ -3906,12 +3907,17 @@ def client_configuration(): ) -class TestClientConfigurationHeaders: +class TestClientConfigurationHeaders(IsolatedAsyncioTestCase): """Tests for ClientConfiguration headers parameter""" - def test_client_configuration_headers_default_none(self, client_configuration): + def setUp(self): + self.configuration = ClientConfiguration( + api_url="http://api.fga.example", + ) + + def test_client_configuration_headers_default_none(self): """Test that headers default to an empty dict in ClientConfiguration""" - assert client_configuration.headers == {} + assert self.configuration.headers == {} def test_client_configuration_headers_initialization_with_dict(self): """Test initializing ClientConfiguration with headers""" @@ -3936,11 +3942,11 @@ def test_client_configuration_headers_initialization_with_none(self): ) assert config.headers == {} - def test_client_configuration_headers_setter(self, client_configuration): + def test_client_configuration_headers_setter(self): """Test setting headers via property setter""" headers = {"X-Test": "test-value"} - client_configuration.headers = headers - assert client_configuration.headers == headers + self.configuration.headers = headers + assert self.configuration.headers == headers def test_client_configuration_headers_with_authorization_model_id(self): """Test ClientConfiguration with headers and authorization_model_id""" @@ -4165,3 +4171,435 @@ async def test_write_with_conflict_options_both(self, mock_request): _preload_content=ANY, _request_timeout=None, ) + + @patch.object(rest.RESTClientObject, "request") + @pytest.mark.asyncio + async def test_raw_request_post_with_body(self, mock_request): + """Test case for execute_api_request + + Make a POST request with JSON body + """ + response_body = '{"result": "success", "data": {"id": "123"}}' + mock_request.return_value = mock_response(response_body, 200) + + configuration = self.configuration + configuration.store_id = store_id + async with OpenFgaClient(configuration) as api_client: + response = await api_client.execute_api_request( + operation_name="CustomEndpoint", + method="POST", + path="/stores/{store_id}/custom-endpoint", + path_params={"store_id": store_id}, + body={"user": "user:bob", "action": "custom_action"}, + query_params={"page_size": "20"}, + headers={"X-Experimental-Feature": "enabled"}, + ) + + self.assertIsInstance(response, RawResponse) + self.assertEqual(response.status, 200) + self.assertIsNotNone(response.headers) + self.assertIsNotNone(response.body) + self.assertIsInstance(response.body, dict) + self.assertEqual(response.body["result"], "success") + + # Verify response helper methods + json_data = response.json() + self.assertIsNotNone(json_data) + self.assertEqual(json_data["result"], "success") + + text_data = response.text() + self.assertIsNotNone(text_data) + self.assertIn("success", text_data) + + # Verify the API was called with correct parameters + mock_request.assert_called_once_with( + "POST", + "http://api.fga.example/stores/01YCP46JKYM8FJCQ37NMBYHE5X/custom-endpoint", + query_params=[("page_size", "20")], + headers=ANY, + post_params=None, + body={"user": "user:bob", "action": "custom_action"}, + _preload_content=True, + _request_timeout=None, + ) + await api_client.close() + + @patch.object(rest.RESTClientObject, "request") + @pytest.mark.asyncio + async def test_raw_request_get_with_query_params(self, mock_request): + """Test case for execute_api_request + + Make a GET request with query parameters + """ + response_body = ( + '{"stores": [{"id": "01YCP46JKYM8FJCQ37NMBYHE5X", "name": "store1"}]}' + ) + mock_request.return_value = mock_response(response_body, 200) + + configuration = self.configuration + async with OpenFgaClient(configuration) as api_client: + response = await api_client.execute_api_request( + operation_name="ListStores", + method="GET", + path="/stores", + query_params={ + "page_size": 10, + "continuation_token": "eyJwayI6...", + }, + ) + + self.assertIsInstance(response, RawResponse) + self.assertEqual(response.status, 200) + self.assertIsNotNone(response.body) + self.assertIsInstance(response.body, dict) + self.assertIn("stores", response.body) + + # Verify the API was called with correct parameters + mock_request.assert_called_once_with( + "GET", + "http://api.fga.example/stores", + query_params=[ + ("page_size", "10"), + ("continuation_token", "eyJwayI6..."), + ], + headers=ANY, + post_params=None, + body=None, + _preload_content=True, + _request_timeout=None, + ) + await api_client.close() + + @patch.object(rest.RESTClientObject, "request") + @pytest.mark.asyncio + async def test_raw_request_with_path_params(self, mock_request): + """Test case for execute_api_request + + Make a request with path parameters + """ + response_body = '{"authorization_model": {"id": "01G5JAVJ41T49E9TT3SKVS7X1J"}}' + mock_request.return_value = mock_response(response_body, 200) + + configuration = self.configuration + configuration.store_id = store_id + async with OpenFgaClient(configuration) as api_client: + response = await api_client.execute_api_request( + operation_name="ReadAuthorizationModel", + method="GET", + path="/stores/{store_id}/authorization-models/{model_id}", + path_params={ + "store_id": store_id, + "model_id": "01G5JAVJ41T49E9TT3SKVS7X1J", + }, + ) + + self.assertIsInstance(response, RawResponse) + self.assertEqual(response.status, 200) + self.assertIsNotNone(response.body) + + # Verify the API was called with correct path + mock_request.assert_called_once_with( + "GET", + "http://api.fga.example/stores/01YCP46JKYM8FJCQ37NMBYHE5X/authorization-models/01G5JAVJ41T49E9TT3SKVS7X1J", + query_params=None, + headers=ANY, + post_params=None, + body=None, + _preload_content=True, + _request_timeout=None, + ) + await api_client.close() + + @patch.object(rest.RESTClientObject, "request") + @pytest.mark.asyncio + async def test_raw_request_explicit_store_id_in_path_params(self, mock_request): + """Test case for execute_api_request + + Test that store_id must be provided explicitly in path_params + """ + response_body = '{"id": "01YCP46JKYM8FJCQ37NMBYHE5X", "name": "store1"}' + mock_request.return_value = mock_response(response_body, 200) + + configuration = self.configuration + configuration.store_id = store_id + async with OpenFgaClient(configuration) as api_client: + response = await api_client.execute_api_request( + operation_name="GetStore", + method="GET", + path="/stores/{store_id}", + path_params={"store_id": store_id}, + ) + + self.assertIsInstance(response, RawResponse) + self.assertEqual(response.status, 200) + + # Verify store_id was substituted from explicit path_params + mock_request.assert_called_once_with( + "GET", + "http://api.fga.example/stores/01YCP46JKYM8FJCQ37NMBYHE5X", + query_params=None, + headers=ANY, + post_params=None, + body=None, + _preload_content=True, + _request_timeout=None, + ) + await api_client.close() + + @pytest.mark.asyncio + async def test_raw_request_missing_operation_name(self): + """Test case for execute_api_request + + Test that operation_name is required + """ + configuration = self.configuration + configuration.store_id = store_id + async with OpenFgaClient(configuration) as api_client: + with self.assertRaises(FgaValidationException) as error: + await api_client.execute_api_request( + operation_name="", + method="GET", + path="/stores", + ) + self.assertIn("operation_name is required", str(error.exception)) + await api_client.close() + + @pytest.mark.asyncio + async def test_raw_request_missing_store_id(self): + """Test case for execute_api_request + + Test that store_id must be provided in path_params when path contains {store_id} + """ + configuration = self.configuration + async with OpenFgaClient(configuration) as api_client: + with self.assertRaises(FgaValidationException) as error: + await api_client.execute_api_request( + operation_name="GetStore", + method="GET", + path="/stores/{store_id}", + ) + self.assertIn("store_id", str(error.exception)) + await api_client.close() + + @pytest.mark.asyncio + async def test_raw_request_missing_path_params(self): + """Test case for execute_api_request + + Test that all path parameters must be provided + """ + configuration = self.configuration + configuration.store_id = store_id + async with OpenFgaClient(configuration) as api_client: + with self.assertRaises(FgaValidationException) as error: + await api_client.execute_api_request( + operation_name="ReadAuthorizationModel", + method="GET", + path="/stores/{store_id}/authorization-models/{model_id}", + path_params={"store_id": store_id}, + # Missing model_id in path_params + ) + self.assertIn("model_id", str(error.exception)) + await api_client.close() + + @patch.object(rest.RESTClientObject, "request") + @pytest.mark.asyncio + async def test_raw_request_with_list_query_params(self, mock_request): + """Test case for execute_api_request + + Test query parameters with list values + """ + response_body = '{"results": []}' + mock_request.return_value = mock_response(response_body, 200) + + configuration = self.configuration + async with OpenFgaClient(configuration) as api_client: + response = await api_client.execute_api_request( + operation_name="ListStores", + method="GET", + path="/stores", + query_params={"ids": ["id1", "id2", "id3"]}, + ) + + self.assertIsInstance(response, RawResponse) + self.assertEqual(response.status, 200) + + # Verify list query params are expanded + mock_request.assert_called_once_with( + "GET", + "http://api.fga.example/stores", + query_params=[("ids", "id1"), ("ids", "id2"), ("ids", "id3")], + headers=ANY, + post_params=None, + body=None, + _preload_content=True, + _request_timeout=None, + ) + await api_client.close() + + @patch.object(rest.RESTClientObject, "request") + @pytest.mark.asyncio + async def test_raw_request_default_headers(self, mock_request): + """Test case for execute_api_request + + Test that default headers (Content-Type, Accept) are set + """ + response_body = '{"result": "success"}' + mock_request.return_value = mock_response(response_body, 200) + + configuration = self.configuration + configuration.store_id = store_id + async with OpenFgaClient(configuration) as api_client: + response = await api_client.execute_api_request( + operation_name="CustomEndpoint", + method="POST", + path="/stores/{store_id}/custom-endpoint", + path_params={"store_id": store_id}, + body={"test": "data"}, + ) + + self.assertIsInstance(response, RawResponse) + self.assertEqual(response.status, 200) + + # Verify default headers are set + call_args = mock_request.call_args + headers = call_args[1]["headers"] + self.assertEqual(headers.get("Content-Type"), "application/json") + self.assertEqual(headers.get("Accept"), "application/json") + await api_client.close() + + @patch.object(rest.RESTClientObject, "request") + @pytest.mark.asyncio + async def test_raw_request_url_encoded_path_params(self, mock_request): + """Test case for execute_api_request + + Test that path parameters are URL encoded + """ + response_body = '{"result": "success"}' + mock_request.return_value = mock_response(response_body, 200) + + configuration = self.configuration + configuration.store_id = store_id + async with OpenFgaClient(configuration) as api_client: + response = await api_client.execute_api_request( + operation_name="CustomEndpoint", + method="GET", + path="/stores/{store_id}/custom/{param}", + path_params={ + "store_id": store_id, + "param": "value with spaces & special chars", + }, + ) + + self.assertIsInstance(response, RawResponse) + + mock_request.assert_called_once_with( + "GET", + "http://api.fga.example/stores/01YCP46JKYM8FJCQ37NMBYHE5X/custom/value%20with%20spaces%20%26%20special%20chars", + query_params=None, + headers=ANY, + post_params=None, + body=None, + _preload_content=True, + _request_timeout=None, + ) + await api_client.close() + + @patch.object(rest.RESTClientObject, "stream") + @pytest.mark.asyncio + async def test_execute_streamed_api_request_basic(self, mock_stream): + """Test execute_streamed_api_request yields all chunks from the stream.""" + + async def mock_gen(): + yield {"result": {"object": "document:roadmap"}} + yield {"result": {"object": "document:budget"}} + + mock_stream.return_value = mock_gen() + + configuration = self.configuration + configuration.store_id = store_id + async with OpenFgaClient(configuration) as api_client: + chunks = [] + async for chunk in api_client.execute_streamed_api_request( + operation_name="StreamedListObjects", + method="POST", + path="/stores/{store_id}/streamed-list-objects", + path_params={"store_id": store_id}, + body={ + "type": "document", + "relation": "viewer", + "user": "user:anne", + }, + ): + chunks.append(chunk) + + self.assertEqual(len(chunks), 2) + self.assertEqual(chunks[0], {"result": {"object": "document:roadmap"}}) + self.assertEqual(chunks[1], {"result": {"object": "document:budget"}}) + + mock_stream.assert_called_once_with( + "POST", + f"http://api.fga.example/stores/{store_id}/streamed-list-objects", + query_params=None, + headers=ANY, + post_params=None, + body={"type": "document", "relation": "viewer", "user": "user:anne"}, + _request_timeout=None, + ) + await api_client.close() + + @patch.object(rest.RESTClientObject, "stream") + @pytest.mark.asyncio + async def test_execute_streamed_api_request_empty_stream(self, mock_stream): + """Test execute_streamed_api_request handles an empty stream gracefully.""" + + async def mock_gen(): + return + yield # make it an async generator + + mock_stream.return_value = mock_gen() + + configuration = self.configuration + configuration.store_id = store_id + async with OpenFgaClient(configuration) as api_client: + chunks = [] + async for chunk in api_client.execute_streamed_api_request( + operation_name="StreamedListObjects", + method="POST", + path="/stores/{store_id}/streamed-list-objects", + path_params={"store_id": store_id}, + body={"type": "document", "relation": "viewer", "user": "user:nobody"}, + ): + chunks.append(chunk) + + self.assertEqual(len(chunks), 0) + await api_client.close() + + @patch.object(rest.RESTClientObject, "stream") + @pytest.mark.asyncio + async def test_execute_streamed_api_request_path_substitution(self, mock_stream): + """Test execute_streamed_api_request substitutes path params correctly.""" + + async def mock_gen(): + yield {"result": {"object": "document:roadmap"}} + + mock_stream.return_value = mock_gen() + + configuration = self.configuration + async with OpenFgaClient(configuration) as api_client: + chunks = [] + async for chunk in api_client.execute_streamed_api_request( + operation_name="StreamedListObjects", + method="POST", + path="/stores/{store_id}/streamed-list-objects", + path_params={"store_id": store_id}, + body={"type": "document", "relation": "viewer", "user": "user:anne"}, + ): + chunks.append(chunk) + + self.assertEqual(len(chunks), 1) + + # Verify store_id was substituted in the URL + call_args = mock_stream.call_args + self.assertIn(store_id, call_args[0][1]) + self.assertNotIn("{store_id}", call_args[0][1]) + await api_client.close() diff --git a/test/sync/client/client_test.py b/test/sync/client/client_test.py index dbffbd0..f71ac96 100644 --- a/test/sync/client/client_test.py +++ b/test/sync/client/client_test.py @@ -3,7 +3,7 @@ import uuid from datetime import datetime -from unittest import IsolatedAsyncioTestCase +from unittest import IsolatedAsyncioTestCase, TestCase from unittest.mock import ANY, patch import pytest @@ -18,6 +18,7 @@ from openfga_sdk.client.models.list_objects_request import ClientListObjectsRequest from openfga_sdk.client.models.list_relations_request import ClientListRelationsRequest from openfga_sdk.client.models.list_users_request import ClientListUsersRequest +from openfga_sdk.client.models.raw_response import RawResponse from openfga_sdk.client.models.read_changes_request import ClientReadChangesRequest from openfga_sdk.client.models.tuple import ClientTuple from openfga_sdk.client.models.write_request import ClientWriteRequest @@ -3885,12 +3886,19 @@ def client_configuration(): ) -class TestSyncClientConfigurationHeaders: +class TestSyncClientConfigurationHeaders(TestCase): """Tests for ClientConfiguration headers parameter in sync client""" - def test_sync_client_configuration_headers_default_none(self, client_configuration): + def setUp(self): + from openfga_sdk.client.configuration import ClientConfiguration + + self.configuration = ClientConfiguration( + api_url="http://api.fga.example", + ) + + def test_sync_client_configuration_headers_default_none(self): """Test that headers default to an empty dict in ClientConfiguration""" - assert client_configuration.headers == {} + assert self.configuration.headers == {} def test_sync_client_configuration_headers_initialization_with_dict(self): """Test initializing ClientConfiguration with headers""" @@ -3919,11 +3927,11 @@ def test_sync_client_configuration_headers_initialization_with_none(self): ) assert config.headers == {} - def test_sync_client_configuration_headers_setter(self, client_configuration): + def test_sync_client_configuration_headers_setter(self): """Test setting headers via property setter""" headers = {"X-Test": "test-value"} - client_configuration.headers = headers - assert client_configuration.headers == headers + self.configuration.headers = headers + assert self.configuration.headers == headers def test_sync_client_configuration_headers_with_authorization_model_id(self): """Test ClientConfiguration with headers and authorization_model_id""" @@ -4146,3 +4154,428 @@ def test_sync_write_with_conflict_options_both(self, mock_request): _preload_content=ANY, _request_timeout=None, ) + + @patch.object(rest.RESTClientObject, "request") + def test_raw_request_post_with_body(self, mock_request): + """Test case for execute_api_request + + Make a POST request with JSON body + """ + response_body = '{"result": "success", "data": {"id": "123"}}' + mock_request.return_value = mock_response(response_body, 200) + + configuration = self.configuration + configuration.store_id = store_id + with OpenFgaClient(configuration) as api_client: + response = api_client.execute_api_request( + operation_name="CustomEndpoint", + method="POST", + path="/stores/{store_id}/custom-endpoint", + path_params={"store_id": store_id}, + body={"user": "user:bob", "action": "custom_action"}, + query_params={"page_size": "20"}, + headers={"X-Experimental-Feature": "enabled"}, + ) + + self.assertIsInstance(response, RawResponse) + self.assertEqual(response.status, 200) + self.assertIsNotNone(response.headers) + self.assertIsNotNone(response.body) + self.assertIsInstance(response.body, dict) + self.assertEqual(response.body["result"], "success") + + # Verify response helper methods + json_data = response.json() + self.assertIsNotNone(json_data) + self.assertEqual(json_data["result"], "success") + + text_data = response.text() + self.assertIsNotNone(text_data) + self.assertIn("success", text_data) + + # Verify the API was called with correct parameters + mock_request.assert_called_once_with( + "POST", + "http://api.fga.example/stores/01YCP46JKYM8FJCQ37NMBYHE5X/custom-endpoint", + query_params=[("page_size", "20")], + headers=ANY, + post_params=None, + body={"user": "user:bob", "action": "custom_action"}, + _preload_content=True, + _request_timeout=None, + ) + api_client.close() + + @patch.object(rest.RESTClientObject, "request") + def test_raw_request_get_with_query_params(self, mock_request): + """Test case for execute_api_request + + Make a GET request with query parameters + """ + response_body = ( + '{"stores": [{"id": "01YCP46JKYM8FJCQ37NMBYHE5X", "name": "store1"}]}' + ) + mock_request.return_value = mock_response(response_body, 200) + + configuration = self.configuration + with OpenFgaClient(configuration) as api_client: + response = api_client.execute_api_request( + operation_name="ListStores", + method="GET", + path="/stores", + query_params={ + "page_size": 10, + "continuation_token": "eyJwayI6...", + }, + ) + + self.assertIsInstance(response, RawResponse) + self.assertEqual(response.status, 200) + self.assertIsNotNone(response.body) + self.assertIsInstance(response.body, dict) + self.assertIn("stores", response.body) + + # Verify the API was called with correct parameters + mock_request.assert_called_once_with( + "GET", + "http://api.fga.example/stores", + query_params=[ + ("page_size", "10"), + ("continuation_token", "eyJwayI6..."), + ], + headers=ANY, + post_params=None, + body=None, + _preload_content=True, + _request_timeout=None, + ) + api_client.close() + + @patch.object(rest.RESTClientObject, "request") + def test_raw_request_with_path_params(self, mock_request): + """Test case for execute_api_request + + Make a request with path parameters + """ + response_body = '{"authorization_model": {"id": "01G5JAVJ41T49E9TT3SKVS7X1J"}}' + mock_request.return_value = mock_response(response_body, 200) + + configuration = self.configuration + configuration.store_id = store_id + with OpenFgaClient(configuration) as api_client: + response = api_client.execute_api_request( + operation_name="ReadAuthorizationModel", + method="GET", + path="/stores/{store_id}/authorization-models/{model_id}", + path_params={ + "store_id": store_id, + "model_id": "01G5JAVJ41T49E9TT3SKVS7X1J", + }, + ) + + self.assertIsInstance(response, RawResponse) + self.assertEqual(response.status, 200) + self.assertIsNotNone(response.body) + + # Verify the API was called with correct path + mock_request.assert_called_once_with( + "GET", + "http://api.fga.example/stores/01YCP46JKYM8FJCQ37NMBYHE5X/authorization-models/01G5JAVJ41T49E9TT3SKVS7X1J", + query_params=None, + headers=ANY, + post_params=None, + body=None, + _preload_content=True, + _request_timeout=None, + ) + api_client.close() + + @patch.object(rest.RESTClientObject, "request") + def test_raw_request_explicit_store_id_in_path_params(self, mock_request): + """Test case for execute_api_request + + Test that store_id must be provided explicitly in path_params + """ + response_body = '{"id": "01YCP46JKYM8FJCQ37NMBYHE5X", "name": "store1"}' + mock_request.return_value = mock_response(response_body, 200) + + configuration = self.configuration + configuration.store_id = store_id + with OpenFgaClient(configuration) as api_client: + response = api_client.execute_api_request( + operation_name="GetStore", + method="GET", + path="/stores/{store_id}", + path_params={"store_id": store_id}, + ) + + self.assertIsInstance(response, RawResponse) + self.assertEqual(response.status, 200) + + # Verify store_id was substituted from explicit path_params + mock_request.assert_called_once_with( + "GET", + "http://api.fga.example/stores/01YCP46JKYM8FJCQ37NMBYHE5X", + query_params=None, + headers=ANY, + post_params=None, + body=None, + _preload_content=True, + _request_timeout=None, + ) + api_client.close() + + def test_raw_request_missing_operation_name(self): + """Test case for execute_api_request + + Test that operation_name is required + """ + configuration = self.configuration + configuration.store_id = store_id + with OpenFgaClient(configuration) as api_client: + with self.assertRaises(FgaValidationException) as error: + api_client.execute_api_request( + operation_name="", + method="GET", + path="/stores", + ) + self.assertIn("operation_name is required", str(error.exception)) + api_client.close() + + def test_raw_request_missing_store_id(self): + """Test case for execute_api_request + + Test that store_id must be provided in path_params when path contains {store_id} + """ + configuration = self.configuration + with OpenFgaClient(configuration) as api_client: + with self.assertRaises(FgaValidationException) as error: + api_client.execute_api_request( + operation_name="GetStore", + method="GET", + path="/stores/{store_id}", + ) + self.assertIn("store_id", str(error.exception)) + api_client.close() + + def test_raw_request_missing_path_params(self): + """Test case for execute_api_request + + Test that all path parameters must be provided + """ + configuration = self.configuration + configuration.store_id = store_id + with OpenFgaClient(configuration) as api_client: + with self.assertRaises(FgaValidationException) as error: + api_client.execute_api_request( + operation_name="ReadAuthorizationModel", + method="GET", + path="/stores/{store_id}/authorization-models/{model_id}", + path_params={"store_id": store_id}, + # Missing model_id in path_params + ) + self.assertIn("model_id", str(error.exception)) + api_client.close() + + @patch.object(rest.RESTClientObject, "request") + def test_raw_request_with_list_query_params(self, mock_request): + """Test case for execute_api_request + + Test query parameters with list values + """ + response_body = '{"results": []}' + mock_request.return_value = mock_response(response_body, 200) + + configuration = self.configuration + with OpenFgaClient(configuration) as api_client: + response = api_client.execute_api_request( + operation_name="ListStores", + method="GET", + path="/stores", + query_params={"ids": ["id1", "id2", "id3"]}, + ) + + self.assertIsInstance(response, RawResponse) + self.assertEqual(response.status, 200) + + mock_request.assert_called_once_with( + "GET", + "http://api.fga.example/stores", + query_params=[("ids", "id1"), ("ids", "id2"), ("ids", "id3")], + headers=ANY, + post_params=None, + body=None, + _preload_content=True, + _request_timeout=None, + ) + api_client.close() + + @patch.object(rest.RESTClientObject, "request") + def test_raw_request_default_headers(self, mock_request): + """Test case for execute_api_request + + Test that default headers (Content-Type, Accept) are set + """ + response_body = '{"result": "success"}' + mock_request.return_value = mock_response(response_body, 200) + + configuration = self.configuration + configuration.store_id = store_id + with OpenFgaClient(configuration) as api_client: + response = api_client.execute_api_request( + operation_name="CustomEndpoint", + method="POST", + path="/stores/{store_id}/custom-endpoint", + path_params={"store_id": store_id}, + body={"test": "data"}, + ) + + self.assertIsInstance(response, RawResponse) + self.assertEqual(response.status, 200) + + call_args = mock_request.call_args + headers = call_args[1]["headers"] + self.assertEqual(headers.get("Content-Type"), "application/json") + self.assertEqual(headers.get("Accept"), "application/json") + api_client.close() + + @patch.object(rest.RESTClientObject, "request") + def test_raw_request_url_encoded_path_params(self, mock_request): + """Test case for execute_api_request + + Test that path parameters are URL encoded + """ + response_body = '{"result": "success"}' + mock_request.return_value = mock_response(response_body, 200) + + configuration = self.configuration + configuration.store_id = store_id + with OpenFgaClient(configuration) as api_client: + response = api_client.execute_api_request( + operation_name="CustomEndpoint", + method="GET", + path="/stores/{store_id}/custom/{param}", + path_params={ + "store_id": store_id, + "param": "value with spaces & special chars", + }, + ) + + self.assertIsInstance(response, RawResponse) + + mock_request.assert_called_once_with( + "GET", + "http://api.fga.example/stores/01YCP46JKYM8FJCQ37NMBYHE5X/custom/value%20with%20spaces%20%26%20special%20chars", + query_params=None, + headers=ANY, + post_params=None, + body=None, + _preload_content=True, + _request_timeout=None, + ) + api_client.close() + + @patch.object(rest.RESTClientObject, "stream") + def test_execute_streamed_api_request_basic(self, mock_stream): + """Test execute_streamed_api_request yields all chunks from the stream.""" + + def mock_gen(): + yield {"result": {"object": "document:roadmap"}} + yield {"result": {"object": "document:budget"}} + + mock_stream.return_value = mock_gen() + + configuration = self.configuration + configuration.store_id = store_id + with OpenFgaClient(configuration) as api_client: + chunks = list( + api_client.execute_streamed_api_request( + operation_name="StreamedListObjects", + method="POST", + path="/stores/{store_id}/streamed-list-objects", + path_params={"store_id": store_id}, + body={ + "type": "document", + "relation": "viewer", + "user": "user:anne", + }, + ) + ) + + self.assertEqual(len(chunks), 2) + self.assertEqual(chunks[0], {"result": {"object": "document:roadmap"}}) + self.assertEqual(chunks[1], {"result": {"object": "document:budget"}}) + + mock_stream.assert_called_once_with( + "POST", + f"http://api.fga.example/stores/{store_id}/streamed-list-objects", + query_params=None, + headers=ANY, + post_params=None, + body={"type": "document", "relation": "viewer", "user": "user:anne"}, + _request_timeout=None, + ) + api_client.close() + + @patch.object(rest.RESTClientObject, "stream") + def test_execute_streamed_api_request_empty_stream(self, mock_stream): + """Test execute_streamed_api_request handles an empty stream gracefully.""" + + def mock_gen(): + return + yield # make it a generator + + mock_stream.return_value = mock_gen() + + configuration = self.configuration + configuration.store_id = store_id + with OpenFgaClient(configuration) as api_client: + chunks = list( + api_client.execute_streamed_api_request( + operation_name="StreamedListObjects", + method="POST", + path="/stores/{store_id}/streamed-list-objects", + path_params={"store_id": store_id}, + body={ + "type": "document", + "relation": "viewer", + "user": "user:nobody", + }, + ) + ) + + self.assertEqual(len(chunks), 0) + api_client.close() + + @patch.object(rest.RESTClientObject, "stream") + def test_execute_streamed_api_request_path_substitution(self, mock_stream): + """Test execute_streamed_api_request substitutes path params correctly.""" + + def mock_gen(): + yield {"result": {"object": "document:roadmap"}} + + mock_stream.return_value = mock_gen() + + configuration = self.configuration + with OpenFgaClient(configuration) as api_client: + chunks = list( + api_client.execute_streamed_api_request( + operation_name="StreamedListObjects", + method="POST", + path="/stores/{store_id}/streamed-list-objects", + path_params={"store_id": store_id}, + body={ + "type": "document", + "relation": "viewer", + "user": "user:anne", + }, + ) + ) + + self.assertEqual(len(chunks), 1) + + # Verify store_id was substituted in the URL + call_args = mock_stream.call_args + self.assertIn(store_id, call_args[0][1]) + self.assertNotIn("{store_id}", call_args[0][1]) + api_client.close()