diff --git a/CHANGELOG.md b/CHANGELOG.md index f8047ec..742dacc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.0.17 + +* **Bugfix supporting list union types in response** + ## 0.0.16 * **Bugfix for file data deserialization** diff --git a/test/api/test_api.py b/test/api/test_api.py index fcc06b1..936c93f 100644 --- a/test/api/test_api.py +++ b/test/api/test_api.py @@ -38,15 +38,9 @@ def generic_validation(self): ] -@pytest.fixture -def file_data() -> FileData: - return FileData( - identifier="mock file data", - connector_type="CON", - source_identifiers=SourceIdentifiers(filename="n", fullpath="n"), - ) - - +@pytest.mark.parametrize( + "file_data", mock_file_data, ids=[type(fd).__name__ for fd in mock_file_data] +) def test_async_sample_function(file_data): from test.assets.async_typed_dict_response import async_sample_function as test_fn @@ -62,6 +56,9 @@ def test_async_sample_function(file_data): assert output == {"response": {"a_out": 1, "b_out": 2}} +@pytest.mark.parametrize( + "file_data", mock_file_data, ids=[type(fd).__name__ for fd in mock_file_data] +) def test_dataclass_response(file_data): from test.assets.dataclass_response import sample_function_with_path as test_fn @@ -85,6 +82,9 @@ def test_dataclass_response(file_data): } +@pytest.mark.parametrize( + "file_data", mock_file_data, ids=[type(fd).__name__ for fd in mock_file_data] +) def test_empty_input_and_output(file_data): from test.assets.empty_input_and_response import SampleClass as TestClass @@ -99,6 +99,9 @@ def test_empty_input_and_output(file_data): assert not output +@pytest.mark.parametrize( + "file_data", mock_file_data, ids=[type(fd).__name__ for fd in mock_file_data] +) def test_filedata_meta(file_data): from test.assets.filedata_meta import Input from test.assets.filedata_meta import process_input as test_fn diff --git a/test/assets/dataclass_response.py b/test/assets/dataclass_response.py index 03e059e..02ddbac 100644 --- a/test/assets/dataclass_response.py +++ b/test/assets/dataclass_response.py @@ -1,6 +1,6 @@ from dataclasses import dataclass from pathlib import Path -from typing import Any, Optional, TypedDict +from typing import Any, Optional, TypedDict, Union from unstructured_ingest.v2.interfaces import BatchFileData, FileData @@ -26,7 +26,7 @@ class SampleFunctionWithPathResponse: def sample_function_with_path( - file_data: FileData, b: str, c: int, a: Optional[Path] = None + file_data: Union[FileData, BatchFileData], b: str, c: int, a: Optional[Path] = None ) -> SampleFunctionWithPathResponse: s: list[Any] = [type(a).__name__, f"[exists: {a.exists()}]", a.resolve()] if a else [] s.extend([b, c]) diff --git a/unstructured_platform_plugins/__version__.py b/unstructured_platform_plugins/__version__.py index fe2619d..a3d1684 100644 --- a/unstructured_platform_plugins/__version__.py +++ b/unstructured_platform_plugins/__version__.py @@ -1 +1 @@ -__version__ = "0.0.16" # pragma: no cover +__version__ = "0.0.17" # pragma: no cover diff --git a/unstructured_platform_plugins/schema/json_schema.py b/unstructured_platform_plugins/schema/json_schema.py index cba6062..38ccf68 100644 --- a/unstructured_platform_plugins/schema/json_schema.py +++ b/unstructured_platform_plugins/schema/json_schema.py @@ -307,11 +307,20 @@ def schema_to_base_model_type(json_type_name, name: str, type_info: dict) -> Typ t = dict[key_subtype, value_subtype] if t is list and "items" in type_info and isinstance(type_info["items"], dict): items = type_info["items"] - item_type_name = items["type"] - subtype = schema_to_base_model_type( - json_type_name=item_type_name, name=f"{name}_type", type_info=items - ) - t = list[subtype] + if "anyOf" in items: + subtype_info = [ + schema_to_base_model_type( + json_type_name=k["type"], name=f"{k}_{index}_type", type_info=k + ) + for index, k in enumerate(items["anyOf"]) + ] + t = _UnionGenericAlias(Union, tuple(subtype_info)) + else: + item_type_name = items["type"] + subtype = schema_to_base_model_type( + json_type_name=item_type_name, name=f"{name}_type", type_info=items + ) + t = list[subtype] if "enum" in type_info and isinstance(type_info["enum"], list): enum_content = type_info["enum"] t = Enum(f"{name}_enum", {v: v for v in enum_content})