uipath 2.1.127__py3-none-any.whl → 2.1.128__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of uipath might be problematic. Click here for more details.
- uipath/utils/dynamic_schema.py +68 -51
- {uipath-2.1.127.dist-info → uipath-2.1.128.dist-info}/METADATA +1 -1
- {uipath-2.1.127.dist-info → uipath-2.1.128.dist-info}/RECORD +6 -6
- {uipath-2.1.127.dist-info → uipath-2.1.128.dist-info}/WHEEL +0 -0
- {uipath-2.1.127.dist-info → uipath-2.1.128.dist-info}/entry_points.txt +0 -0
- {uipath-2.1.127.dist-info → uipath-2.1.128.dist-info}/licenses/LICENSE +0 -0
uipath/utils/dynamic_schema.py
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
"""Json schema to dynamic pydantic model."""
|
|
2
2
|
|
|
3
|
-
from
|
|
3
|
+
from enum import Enum
|
|
4
|
+
from typing import Any, Dict, List, Type, Union
|
|
4
5
|
|
|
5
6
|
from pydantic import BaseModel, Field, create_model
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
def jsonschema_to_pydantic(
|
|
9
10
|
schema: dict[str, Any],
|
|
10
|
-
definitions: Optional[dict[str, Any]] = None,
|
|
11
11
|
) -> Type[BaseModel]:
|
|
12
12
|
"""Convert a schema dict to a pydantic model.
|
|
13
13
|
|
|
14
|
-
Modified version of https://github.com/kreneskyp/jsonschema-pydantic to account for
|
|
14
|
+
Modified version of https://github.com/kreneskyp/jsonschema-pydantic to account for three unresolved issues.
|
|
15
|
+
1. Support for title
|
|
16
|
+
2. Better representation of optionals.
|
|
17
|
+
3. Support for optional
|
|
15
18
|
|
|
16
19
|
Args:
|
|
17
20
|
schema: JSON schema.
|
|
@@ -19,25 +22,14 @@ def jsonschema_to_pydantic(
|
|
|
19
22
|
|
|
20
23
|
Returns: Pydantic model.
|
|
21
24
|
"""
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
description = schema.get("description", None)
|
|
26
|
-
|
|
27
|
-
# top level schema provides definitions
|
|
28
|
-
if definitions is None:
|
|
29
|
-
if "$defs" in schema:
|
|
30
|
-
definitions = schema["$defs"]
|
|
31
|
-
elif "definitions" in schema:
|
|
32
|
-
definitions = schema["definitions"]
|
|
33
|
-
else:
|
|
34
|
-
definitions = {}
|
|
25
|
+
dynamic_type_counter = 0
|
|
26
|
+
combined_model_counter = 0
|
|
35
27
|
|
|
36
28
|
def convert_type(prop: dict[str, Any]) -> Any:
|
|
29
|
+
nonlocal dynamic_type_counter, combined_model_counter
|
|
37
30
|
if "$ref" in prop:
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return jsonschema_to_pydantic(ref, definitions)
|
|
31
|
+
# This is the full path. It will be updated in update_forward_refs.
|
|
32
|
+
return prop["$ref"].split("/")[-1].capitalize()
|
|
41
33
|
|
|
42
34
|
if "type" in prop:
|
|
43
35
|
type_mapping = {
|
|
@@ -52,13 +44,55 @@ def jsonschema_to_pydantic(
|
|
|
52
44
|
|
|
53
45
|
type_ = prop["type"]
|
|
54
46
|
|
|
55
|
-
if
|
|
47
|
+
if "enum" in prop:
|
|
48
|
+
dynamic_members = {
|
|
49
|
+
f"KEY_{i}": value for i, value in enumerate(prop["enum"])
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
base_type: Any = type_mapping.get(type_, Any)
|
|
53
|
+
|
|
54
|
+
class DynamicEnum(base_type, Enum):
|
|
55
|
+
pass
|
|
56
|
+
|
|
57
|
+
type_ = DynamicEnum(prop.get("title", "DynamicEnum"), dynamic_members) # type: ignore[call-arg]
|
|
58
|
+
return type_
|
|
59
|
+
elif type_ == "array":
|
|
56
60
|
item_type: Any = convert_type(prop.get("items", {}))
|
|
57
|
-
assert isinstance(item_type, type)
|
|
58
61
|
return List[item_type] # noqa F821
|
|
59
62
|
elif type_ == "object":
|
|
60
63
|
if "properties" in prop:
|
|
61
|
-
|
|
64
|
+
if "title" in prop and prop["title"]:
|
|
65
|
+
title = prop["title"]
|
|
66
|
+
else:
|
|
67
|
+
title = f"DynamicType_{dynamic_type_counter}"
|
|
68
|
+
dynamic_type_counter += 1
|
|
69
|
+
|
|
70
|
+
fields: dict[str, Any] = {}
|
|
71
|
+
required_fields = prop.get("required", [])
|
|
72
|
+
|
|
73
|
+
for name, property in prop.get("properties", {}).items():
|
|
74
|
+
pydantic_type = convert_type(property)
|
|
75
|
+
field_kwargs = {}
|
|
76
|
+
if "default" in property:
|
|
77
|
+
field_kwargs["default"] = property["default"]
|
|
78
|
+
if name not in required_fields:
|
|
79
|
+
# Note that we do not make this optional. This is due to a limitation in Pydantic/Python.
|
|
80
|
+
# If we convert the Optional type back to json schema, it is represented as type | None.
|
|
81
|
+
# pydantic_type = Optional[pydantic_type]
|
|
82
|
+
|
|
83
|
+
if "default" not in field_kwargs:
|
|
84
|
+
field_kwargs["default"] = None
|
|
85
|
+
if "description" in property:
|
|
86
|
+
field_kwargs["description"] = property["description"]
|
|
87
|
+
if "title" in property:
|
|
88
|
+
field_kwargs["title"] = property["title"]
|
|
89
|
+
|
|
90
|
+
fields[name] = (pydantic_type, Field(**field_kwargs))
|
|
91
|
+
|
|
92
|
+
object_model = create_model(title, **fields)
|
|
93
|
+
if "description" in prop:
|
|
94
|
+
object_model.__doc__ = prop["description"]
|
|
95
|
+
return object_model
|
|
62
96
|
else:
|
|
63
97
|
return Dict[str, Any]
|
|
64
98
|
else:
|
|
@@ -67,9 +101,13 @@ def jsonschema_to_pydantic(
|
|
|
67
101
|
elif "allOf" in prop:
|
|
68
102
|
combined_fields = {}
|
|
69
103
|
for sub_schema in prop["allOf"]:
|
|
70
|
-
model =
|
|
104
|
+
model = convert_type(sub_schema)
|
|
71
105
|
combined_fields.update(model.__annotations__)
|
|
72
|
-
|
|
106
|
+
combined_model = create_model(
|
|
107
|
+
f"CombinedModel_{combined_model_counter}", **combined_fields
|
|
108
|
+
)
|
|
109
|
+
combined_model_counter += 1
|
|
110
|
+
return combined_model
|
|
73
111
|
|
|
74
112
|
elif "anyOf" in prop:
|
|
75
113
|
unioned_types = tuple(
|
|
@@ -81,31 +119,10 @@ def jsonschema_to_pydantic(
|
|
|
81
119
|
else:
|
|
82
120
|
raise ValueError(f"Unsupported schema: {prop}")
|
|
83
121
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if "default" in prop:
|
|
91
|
-
field_kwargs["default"] = prop["default"]
|
|
92
|
-
if name not in required_fields:
|
|
93
|
-
# Note that we do not make this optional. This is due to a limitation in Pydantic/Python.
|
|
94
|
-
# If we convert the Optional type back to json schema, it is represented as type | None.
|
|
95
|
-
# pydantic_type = Optional[pydantic_type]
|
|
96
|
-
|
|
97
|
-
if "default" not in field_kwargs:
|
|
98
|
-
field_kwargs["default"] = None
|
|
99
|
-
if "description" in prop:
|
|
100
|
-
field_kwargs["description"] = prop["description"]
|
|
101
|
-
if "title" in prop:
|
|
102
|
-
field_kwargs["title"] = prop["title"]
|
|
103
|
-
|
|
104
|
-
fields[name] = (pydantic_type, Field(**field_kwargs))
|
|
105
|
-
|
|
106
|
-
convert_type(schema.get("properties", {}).get("choices", {}))
|
|
107
|
-
|
|
108
|
-
model = create_model(title, **fields)
|
|
109
|
-
if description:
|
|
110
|
-
model.__doc__ = description
|
|
122
|
+
namespace: dict[str, Any] = {}
|
|
123
|
+
for name, definition in schema.get("$defs", schema.get("definitions", {})).items():
|
|
124
|
+
model = convert_type(definition)
|
|
125
|
+
namespace[name.capitalize()] = model
|
|
126
|
+
model = convert_type(schema)
|
|
127
|
+
model.model_rebuild(force=True, _types_namespace=namespace)
|
|
111
128
|
return model
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: uipath
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.128
|
|
4
4
|
Summary: Python SDK and CLI for UiPath Platform, enabling programmatic interaction with automation services, process management, and deployment tools.
|
|
5
5
|
Project-URL: Homepage, https://uipath.com
|
|
6
6
|
Project-URL: Repository, https://github.com/UiPath/uipath-python
|
|
@@ -223,9 +223,9 @@ uipath/tracing/_traced.py,sha256=VAwEIfDHLx-AZ792SeGxCtOttEJXrLgI0YCkUMbxHsQ,203
|
|
|
223
223
|
uipath/tracing/_utils.py,sha256=emsQRgYu-P1gj1q7XUPJD94mOa12JvhheRkuZJpLd9Y,15051
|
|
224
224
|
uipath/utils/__init__.py,sha256=VD-KXFpF_oWexFg6zyiWMkxl2HM4hYJMIUDZ1UEtGx0,105
|
|
225
225
|
uipath/utils/_endpoints_manager.py,sha256=tnF_FiCx8qI2XaJDQgYkMN_gl9V0VqNR1uX7iawuLp8,8230
|
|
226
|
-
uipath/utils/dynamic_schema.py,sha256=
|
|
227
|
-
uipath-2.1.
|
|
228
|
-
uipath-2.1.
|
|
229
|
-
uipath-2.1.
|
|
230
|
-
uipath-2.1.
|
|
231
|
-
uipath-2.1.
|
|
226
|
+
uipath/utils/dynamic_schema.py,sha256=ahgRLBWzuU0SQilaQVBJfBAVjimq3N3QJ1ztx0U_h2c,4943
|
|
227
|
+
uipath-2.1.128.dist-info/METADATA,sha256=ue_yfY8MlN-zghxuxIlCR7pul3lCbAqL5xmXUMA8oUg,6626
|
|
228
|
+
uipath-2.1.128.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
229
|
+
uipath-2.1.128.dist-info/entry_points.txt,sha256=9C2_29U6Oq1ExFu7usihR-dnfIVNSKc-0EFbh0rskB4,43
|
|
230
|
+
uipath-2.1.128.dist-info/licenses/LICENSE,sha256=-KBavWXepyDjimmzH5fVAsi-6jNVpIKFc2kZs0Ri4ng,1058
|
|
231
|
+
uipath-2.1.128.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|