diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index c1be427d..dafa967b 100755 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,12 +1,12 @@ lockVersion: 2.0.0 id: 8b5fa338-9106-4734-abf0-e30d67044a90 management: - docChecksum: 774e507b2df4f671362defe668d4d0d6 - docVersion: 1.0.39 - speakeasyVersion: 1.335.0 - generationVersion: 2.370.2 - releaseVersion: 0.24.1 - configChecksum: 7ebed47354cd1fd023aebb9420561b04 + docChecksum: c20db13bfb07ee6d97a80d72980a238c + docVersion: 1.0.41 + speakeasyVersion: 1.346.3 + generationVersion: 2.379.6 + releaseVersion: 0.24.2 + configChecksum: fec8eaa9c3b1e2a9c9a2032679e8c951 repoURL: https://github.com/Unstructured-IO/unstructured-python-client.git repoSubDirectory: . installationURL: https://github.com/Unstructured-IO/unstructured-python-client.git @@ -15,7 +15,7 @@ features: python: additionalDependencies: 0.1.0 constsAndDefaults: 0.1.3 - core: 4.8.1 + core: 4.8.4 examples: 2.81.3 globalSecurity: 2.83.5 globalSecurityCallbacks: 0.1.0 @@ -71,3 +71,4 @@ generatedFiles: - src/unstructured_client/_hooks/sdkhooks.py - src/unstructured_client/_hooks/types.py - src/unstructured_client/_hooks/__init__.py + - CONTRIBUTING.md diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index 709b7c6a..74e2ef29 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -1,9 +1,9 @@ -speakeasyVersion: 1.335.0 +speakeasyVersion: 1.346.3 sources: my-source: sourceNamespace: my-source - sourceRevisionDigest: sha256:f10e0d137f19dffb5d454153726970d685470742c7a8d9371417d497011f39be - sourceBlobDigest: sha256:b90b7b4a3f5ad94dd55e1cbaa47ae166776a377cb529dde2e3f1996f7789dbda + sourceRevisionDigest: sha256:d7d2a055d6ce84bc512e2ef5032d21752490a00ea75a714852cd77d2c9c43042 + sourceBlobDigest: sha256:b7abdf82170bf9e9846b503d31c624fcec0e5d40450496a27461cacda22ca081 tags: - latest - main @@ -11,8 +11,8 @@ targets: unstructured-python: source: my-source sourceNamespace: my-source - sourceRevisionDigest: sha256:f10e0d137f19dffb5d454153726970d685470742c7a8d9371417d497011f39be - sourceBlobDigest: sha256:b90b7b4a3f5ad94dd55e1cbaa47ae166776a377cb529dde2e3f1996f7789dbda + sourceRevisionDigest: sha256:d7d2a055d6ce84bc512e2ef5032d21752490a00ea75a714852cd77d2c9c43042 + sourceBlobDigest: sha256:b7abdf82170bf9e9846b503d31c624fcec0e5d40450496a27461cacda22ca081 outLocation: /github/workspace/repo workflow: workflowVersion: 1.0.0 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..d585717f --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,26 @@ +# Contributing to This Repository + +Thank you for your interest in contributing to this repository. Please note that this repository contains generated code. As such, we do not accept direct changes or pull requests. Instead, we encourage you to follow the guidelines below to report issues and suggest improvements. + +## How to Report Issues + +If you encounter any bugs or have suggestions for improvements, please open an issue on GitHub. When reporting an issue, please provide as much detail as possible to help us reproduce the problem. This includes: + +- A clear and descriptive title +- Steps to reproduce the issue +- Expected and actual behavior +- Any relevant logs, screenshots, or error messages +- Information about your environment (e.g., operating system, software versions) + - For example can be collected using the `npx envinfo` command from your terminal if you have Node.js installed + +## Issue Triage and Upstream Fixes + +We will review and triage issues as quickly as possible. Our goal is to address bugs and incorporate improvements in the upstream source code. Fixes will be included in the next generation of the generated code. + +## Contact + +If you have any questions or need further assistance, please feel free to reach out by opening an issue. + +Thank you for your understanding and cooperation! + +The Maintainers diff --git a/README.md b/README.md index 8f222dec..be4a9d66 100755 --- a/README.md +++ b/README.md @@ -131,11 +131,12 @@ res = s.general.partition(request=operations.PartitionRequest( content='0x2cC94b2FEF'.encode(), file_name='your_file_here', ), + chunking_strategy=shared.ChunkingStrategy.BY_TITLE, split_pdf_page_range=[ 1, 10, ], - strategy=shared.Strategy.AUTO, + strategy=shared.Strategy.HI_RES, ), ), RetryConfig('backoff', BackoffStrategy(1, 50, 1.1, 100), False)) @@ -164,11 +165,12 @@ res = s.general.partition(request=operations.PartitionRequest( content='0x2cC94b2FEF'.encode(), file_name='your_file_here', ), + chunking_strategy=shared.ChunkingStrategy.BY_TITLE, split_pdf_page_range=[ 1, 10, ], - strategy=shared.Strategy.AUTO, + strategy=shared.Strategy.HI_RES, ), )) diff --git a/RELEASES.md b/RELEASES.md index 96acee1b..6a7c4085 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -584,4 +584,14 @@ Based on: ### Generated - [python v0.24.1] . ### Releases -- [PyPI v0.24.1] https://pypi.org/project/unstructured-client/0.24.1 - . \ No newline at end of file +- [PyPI v0.24.1] https://pypi.org/project/unstructured-client/0.24.1 - . + +## 2024-07-29 00:22:26 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.346.3 (2.379.6) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v0.24.2] . +### Releases +- [PyPI v0.24.2] https://pypi.org/project/unstructured-client/0.24.2 - . \ No newline at end of file diff --git a/USAGE.md b/USAGE.md index c58c078b..969b4640 100644 --- a/USAGE.md +++ b/USAGE.md @@ -14,11 +14,12 @@ res = s.general.partition(request=operations.PartitionRequest( content='0x2cC94b2FEF'.encode(), file_name='your_file_here', ), + chunking_strategy=shared.ChunkingStrategy.BY_TITLE, split_pdf_page_range=[ 1, 10, ], - strategy=shared.Strategy.AUTO, + strategy=shared.Strategy.HI_RES, ), )) diff --git a/codeSamples.yaml b/codeSamples.yaml index 4e506972..ffc6c90f 100644 --- a/codeSamples.yaml +++ b/codeSamples.yaml @@ -24,6 +24,7 @@ actions: content='0x2cC94b2FEF'.encode(), ), strategy=shared.Strategy.AUTO, + chunking_strategy=shared.ChunkingStrategy.BASIC, split_pdf_page_range=[ 1, 10, diff --git a/docs/models/shared/partitionparameters.md b/docs/models/shared/partitionparameters.md index 6133821a..ff0c3c1f 100644 --- a/docs/models/shared/partitionparameters.md +++ b/docs/models/shared/partitionparameters.md @@ -6,7 +6,7 @@ | Field | Type | Required | Description | Example | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `files` | [shared.Files](../../models/shared/files.md) | :heavy_check_mark: | The file to extract | | -| `chunking_strategy` | [Optional[shared.ChunkingStrategy]](../../models/shared/chunkingstrategy.md) | :heavy_minus_sign: | Use one of the supported strategies to chunk the returned elements after partitioning. When 'chunking_strategy' is not specified, no chunking is performed and any other chunking parameters provided are ignored. Supported strategies: 'basic', 'by_page', 'by_similarity', or 'by_title' | | +| `chunking_strategy` | [Optional[shared.ChunkingStrategy]](../../models/shared/chunkingstrategy.md) | :heavy_minus_sign: | Use one of the supported strategies to chunk the returned elements after partitioning. When 'chunking_strategy' is not specified, no chunking is performed and any other chunking parameters provided are ignored. Supported strategies: 'basic', 'by_page', 'by_similarity', or 'by_title' | by_title | | `combine_under_n_chars` | *Optional[int]* | :heavy_minus_sign: | If chunking strategy is set, combine elements until a section reaches a length of n chars. Default: 500 | | | `coordinates` | *Optional[bool]* | :heavy_minus_sign: | If `True`, return coordinates for each element extracted via OCR. Default: `False` | | | `encoding` | *Optional[str]* | :heavy_minus_sign: | The encoding method used to decode the text input. Default: utf-8 | | diff --git a/gen.yaml b/gen.yaml index e0c43f34..2fe81b7f 100644 --- a/gen.yaml +++ b/gen.yaml @@ -10,7 +10,7 @@ generation: auth: oAuth2ClientCredentialsEnabled: false python: - version: 0.24.1 + version: 0.24.2 additionalDependencies: dependencies: deepdiff: '>=6.0' diff --git a/setup.py b/setup.py index 57d3206f..2c59e4ef 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" import setuptools import re @@ -19,7 +19,7 @@ setuptools.setup( name='unstructured-client', - version='0.24.1', + version='0.24.2', author='Unstructured', description='Python Client SDK for Unstructured API', license = 'MIT', diff --git a/src/unstructured_client/__init__.py b/src/unstructured_client/__init__.py index e6c0deeb..d8d60c47 100644 --- a/src/unstructured_client/__init__.py +++ b/src/unstructured_client/__init__.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" from .sdk import * from .sdkconfiguration import * diff --git a/src/unstructured_client/_hooks/__init__.py b/src/unstructured_client/_hooks/__init__.py index 5fd985a8..2ee66cdd 100644 --- a/src/unstructured_client/_hooks/__init__.py +++ b/src/unstructured_client/_hooks/__init__.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" from .sdkhooks import * from .types import * diff --git a/src/unstructured_client/_hooks/sdkhooks.py b/src/unstructured_client/_hooks/sdkhooks.py index 17750b62..1fdae95a 100644 --- a/src/unstructured_client/_hooks/sdkhooks.py +++ b/src/unstructured_client/_hooks/sdkhooks.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" import requests from .types import SDKInitHook, BeforeRequestContext, BeforeRequestHook, AfterSuccessContext, AfterSuccessHook, AfterErrorContext, AfterErrorHook, Hooks diff --git a/src/unstructured_client/_hooks/types.py b/src/unstructured_client/_hooks/types.py index b24c1414..72ab059b 100644 --- a/src/unstructured_client/_hooks/types.py +++ b/src/unstructured_client/_hooks/types.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" import requests as requests_http from abc import ABC, abstractmethod diff --git a/src/unstructured_client/general.py b/src/unstructured_client/general.py index 8a942cf1..c6965b5c 100644 --- a/src/unstructured_client/general.py +++ b/src/unstructured_client/general.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" import requests as requests_http from .sdkconfiguration import SDKConfiguration diff --git a/src/unstructured_client/models/__init__.py b/src/unstructured_client/models/__init__.py index 722bb998..97d7cbfd 100644 --- a/src/unstructured_client/models/__init__.py +++ b/src/unstructured_client/models/__init__.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" # package diff --git a/src/unstructured_client/models/errors/__init__.py b/src/unstructured_client/models/errors/__init__.py index 2b2c501f..03839458 100644 --- a/src/unstructured_client/models/errors/__init__.py +++ b/src/unstructured_client/models/errors/__init__.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" from .httpvalidationerror import * from .sdkerror import * diff --git a/src/unstructured_client/models/errors/httpvalidationerror.py b/src/unstructured_client/models/errors/httpvalidationerror.py index cf468c0f..9b943ef5 100644 --- a/src/unstructured_client/models/errors/httpvalidationerror.py +++ b/src/unstructured_client/models/errors/httpvalidationerror.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" from __future__ import annotations import dataclasses diff --git a/src/unstructured_client/models/errors/sdkerror.py b/src/unstructured_client/models/errors/sdkerror.py index 6bb02bbd..2e7ef211 100644 --- a/src/unstructured_client/models/errors/sdkerror.py +++ b/src/unstructured_client/models/errors/sdkerror.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" import requests as requests_http diff --git a/src/unstructured_client/models/errors/servererror.py b/src/unstructured_client/models/errors/servererror.py index 477df745..14e1bd77 100644 --- a/src/unstructured_client/models/errors/servererror.py +++ b/src/unstructured_client/models/errors/servererror.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" from __future__ import annotations import dataclasses diff --git a/src/unstructured_client/models/operations/__init__.py b/src/unstructured_client/models/operations/__init__.py index 9f418731..53ed8933 100644 --- a/src/unstructured_client/models/operations/__init__.py +++ b/src/unstructured_client/models/operations/__init__.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" from .partition import * diff --git a/src/unstructured_client/models/operations/partition.py b/src/unstructured_client/models/operations/partition.py index 262e25c7..cb462c2a 100644 --- a/src/unstructured_client/models/operations/partition.py +++ b/src/unstructured_client/models/operations/partition.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" from __future__ import annotations import dataclasses diff --git a/src/unstructured_client/models/shared/__init__.py b/src/unstructured_client/models/shared/__init__.py index 93e5127f..b6a7718a 100644 --- a/src/unstructured_client/models/shared/__init__.py +++ b/src/unstructured_client/models/shared/__init__.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" from .partition_parameters import * from .security import * diff --git a/src/unstructured_client/models/shared/partition_parameters.py b/src/unstructured_client/models/shared/partition_parameters.py index 7f2fe724..3f155f9e 100644 --- a/src/unstructured_client/models/shared/partition_parameters.py +++ b/src/unstructured_client/models/shared/partition_parameters.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" from __future__ import annotations import dataclasses diff --git a/src/unstructured_client/models/shared/security.py b/src/unstructured_client/models/shared/security.py index 57b7d7fd..df26f743 100644 --- a/src/unstructured_client/models/shared/security.py +++ b/src/unstructured_client/models/shared/security.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" from __future__ import annotations import dataclasses diff --git a/src/unstructured_client/models/shared/validationerror.py b/src/unstructured_client/models/shared/validationerror.py index 62d740b8..a7c35ec2 100644 --- a/src/unstructured_client/models/shared/validationerror.py +++ b/src/unstructured_client/models/shared/validationerror.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" from __future__ import annotations import dataclasses diff --git a/src/unstructured_client/sdk.py b/src/unstructured_client/sdk.py index 399e316c..9ef0ef93 100644 --- a/src/unstructured_client/sdk.py +++ b/src/unstructured_client/sdk.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" import requests as requests_http from .general import General diff --git a/src/unstructured_client/sdkconfiguration.py b/src/unstructured_client/sdkconfiguration.py index 0b4b17e6..4a3fa0d9 100644 --- a/src/unstructured_client/sdkconfiguration.py +++ b/src/unstructured_client/sdkconfiguration.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" import requests as requests_http @@ -10,11 +10,14 @@ from unstructured_client.models import shared +SERVER_SAAS_API = 'saas-api' +r"""Serverless SaaS API""" SERVER_FREE_API = 'free-api' r"""Hosted API Free""" SERVER_DEVELOPMENT = 'development' r"""Development server""" SERVERS = { + SERVER_SAAS_API: 'https://api.unstructuredapp.io', SERVER_FREE_API: 'https://api.unstructured.io', SERVER_DEVELOPMENT: 'http://localhost:8000', } @@ -28,10 +31,10 @@ class SDKConfiguration: server_url: Optional[str] = '' server: Optional[str] = '' language: str = 'python' - openapi_doc_version: str = '1.0.39' - sdk_version: str = '0.24.1' - gen_version: str = '2.370.2' - user_agent: str = 'speakeasy-sdk/python 0.24.1 2.370.2 1.0.39 unstructured-client' + openapi_doc_version: str = '1.0.41' + sdk_version: str = '0.24.2' + gen_version: str = '2.379.6' + user_agent: str = 'speakeasy-sdk/python 0.24.2 2.379.6 1.0.41 unstructured-client' retry_config: Optional[RetryConfig] = None def __post_init__(self): @@ -41,7 +44,7 @@ def get_server_details(self) -> Tuple[str, Dict[str, str]]: if self.server_url is not None and self.server_url != '': return utils.remove_suffix(self.server_url, '/'), {} if not self.server: - self.server = SERVER_FREE_API + self.server = SERVER_SAAS_API if self.server not in SERVERS: raise ValueError(f"Invalid server \"{self.server}\"") diff --git a/src/unstructured_client/utils/__init__.py b/src/unstructured_client/utils/__init__.py index a4fca38b..cbf886a7 100644 --- a/src/unstructured_client/utils/__init__.py +++ b/src/unstructured_client/utils/__init__.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" from .retries import * from .utils import * diff --git a/src/unstructured_client/utils/enums.py b/src/unstructured_client/utils/enums.py index 7e8bc83c..4d3aec17 100644 --- a/src/unstructured_client/utils/enums.py +++ b/src/unstructured_client/utils/enums.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" import enum diff --git a/src/unstructured_client/utils/retries.py b/src/unstructured_client/utils/retries.py index c40fc413..5edae538 100644 --- a/src/unstructured_client/utils/retries.py +++ b/src/unstructured_client/utils/retries.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" import random import time diff --git a/src/unstructured_client/utils/utils.py b/src/unstructured_client/utils/utils.py index 497c3a6e..f21a65d9 100644 --- a/src/unstructured_client/utils/utils.py +++ b/src/unstructured_client/utils/utils.py @@ -1,4 +1,4 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" import base64 import json @@ -410,61 +410,78 @@ def _populate_deep_object_query_params( return if is_dataclass(obj): - obj_fields: Tuple[Field, ...] = fields(obj) - for obj_field in obj_fields: - obj_param_metadata = obj_field.metadata.get("query_param") - if not obj_param_metadata: - continue + _populate_deep_object_query_params_dataclass(metadata.get("field_name", field_name), obj, params) + elif isinstance(obj, Dict): + _populate_deep_object_query_params_dict(metadata.get("field_name", field_name), obj, params) - obj_val = getattr(obj, obj_field.name) - if obj_val is None: - continue - if isinstance(obj_val, List): - for val in obj_val: - if val is None: - continue +def _populate_deep_object_query_params_dataclass( + prior_params_key: str, obj: Any, params: Dict[str, List[str]] +): + if obj is None: + return - if ( - params.get( - f'{metadata.get("field_name", field_name)}[{obj_param_metadata.get("field_name", obj_field.name)}]' - ) - is None - ): - params[ - f'{metadata.get("field_name", field_name)}[{obj_param_metadata.get("field_name", obj_field.name)}]' - ] = [] - - params[ - f'{metadata.get("field_name", field_name)}[{obj_param_metadata.get("field_name", obj_field.name)}]' - ].append(_val_to_string(val)) - else: - params[ - f'{metadata.get("field_name", field_name)}[{obj_param_metadata.get("field_name", obj_field.name)}]' - ] = [_val_to_string(obj_val)] - elif isinstance(obj, Dict): - for key, value in obj.items(): - if value is None: - continue + if not is_dataclass(obj): + return - if isinstance(value, List): - for val in value: - if val is None: - continue + obj_fields: Tuple[Field, ...] = fields(obj) + for obj_field in obj_fields: + obj_param_metadata = obj_field.metadata.get("query_param") + if not obj_param_metadata: + continue - if ( - params.get(f'{metadata.get("field_name", field_name)}[{key}]') - is None - ): - params[f'{metadata.get("field_name", field_name)}[{key}]'] = [] + obj_val = getattr(obj, obj_field.name) + if obj_val is None: + continue - params[f'{metadata.get("field_name", field_name)}[{key}]'].append( - _val_to_string(val) - ) - else: - params[f'{metadata.get("field_name", field_name)}[{key}]'] = [ - _val_to_string(value) - ] + params_key = f'{prior_params_key}[{obj_param_metadata.get("field_name", obj_field.name)}]' + + if is_dataclass(obj_val): + _populate_deep_object_query_params_dataclass(params_key, obj_val, params) + elif isinstance(obj_val, Dict): + _populate_deep_object_query_params_dict(params_key, obj_val, params) + elif isinstance(obj_val, List): + _populate_deep_object_query_params_list(params_key, obj_val, params) + else: + params[params_key] = [_val_to_string(obj_val)] + + +def _populate_deep_object_query_params_dict( + prior_params_key: str, value: Dict, params: Dict[str, List[str]] +): + if value is None: + return + + for key, val in value.items(): + if val is None: + continue + + params_key = f'{prior_params_key}[{key}]' + + if is_dataclass(val): + _populate_deep_object_query_params_dataclass(params_key, val, params) + elif isinstance(val, Dict): + _populate_deep_object_query_params_dict(params_key, val, params) + elif isinstance(val, List): + _populate_deep_object_query_params_list(params_key, val, params) + else: + params[params_key] = [_val_to_string(val)] + + +def _populate_deep_object_query_params_list( + params_key: str, value: List, params: Dict[str, List[str]] +): + if value is None: + return + + for val in value: + if val is None: + continue + + if params.get(params_key) is None: + params[params_key] = [] + + params[params_key].append(_val_to_string(val)) def _get_query_param_field_name(obj_field: Field) -> str: