Skip to content

Commit 5d55088

Browse files
committed
pojo sync poc - with @DataClass
1 parent 07c38ec commit 5d55088

6 files changed

Lines changed: 215 additions & 66 deletions

File tree

src/conductor/client/http/models/action.py

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import pprint
22
import re # noqa: F401
3+
from dataclasses import dataclass, field, InitVar
4+
from typing import Optional, Dict, List, Any, Union
5+
from deprecated import deprecated
36

47
import six
58

69

7-
class Action(object):
10+
@dataclass
11+
class Action:
812
"""NOTE: This class is auto generated by the swagger code generator program.
913
1014
Do not edit the class manually.
@@ -16,25 +20,46 @@ class Action(object):
1620
attribute_map (dict): The key is attribute name
1721
and the value is json key in definition.
1822
"""
19-
swagger_types = {
23+
# Initialize private fields
24+
_action: Optional[str] = field(default=None, init=False)
25+
_start_workflow: Any = field(default=None, init=False)
26+
_complete_task: Any = field(default=None, init=False)
27+
_fail_task: Any = field(default=None, init=False)
28+
_expand_inline_json: Optional[bool] = field(default=None, init=False)
29+
_terminate_workflow: Any = field(default=None, init=False)
30+
_update_workflow_variables: Any = field(default=None, init=False)
31+
32+
# Init variables for backward compatibility
33+
action: InitVar[Optional[str]] = None
34+
start_workflow: InitVar[Any] = None
35+
complete_task: InitVar[Any] = None
36+
fail_task: InitVar[Any] = None
37+
expand_inline_json: InitVar[Optional[bool]] = None
38+
terminate_workflow: InitVar[Any] = None
39+
update_workflow_variables: InitVar[Any] = None
40+
41+
# Class variables
42+
swagger_types: Dict[str, str] = field(default_factory=lambda: {
2043
'action': 'str',
2144
'start_workflow': 'StartWorkflowRequest',
2245
'complete_task': 'TaskDetails',
2346
'fail_task': 'TaskDetails',
2447
'expand_inline_json': 'bool',
2548
'terminate_workflow': 'TerminateWorkflow',
2649
'update_workflow_variables': 'UpdateWorkflowVariables'
27-
}
50+
})
2851

29-
attribute_map = {
52+
attribute_map: Dict[str, str] = field(default_factory=lambda: {
3053
'action': 'action',
3154
'start_workflow': 'start_workflow',
3255
'complete_task': 'complete_task',
3356
'fail_task': 'fail_task',
3457
'expand_inline_json': 'expandInlineJSON',
3558
'terminate_workflow': 'terminate_workflow',
3659
'update_workflow_variables': 'update_workflow_variables'
37-
}
60+
})
61+
62+
discriminator = None
3863

