From 028998aed852c209242595ddcfe90c84e67ce265 Mon Sep 17 00:00:00 2001 From: brandon Date: Thu, 12 Dec 2024 15:41:24 -0800 Subject: [PATCH] regenerating api spec, correcting parameter --- generated/docs/ActionsApi.md | 12 ++++++++++++ generated/docs/ImageQueriesApi.md | 6 +++--- .../api/actions_api.py | 10 ++++++++++ .../api/image_queries_api.py | 10 +++++----- generated/model.py | 2 +- spec/public-api.yaml | 19 ++++++++++++++++++- src/groundlight/experimental_api.py | 15 +++++++++++---- test/unit/test_actions.py | 3 +++ 8 files changed, 63 insertions(+), 14 deletions(-) diff --git a/generated/docs/ActionsApi.md b/generated/docs/ActionsApi.md index f1d5b017..306424fb 100644 --- a/generated/docs/ActionsApi.md +++ b/generated/docs/ActionsApi.md @@ -296,6 +296,8 @@ with groundlight_openapi_client.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = actions_api.ActionsApi(api_client) detector_id = "detector_id_example" # str | + page = 1 # int | A page number within the paginated result set. (optional) + page_size = 1 # int | Number of results to return per page. (optional) # example passing only required values which don't have defaults set try: @@ -303,6 +305,14 @@ with groundlight_openapi_client.ApiClient(configuration) as api_client: pprint(api_response) except groundlight_openapi_client.ApiException as e: print("Exception when calling ActionsApi->list_detector_rules: %s\n" % e) + + # example passing only required values which don't have defaults set + # and optional values + try: + api_response = api_instance.list_detector_rules(detector_id, page=page, page_size=page_size) + pprint(api_response) + except groundlight_openapi_client.ApiException as e: + print("Exception when calling ActionsApi->list_detector_rules: %s\n" % e) ``` @@ -311,6 +321,8 @@ with groundlight_openapi_client.ApiClient(configuration) as api_client: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- **detector_id** | **str**| | + **page** | **int**| A page number within the paginated result set. | [optional] + **page_size** | **int**| Number of results to return per page. | [optional] ### Return type diff --git a/generated/docs/ImageQueriesApi.md b/generated/docs/ImageQueriesApi.md index 47a65ae5..e3f91416 100644 --- a/generated/docs/ImageQueriesApi.md +++ b/generated/docs/ImageQueriesApi.md @@ -201,14 +201,14 @@ configuration.api_key['ApiToken'] = 'YOUR_API_KEY' with groundlight_openapi_client.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = image_queries_api.ImageQueriesApi(api_client) + detector_id = "detector_id_example" # str | Optionally filter image queries by detector ID. (optional) page = 1 # int | A page number within the paginated result set. (optional) page_size = 1 # int | Number of items to return per page. (optional) - predictor_id = "predictor_id_example" # str | Optionally filter image queries by detector ID. (optional) # example passing only required values which don't have defaults set # and optional values try: - api_response = api_instance.list_image_queries(page=page, page_size=page_size, predictor_id=predictor_id) + api_response = api_instance.list_image_queries(detector_id=detector_id, page=page, page_size=page_size) pprint(api_response) except groundlight_openapi_client.ApiException as e: print("Exception when calling ImageQueriesApi->list_image_queries: %s\n" % e) @@ -219,9 +219,9 @@ with groundlight_openapi_client.ApiClient(configuration) as api_client: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- + **detector_id** | **str**| Optionally filter image queries by detector ID. | [optional] **page** | **int**| A page number within the paginated result set. | [optional] **page_size** | **int**| Number of items to return per page. | [optional] - **predictor_id** | **str**| Optionally filter image queries by detector ID. | [optional] ### Return type diff --git a/generated/groundlight_openapi_client/api/actions_api.py b/generated/groundlight_openapi_client/api/actions_api.py index 47ac8d0d..4f9d42f5 100644 --- a/generated/groundlight_openapi_client/api/actions_api.py +++ b/generated/groundlight_openapi_client/api/actions_api.py @@ -173,6 +173,8 @@ def __init__(self, api_client=None): params_map={ "all": [ "detector_id", + "page", + "page_size", ], "required": [ "detector_id", @@ -186,12 +188,18 @@ def __init__(self, api_client=None): "allowed_values": {}, "openapi_types": { "detector_id": (str,), + "page": (int,), + "page_size": (int,), }, "attribute_map": { "detector_id": "detector_id", + "page": "page", + "page_size": "page_size", }, "location_map": { "detector_id": "path", + "page": "query", + "page_size": "query", }, "collection_format_map": {}, }, @@ -434,6 +442,8 @@ def list_detector_rules(self, detector_id, **kwargs): detector_id (str): Keyword Args: + page (int): A page number within the paginated result set.. [optional] + page_size (int): Number of results to return per page.. [optional] _return_http_data_only (bool): response data without head status code and headers. Default is True. _preload_content (bool): if False, the urllib3.HTTPResponse object diff --git a/generated/groundlight_openapi_client/api/image_queries_api.py b/generated/groundlight_openapi_client/api/image_queries_api.py index b25ad772..03ad2600 100644 --- a/generated/groundlight_openapi_client/api/image_queries_api.py +++ b/generated/groundlight_openapi_client/api/image_queries_api.py @@ -127,9 +127,9 @@ def __init__(self, api_client=None): }, params_map={ "all": [ + "detector_id", "page", "page_size", - "predictor_id", ], "required": [], "nullable": [], @@ -140,19 +140,19 @@ def __init__(self, api_client=None): "validations": {}, "allowed_values": {}, "openapi_types": { + "detector_id": (str,), "page": (int,), "page_size": (int,), - "predictor_id": (str,), }, "attribute_map": { + "detector_id": "detector_id", "page": "page", "page_size": "page_size", - "predictor_id": "predictor_id", }, "location_map": { + "detector_id": "query", "page": "query", "page_size": "query", - "predictor_id": "query", }, "collection_format_map": {}, }, @@ -377,9 +377,9 @@ def list_image_queries(self, **kwargs): Keyword Args: + detector_id (str): Optionally filter image queries by detector ID.. [optional] page (int): A page number within the paginated result set.. [optional] page_size (int): Number of items to return per page.. [optional] - predictor_id (str): Optionally filter image queries by detector ID.. [optional] _return_http_data_only (bool): response data without head status code and headers. Default is True. _preload_content (bool): if False, the urllib3.HTTPResponse object diff --git a/generated/model.py b/generated/model.py index 827e7ea1..bf5c9086 100644 --- a/generated/model.py +++ b/generated/model.py @@ -1,6 +1,6 @@ # generated by datamodel-codegen: # filename: public-api.yaml -# timestamp: 2024-12-10T01:13:13+00:00 +# timestamp: 2024-12-12T23:38:24+00:00 from __future__ import annotations diff --git a/spec/public-api.yaml b/spec/public-api.yaml index 89f9f0c0..10ab8471 100644 --- a/spec/public-api.yaml +++ b/spec/public-api.yaml @@ -19,6 +19,18 @@ paths: schema: type: string required: true + - name: page + required: false + in: query + description: A page number within the paginated result set. + schema: + type: integer + - name: page_size + required: false + in: query + description: Number of results to return per page. + schema: + type: integer tags: - actions security: @@ -313,6 +325,11 @@ paths: operationId: List image queries description: Retrieve a list of image-queries. parameters: + - in: query + name: detector_id + schema: + type: string + description: Optionally filter image queries by detector ID. - in: query name: page schema: @@ -1457,4 +1474,4 @@ servers: - url: https://device.positronix.ai/device-api description: Device Prod - url: https://device.integ.positronix.ai/device-api - description: Device Integ \ No newline at end of file + description: Device Integ diff --git a/src/groundlight/experimental_api.py b/src/groundlight/experimental_api.py index b3a687fd..ee8d6ed7 100644 --- a/src/groundlight/experimental_api.py +++ b/src/groundlight/experimental_api.py @@ -214,9 +214,9 @@ def get_rule(self, action_id: int) -> Rule: """ return Rule.model_validate(self.actions_api.get_rule(action_id).to_dict()) - def list_detector_rules(self, detector: Union[str, Detector]) -> List[Rule]: + def list_detector_rules(self, detector: Union[str, Detector], page=1, page_size=10) -> PaginatedRuleList: """ - Gets all rules associated with the given detector. + Gets a paginated list of rules associated with the given detector. **Example usage**:: @@ -224,15 +224,22 @@ def list_detector_rules(self, detector: Union[str, Detector]) -> List[Rule]: # Get all rules for a specific detector rules = gl.list_detector_rules(det_mydetectorid) - for rule in rules: + for rule in rules.results: print(f"Rule {rule.id}: {rule.name}") + # Get next page + next_page = gl.list_detector_rules(det_mydetectorid, page=2) + :param detector: the detector or detector_id to get the rules for + :param page: the page number to retrieve (default: 1) + :param page_size: the number of rules per page (default: 10) :return: a list of Rule objects associated with the given detector """ if isinstance(detector, Detector): detector = detector.id - return [Rule.model_validate(rule.to_dict()) for rule in self.actions_api.list_detector_rules(detector)] + return PaginatedRuleList.parse_obj( + self.actions_api.list_detector_rules(detector, page=page, page_size=page_size).to_dict() + ) def delete_rule(self, action_id: int) -> None: """ diff --git a/test/unit/test_actions.py b/test/unit/test_actions.py index 6f014b46..3c1b9eec 100644 --- a/test/unit/test_actions.py +++ b/test/unit/test_actions.py @@ -33,6 +33,9 @@ def test_delete_actions(gl_experimental: ExperimentalApi): det = gl_experimental.get_or_create_detector(name, "test_query") for i in range(num_test_rules): _ = gl_experimental.create_rule(det, f"test_rule_{i}", "EMAIL", "test@example.com") + import IPython + + IPython.embed() rules = gl_experimental.list_detector_rules(det.id) assert rules.count == num_test_rules gl_experimental.delete_all_rules(det.id)