3964
def __init__(self, action=None, start_workflow=None, complete_task=None, fail_task=None,
4065
expand_inline_json=None, terminate_workflow=None, update_workflow_variables=None): # noqa: E501
@@ -62,6 +87,24 @@ def __init__(self, action=None, start_workflow=None, complete_task=None, fail_ta
6287
if update_workflow_variables is not None:
6388
self.update_workflow_variables = update_workflow_variables
6489

90+
def __post_init__(self, action, start_workflow, complete_task, fail_task,
91+
expand_inline_json, terminate_workflow, update_workflow_variables):
92+
"""Handle initialization for dataclass compatibility"""
93+
if action is not None:
94+
self.action = action
95+
if start_workflow is not None:
96+
self.start_workflow = start_workflow
97+
if complete_task is not None:
98+
self.complete_task = complete_task
99+
if fail_task is not None:
100+
self.fail_task = fail_task
101+
if expand_inline_json is not None:
102+
self.expand_inline_json = expand_inline_json
103+
if terminate_workflow is not None:
104+
self.terminate_workflow = terminate_workflow
105+
if update_workflow_variables is not None:
106+
self.update_workflow_variables = update_workflow_variables
107+
65108
@property
66109
def action(self):
67110
"""Gets the action of this Action. # noqa: E501
@@ -80,7 +123,8 @@ def action(self, action):
80123
:param action: The action of this Action. # noqa: E501
81124
:type: str
82125
"""
83-
allowed_values = ["start_workflow", "complete_task", "fail_task", "terminate_workflow", "update_workflow_variables"] # noqa: E501
126+
allowed_values = ["start_workflow", "complete_task", "fail_task", "terminate_workflow",
127+
"update_workflow_variables"] # noqa: E501
84128
if action not in allowed_values:
85129
raise ValueError(
86130
"Invalid value for `action` ({0}), must be one of {1}" # noqa: E501

src/conductor/client/http/models/authorization_request.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import pprint
22
import re # noqa: F401
3-
3+
from dataclasses import dataclass, field, InitVar
4+
from typing import List, Optional, Dict, Any
45
import six
6+
from deprecated import deprecated
57

68

7-
class AuthorizationRequest(object):
9+
@dataclass
10+
class AuthorizationRequest:
811
"""NOTE: This class is auto generated by the swagger code generator program.
912
1013
Do not edit the class manually.
@@ -16,17 +19,34 @@ class AuthorizationRequest(object):
1619
attribute_map (dict): The key is attribute name
1720
and the value is json key in definition.
1821
"""
19-
swagger_types = {
22+
subject: InitVar[Any] = None
23+
target: InitVar[Any] = None
24+
access: InitVar[List[str]] = None
25+
26+
_subject = None
27+
_target = None
28+
_access = None
29+
30+
# Class variables
31+
swagger_types: Dict[str, str] = field(default_factory=lambda: {
2032
'subject': 'SubjectRef',
2133
'target': 'TargetRef',
2234
'access': 'list[str]'
23-
}
35+
})
2436

25-
attribute_map = {
37+
attribute_map: Dict[str, str] = field(default_factory=lambda: {
2638
'subject': 'subject',
2739
'target': 'target',
2840
'access': 'access'
29-
}
41+
})
42+
43+
discriminator = None
44+
45+
def __post_init__(self, subject, target, access):
46+
"""Initialize fields after dataclass initialization"""
47+
self.subject = subject
48+
self.target = target
49+
self.access = access
3050

3151
def __init__(self, subject=None, target=None, access=None): # noqa: E501
3252
"""AuthorizationRequest - a model defined in Swagger""" # noqa: E501
@@ -152,4 +172,4 @@ def __eq__(self, other):
152172

153173
def __ne__(self, other):
154174
"""Returns true if both objects are not equal"""
155-
return not self == other
175+
return not self == other

src/conductor/client/http/models/bulk_response.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import pprint
22
import re # noqa: F401
3+
from dataclasses import dataclass, field, InitVar
4+
from typing import Dict, List, Optional, Any, TypeVar, Generic, Union
35

46
import six
7+
from deprecated import deprecated
58

9+
T = TypeVar('T')
610

7-
class BulkResponse(object):
11+
12+
@dataclass
13+
class BulkResponse(Generic[T]):
814
"""NOTE: This class is auto generated by the swagger code generator program.
915
1016
Do not edit the class manually.
@@ -28,6 +34,13 @@ class BulkResponse(object):
2834
'message': 'message'
2935
}
3036

37+
bulk_error_results: InitVar[Optional[Dict[str, str]]] = None
38+
bulk_successful_results: InitVar[Optional[List[T]]] = None
39+
40+
_bulk_error_results: Optional[Dict[str, str]] = field(default=None, init=False)
41+
_bulk_successful_results: Optional[List[T]] = field(default=None, init=False)
42+
_message: str = field(default="Bulk Request has been processed.", init=False)
43+
3144
def __init__(self, bulk_error_results=None, bulk_successful_results=None): # noqa: E501
3245
"""BulkResponse - a model defined in Swagger""" # noqa: E501
3346
self._bulk_error_results = None
@@ -39,8 +52,15 @@ def __init__(self, bulk_error_results=None, bulk_successful_results=None): # no
3952
if bulk_successful_results is not None:
4053
self.bulk_successful_results = bulk_successful_results
4154

55+
def __post_init__(self, bulk_error_results, bulk_successful_results):
56+
"""Initialize fields after dataclass initialization"""
57+
if bulk_error_results is not None:
58+
self.bulk_error_results = bulk_error_results
59+
if bulk_successful_results is not None:
60+
self.bulk_successful_results = bulk_successful_results
61+
4262
@property
43-
def bulk_error_results(self):
63+
def bulk_error_results(self) -> Optional[Dict[str, str]]:
4464
"""Gets the bulk_error_results of this BulkResponse. # noqa: E501
4565
4666
Key - entityId Value - error message processing this entity
@@ -51,7 +71,7 @@ def bulk_error_results(self):
5171
return self._bulk_error_results
5272

5373
@bulk_error_results.setter
54-
def bulk_error_results(self, bulk_error_results):
74+
def bulk_error_results(self, bulk_error_results: Optional[Dict[str, str]]):
5575
"""Sets the bulk_error_results of this BulkResponse.
5676
5777
Key - entityId Value - error message processing this entity
@@ -63,17 +83,17 @@ def bulk_error_results(self, bulk_error_results):
6383
self._bulk_error_results = bulk_error_results
6484

6585
@property
66-
def bulk_successful_results(self):
86+
def bulk_successful_results(self) -> Optional[List[T]]:
6787
"""Gets the bulk_successful_results of this BulkResponse. # noqa: E501
6888
6989
7090
:return: The bulk_successful_results of this BulkResponse. # noqa: E501
71-
:rtype: list[str]
91+
:rtype: list[T]
7292
"""
7393
return self._bulk_successful_results
7494

7595
@bulk_successful_results.setter
76-
def bulk_successful_results(self, bulk_successful_results):
96+
def bulk_successful_results(self, bulk_successful_results: Optional[List[T]]):
7797
"""Sets the bulk_successful_results of this BulkResponse.
7898
7999
@@ -84,7 +104,7 @@ def bulk_successful_results(self, bulk_successful_results):
84104
self._bulk_successful_results = bulk_successful_results
85105

86106
@property
87-
def message(self):
107+
def message(self) -> str:
88108
"""Gets the message of this BulkResponse. # noqa: E501
89109
90110
@@ -93,7 +113,7 @@ def message(self):
93113
"""
94114
return self._message
95115

96-
def append_success_response(self, result):
116+
def append_success_response(self, result: T):
97117
"""Appends a successful result to bulk_successful_results. # noqa: E501
98118
99119
:param result: The result to append to bulk_successful_results
@@ -102,7 +122,7 @@ def append_success_response(self, result):
102122
self._bulk_successful_results = []
103123
self._bulk_successful_results.append(result)
104124

105-
def append_failed_response(self, id, error_message):
125+
def append_failed_response(self, id: str, error_message: str):
106126
"""Appends a failed result to bulk_error_results. # noqa: E501
107127
108128
:param id: The entity ID that failed
@@ -112,7 +132,7 @@ def append_failed_response(self, id, error_message):
112132
self._bulk_error_results = {}
113133
self._bulk_error_results[id] = error_message
114134

115-
def to_dict(self):
135+
def to_dict(self) -> Dict[str, Any]:
116136
"""Returns the model properties as a dict"""
117137
result = {}
118138

@@ -139,21 +159,21 @@ def to_dict(self):
139159

140160
return result
141161

142-
def to_str(self):
162+
def to_str(self) -> str:
143163
"""Returns the string representation of the model"""
144164
return pprint.pformat(self.to_dict())
145165

146-
def __repr__(self):
166+
def __repr__(self) -> str:
147167
"""For `print` and `pprint`"""
148168
return self.to_str()
149169

150-
def __eq__(self, other):
170+
def __eq__(self, other) -> bool:
151171
"""Returns true if both objects are equal"""
152172
if not isinstance(other, BulkResponse):
153173
return False
154174

155175
return self.__dict__ == other.__dict__
156176

157-
def __ne__(self, other):
177+
def __ne__(self, other) -> bool:
158178
"""Returns true if both objects are not equal"""
159179
return not self == other

0 commit comments

Comments
 (0)