step_rest_client 1.0.0__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.
- step_rest_client/__init__.py +136 -0
- step_rest_client/api/__init__.py +26 -0
- step_rest_client/api/assets_api.py +7960 -0
- step_rest_client/api/attributes_api.py +340 -0
- step_rest_client/api/background_process_types_api.py +640 -0
- step_rest_client/api/background_processes_api.py +1577 -0
- step_rest_client/api/classifications_api.py +7991 -0
- step_rest_client/api/data_container_types_api.py +340 -0
- step_rest_client/api/data_type_groups_api.py +340 -0
- step_rest_client/api/entities_api.py +8680 -0
- step_rest_client/api/event_processors_api.py +3337 -0
- step_rest_client/api/export_api.py +383 -0
- step_rest_client/api/gateway_integration_endpoints_api.py +1232 -0
- step_rest_client/api/import_api.py +390 -0
- step_rest_client/api/inbound_integration_endpoints_api.py +2815 -0
- step_rest_client/api/lists_of_values_api.py +642 -0
- step_rest_client/api/object_types_api.py +340 -0
- step_rest_client/api/outbound_integration_endpoints_api.py +3655 -0
- step_rest_client/api/products_api.py +8007 -0
- step_rest_client/api/reference_types_api.py +340 -0
- step_rest_client/api/reporting_api.py +707 -0
- step_rest_client/api/units_api.py +340 -0
- step_rest_client/api/workflow_tasks_api.py +1887 -0
- step_rest_client/api/workflows_api.py +1270 -0
- step_rest_client/api_client.py +797 -0
- step_rest_client/api_response.py +21 -0
- step_rest_client/configuration.py +597 -0
- step_rest_client/exceptions.py +216 -0
- step_rest_client/models/__init__.py +98 -0
- step_rest_client/models/amount.py +89 -0
- step_rest_client/models/and_condition.py +107 -0
- step_rest_client/models/approval_response.py +87 -0
- step_rest_client/models/approval_status.py +99 -0
- step_rest_client/models/asset.py +129 -0
- step_rest_client/models/attribute.py +120 -0
- step_rest_client/models/attribute_link.py +102 -0
- step_rest_client/models/background_process.py +139 -0
- step_rest_client/models/background_process_attachment_metadata.py +105 -0
- step_rest_client/models/background_process_identification.py +89 -0
- step_rest_client/models/background_process_type.py +89 -0
- step_rest_client/models/classification.py +135 -0
- step_rest_client/models/condition.py +265 -0
- step_rest_client/models/data_container.py +139 -0
- step_rest_client/models/data_container_entry.py +117 -0
- step_rest_client/models/data_container_object_condition.py +181 -0
- step_rest_client/models/data_container_type.py +106 -0
- step_rest_client/models/data_type_group.py +108 -0
- step_rest_client/models/endpoint_statistics.py +109 -0
- step_rest_client/models/endpoint_status.py +99 -0
- step_rest_client/models/entity.py +142 -0
- step_rest_client/models/error.py +91 -0
- step_rest_client/models/event_processor.py +93 -0
- step_rest_client/models/event_processor_statistics.py +97 -0
- step_rest_client/models/event_processor_status.py +99 -0
- step_rest_client/models/event_queue_status.py +89 -0
- step_rest_client/models/execution_report_entry.py +103 -0
- step_rest_client/models/export_specification.py +89 -0
- step_rest_client/models/find_similar_business_rule_result.py +91 -0
- step_rest_client/models/find_similar_entities_request.py +95 -0
- step_rest_client/models/find_similar_entities_response.py +103 -0
- step_rest_client/models/find_similar_entities_response_record.py +95 -0
- step_rest_client/models/find_similar_execution_report.py +103 -0
- step_rest_client/models/gateway_integration_endpoint.py +93 -0
- step_rest_client/models/has_data_container_object_condition.py +106 -0
- step_rest_client/models/has_reference_to_condition.py +108 -0
- step_rest_client/models/id_condition.py +105 -0
- step_rest_client/models/inbound_integration_endpoint.py +93 -0
- step_rest_client/models/incoming_reference_entry.py +118 -0
- step_rest_client/models/list_of_values.py +110 -0
- step_rest_client/models/list_of_values_entry.py +91 -0
- step_rest_client/models/lov_value_condition.py +100 -0
- step_rest_client/models/match_and_merge_execution_report.py +119 -0
- step_rest_client/models/match_and_merge_general_execution_report.py +91 -0
- step_rest_client/models/match_and_merge_potential_duplicate.py +93 -0
- step_rest_client/models/match_and_merge_record_in.py +95 -0
- step_rest_client/models/match_and_merge_record_out.py +117 -0
- step_rest_client/models/match_and_merge_response.py +103 -0
- step_rest_client/models/multi_data_container.py +101 -0
- step_rest_client/models/multi_reference.py +97 -0
- step_rest_client/models/multi_value.py +103 -0
- step_rest_client/models/name_condition.py +107 -0
- step_rest_client/models/numeric_value_condition.py +111 -0
- step_rest_client/models/object_type.py +104 -0
- step_rest_client/models/object_type_condition.py +96 -0
- step_rest_client/models/or_condition.py +107 -0
- step_rest_client/models/outbound_integration_endpoint.py +93 -0
- step_rest_client/models/product.py +150 -0
- step_rest_client/models/query.py +91 -0
- step_rest_client/models/query_result.py +99 -0
- step_rest_client/models/reference.py +139 -0
- step_rest_client/models/reference_entry.py +141 -0
- step_rest_client/models/reference_metadata_condition.py +181 -0
- step_rest_client/models/reference_type.py +114 -0
- step_rest_client/models/rejected_by_business_condition.py +93 -0
- step_rest_client/models/simple_below_condition.py +105 -0
- step_rest_client/models/single_data_container.py +97 -0
- step_rest_client/models/single_reference.py +93 -0
- step_rest_client/models/single_value.py +103 -0
- step_rest_client/models/status_flag.py +89 -0
- step_rest_client/models/text_value_condition.py +111 -0
- step_rest_client/models/trigger_workflow_event.py +93 -0
- step_rest_client/models/unit.py +104 -0
- step_rest_client/models/value.py +137 -0
- step_rest_client/models/value_entry.py +91 -0
- step_rest_client/models/workflow.py +91 -0
- step_rest_client/models/workflow_event.py +89 -0
- step_rest_client/models/workflow_instance.py +87 -0
- step_rest_client/models/workflow_instance_creation.py +93 -0
- step_rest_client/models/workflow_node.py +99 -0
- step_rest_client/models/workflow_task.py +113 -0
- step_rest_client/models/workflow_task_query.py +101 -0
- step_rest_client/py.typed +0 -0
- step_rest_client/rest.py +258 -0
- step_rest_client-1.0.0.dist-info/METADATA +23 -0
- step_rest_client-1.0.0.dist-info/RECORD +117 -0
- step_rest_client-1.0.0.dist-info/WHEEL +5 -0
- step_rest_client-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,797 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
"""
|
4
|
+
STEP REST API V2
|
5
|
+
|
6
|
+
<h1>About</h1><p>The STEP REST API V2 provides read and write access to a set of core STEP objects using the HTTP operations GET, PUT, POST, PATCH and DELETE.</p><h1>Resource Representation</h1><p>With the exception of a few resource operations for retrieving and uploading binary data, all request and response bodies are JSON, compliant with the schema documented here.</p><h1>Context and Workspace</h1><p>All requests are handled in a specific STEP context and workspace and both can be specified via query parameters available for all resource operations. A context must always be specified while requests per default will be handled in the "Main" workspace.</p><h1>Polymorphism</h1><p>In STEP, attributes, reference types and data container types can all be either single- or multivalued. The STEP REST API V2 uses polymorphism to address this complexity with resources that include values, references and data containers specified to produce and consume a common "abstract" supertype that always will be one of either the single- or multivalued subtype.<br/>As an example, the GET /entities/{id}/values/{attributeId} resource operation is specified to return a "Value" but as evident from the model, the "Value" will always be "oneOf" either "SingleValue", that has a "value" property for which the value is an object, or "MultiValue", that has a "values" property for which the value is an array.<br/>Clients are advised to use the presence or absence of the plural array property ("values", "references" and "dataContainers") to determine the concrete type.</p><h1>Authentication</h1><p>The REST API is protected by HTTP Basic Authentication or if OAuth2-based authentication is enabled (SaaS customers only), by Bearer Authentication. With Basic Authentication, user name and password are supplied with each request and it is therefore highly recommended to only use the API in conjunction with HTTPS. For more information about OAuth2-based authentication for SaaS customers, please see the STEP Authentication Guide.</p><h1>Versioning</h1><p>The STEP REST API V2 is versioned using semantic versioning. Stibo Systems reserve the right to make non-breaking, minor / patch changes in any release without warning and clients must be coded / configured to be 'tolerant' and capable of handling such changes.</p><p>Examples of breaking, major changes:</p><ul><li>Renaming of a property</li><li>Removal of a property</li><li>Property type change</li><li>Addition of new property required for write operations</li><li>Marking existing property as required for write operations</li><li>Removal of resource or resource operation</li><li>Materially different behavior for existing resource operation</li></ul><p>Examples of non-breaking, minor / patch changes:</p><ul><li>Addition of new properties in request responses</li><li>Addition of new query parameter not required for write operations</li><li>Addition of new resource or resource operation</li><li>Bug fixes that do not change the schema or resource operations as described here</li><li>Inclusion of a response body for resource operations specified to return a 200 response with no body</li><li>Change of response "Model" / "schema" to type extending the previously specified type</li><li>Renaming a "Model" / "schema" type</li></ul><p>In addition, error message texts may change without warning within the same version. Client program logic should not depend upon the message content.</p><h1>Error Handling</h1><p>The STEP REST API V2 responds with standard HTTP status codes, with 2** responses indicating a success, 4** responses indicating a client error and 5** indicating a server error. Notice that this specification does not specify common error responses like 500 (internal server error) or 401 (unauthorized) for the individual resource operations. Clients should however be capable of handling such responses.</p><p>Error responses have a JSON response body (see Error schema below) containing HTTP status code information in addition to a message providing details about the error. As mentioned above, client program logic should not depend upon the message content.</p><p>The specific status codes used in the API are:</p><ul><li>200 (OK): Success, response may or may not have a body</li><li>201 (Created): Entity successfully created, response may or may not have a body</li><li>400 (Bad request): The server cannot or will not process the request due to an apparent client error</li><li>401 (Unauthorized): Returned only in relation to failed authentication</li><li>404 (Not Found): Returned only in relation to objects specified via path parameters (variable parts of the URL). If STEP objects referenced in request bodies or via query parameters cannot be found, the response will be 400.</li><li>429 (Too Many Requests): Clients are per default limited to 100 requests per second. Returned if the rate limit is exceeded.</li><li>500 (Internal Server Error): Unexpected error (could potentially cover an issue that rightfully should be a 400)</li></ul>
|
7
|
+
|
8
|
+
The version of the OpenAPI document: 1.3.0
|
9
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
10
|
+
|
11
|
+
Do not edit the class manually.
|
12
|
+
""" # noqa: E501
|
13
|
+
|
14
|
+
|
15
|
+
import datetime
|
16
|
+
from dateutil.parser import parse
|
17
|
+
from enum import Enum
|
18
|
+
import decimal
|
19
|
+
import json
|
20
|
+
import mimetypes
|
21
|
+
import os
|
22
|
+
import re
|
23
|
+
import tempfile
|
24
|
+
|
25
|
+
from urllib.parse import quote
|
26
|
+
from typing import Tuple, Optional, List, Dict, Union
|
27
|
+
from pydantic import SecretStr
|
28
|
+
|
29
|
+
from step_rest_client.configuration import Configuration
|
30
|
+
from step_rest_client.api_response import ApiResponse, T as ApiResponseT
|
31
|
+
import step_rest_client.models
|
32
|
+
from step_rest_client import rest
|
33
|
+
from step_rest_client.exceptions import (
|
34
|
+
ApiValueError,
|
35
|
+
ApiException,
|
36
|
+
BadRequestException,
|
37
|
+
UnauthorizedException,
|
38
|
+
ForbiddenException,
|
39
|
+
NotFoundException,
|
40
|
+
ServiceException
|
41
|
+
)
|
42
|
+
|
43
|
+
RequestSerialized = Tuple[str, str, Dict[str, str], Optional[str], List[str]]
|
44
|
+
|
45
|
+
class ApiClient:
|
46
|
+
"""Generic API client for OpenAPI client library builds.
|
47
|
+
|
48
|
+
OpenAPI generic API client. This client handles the client-
|
49
|
+
server communication, and is invariant across implementations. Specifics of
|
50
|
+
the methods and models for each application are generated from the OpenAPI
|
51
|
+
templates.
|
52
|
+
|
53
|
+
:param configuration: .Configuration object for this client
|
54
|
+
:param header_name: a header to pass when making calls to the API.
|
55
|
+
:param header_value: a header value to pass when making calls to
|
56
|
+
the API.
|
57
|
+
:param cookie: a cookie to include in the header when making calls
|
58
|
+
to the API
|
59
|
+
"""
|
60
|
+
|
61
|
+
PRIMITIVE_TYPES = (float, bool, bytes, str, int)
|
62
|
+
NATIVE_TYPES_MAPPING = {
|
63
|
+
'int': int,
|
64
|
+
'long': int, # TODO remove as only py3 is supported?
|
65
|
+
'float': float,
|
66
|
+
'str': str,
|
67
|
+
'bool': bool,
|
68
|
+
'date': datetime.date,
|
69
|
+
'datetime': datetime.datetime,
|
70
|
+
'decimal': decimal.Decimal,
|
71
|
+
'object': object,
|
72
|
+
}
|
73
|
+
_pool = None
|
74
|
+
|
75
|
+
def __init__(
|
76
|
+
self,
|
77
|
+
configuration=None,
|
78
|
+
header_name=None,
|
79
|
+
header_value=None,
|
80
|
+
cookie=None
|
81
|
+
) -> None:
|
82
|
+
# use default configuration if none is provided
|
83
|
+
if configuration is None:
|
84
|
+
configuration = Configuration.get_default()
|
85
|
+
self.configuration = configuration
|
86
|
+
|
87
|
+
self.rest_client = rest.RESTClientObject(configuration)
|
88
|
+
self.default_headers = {}
|
89
|
+
if header_name is not None:
|
90
|
+
self.default_headers[header_name] = header_value
|
91
|
+
self.cookie = cookie
|
92
|
+
# Set default User-Agent.
|
93
|
+
self.user_agent = 'OpenAPI-Generator/1.0.0/python'
|
94
|
+
self.client_side_validation = configuration.client_side_validation
|
95
|
+
|
96
|
+
def __enter__(self):
|
97
|
+
return self
|
98
|
+
|
99
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
100
|
+
pass
|
101
|
+
|
102
|
+
@property
|
103
|
+
def user_agent(self):
|
104
|
+
"""User agent for this API client"""
|
105
|
+
return self.default_headers['User-Agent']
|
106
|
+
|
107
|
+
@user_agent.setter
|
108
|
+
def user_agent(self, value):
|
109
|
+
self.default_headers['User-Agent'] = value
|
110
|
+
|
111
|
+
def set_default_header(self, header_name, header_value):
|
112
|
+
self.default_headers[header_name] = header_value
|
113
|
+
|
114
|
+
|
115
|
+
_default = None
|
116
|
+
|
117
|
+
@classmethod
|
118
|
+
def get_default(cls):
|
119
|
+
"""Return new instance of ApiClient.
|
120
|
+
|
121
|
+
This method returns newly created, based on default constructor,
|
122
|
+
object of ApiClient class or returns a copy of default
|
123
|
+
ApiClient.
|
124
|
+
|
125
|
+
:return: The ApiClient object.
|
126
|
+
"""
|
127
|
+
if cls._default is None:
|
128
|
+
cls._default = ApiClient()
|
129
|
+
return cls._default
|
130
|
+
|
131
|
+
@classmethod
|
132
|
+
def set_default(cls, default):
|
133
|
+
"""Set default instance of ApiClient.
|
134
|
+
|
135
|
+
It stores default ApiClient.
|
136
|
+
|
137
|
+
:param default: object of ApiClient.
|
138
|
+
"""
|
139
|
+
cls._default = default
|
140
|
+
|
141
|
+
def param_serialize(
|
142
|
+
self,
|
143
|
+
method,
|
144
|
+
resource_path,
|
145
|
+
path_params=None,
|
146
|
+
query_params=None,
|
147
|
+
header_params=None,
|
148
|
+
body=None,
|
149
|
+
post_params=None,
|
150
|
+
files=None, auth_settings=None,
|
151
|
+
collection_formats=None,
|
152
|
+
_host=None,
|
153
|
+
_request_auth=None
|
154
|
+
) -> RequestSerialized:
|
155
|
+
|
156
|
+
"""Builds the HTTP request params needed by the request.
|
157
|
+
:param method: Method to call.
|
158
|
+
:param resource_path: Path to method endpoint.
|
159
|
+
:param path_params: Path parameters in the url.
|
160
|
+
:param query_params: Query parameters in the url.
|
161
|
+
:param header_params: Header parameters to be
|
162
|
+
placed in the request header.
|
163
|
+
:param body: Request body.
|
164
|
+
:param post_params dict: Request post form parameters,
|
165
|
+
for `application/x-www-form-urlencoded`, `multipart/form-data`.
|
166
|
+
:param auth_settings list: Auth Settings names for the request.
|
167
|
+
:param files dict: key -> filename, value -> filepath,
|
168
|
+
for `multipart/form-data`.
|
169
|
+
:param collection_formats: dict of collection formats for path, query,
|
170
|
+
header, and post parameters.
|
171
|
+
:param _request_auth: set to override the auth_settings for an a single
|
172
|
+
request; this effectively ignores the authentication
|
173
|
+
in the spec for a single request.
|
174
|
+
:return: tuple of form (path, http_method, query_params, header_params,
|
175
|
+
body, post_params, files)
|
176
|
+
"""
|
177
|
+
|
178
|
+
config = self.configuration
|
179
|
+
|
180
|
+
# header parameters
|
181
|
+
header_params = header_params or {}
|
182
|
+
header_params.update(self.default_headers)
|
183
|
+
if self.cookie:
|
184
|
+
header_params['Cookie'] = self.cookie
|
185
|
+
if header_params:
|
186
|
+
header_params = self.sanitize_for_serialization(header_params)
|
187
|
+
header_params = dict(
|
188
|
+
self.parameters_to_tuples(header_params,collection_formats)
|
189
|
+
)
|
190
|
+
|
191
|
+
# path parameters
|
192
|
+
if path_params:
|
193
|
+
path_params = self.sanitize_for_serialization(path_params)
|
194
|
+
path_params = self.parameters_to_tuples(
|
195
|
+
path_params,
|
196
|
+
collection_formats
|
197
|
+
)
|
198
|
+
for k, v in path_params:
|
199
|
+
# specified safe chars, encode everything
|
200
|
+
resource_path = resource_path.replace(
|
201
|
+
'{%s}' % k,
|
202
|
+
quote(str(v), safe=config.safe_chars_for_path_param)
|
203
|
+
)
|
204
|
+
|
205
|
+
# post parameters
|
206
|
+
if post_params or files:
|
207
|
+
post_params = post_params if post_params else []
|
208
|
+
post_params = self.sanitize_for_serialization(post_params)
|
209
|
+
post_params = self.parameters_to_tuples(
|
210
|
+
post_params,
|
211
|
+
collection_formats
|
212
|
+
)
|
213
|
+
if files:
|
214
|
+
post_params.extend(self.files_parameters(files))
|
215
|
+
|
216
|
+
# auth setting
|
217
|
+
self.update_params_for_auth(
|
218
|
+
header_params,
|
219
|
+
query_params,
|
220
|
+
auth_settings,
|
221
|
+
resource_path,
|
222
|
+
method,
|
223
|
+
body,
|
224
|
+
request_auth=_request_auth
|
225
|
+
)
|
226
|
+
|
227
|
+
# body
|
228
|
+
if body:
|
229
|
+
body = self.sanitize_for_serialization(body)
|
230
|
+
|
231
|
+
# request url
|
232
|
+
if _host is None or self.configuration.ignore_operation_servers:
|
233
|
+
url = self.configuration.host + resource_path
|
234
|
+
else:
|
235
|
+
# use server/host defined in path or operation instead
|
236
|
+
url = _host + resource_path
|
237
|
+
|
238
|
+
# query parameters
|
239
|
+
if query_params:
|
240
|
+
query_params = self.sanitize_for_serialization(query_params)
|
241
|
+
url_query = self.parameters_to_url_query(
|
242
|
+
query_params,
|
243
|
+
collection_formats
|
244
|
+
)
|
245
|
+
url += "?" + url_query
|
246
|
+
|
247
|
+
return method, url, header_params, body, post_params
|
248
|
+
|
249
|
+
|
250
|
+
def call_api(
|
251
|
+
self,
|
252
|
+
method,
|
253
|
+
url,
|
254
|
+
header_params=None,
|
255
|
+
body=None,
|
256
|
+
post_params=None,
|
257
|
+
_request_timeout=None
|
258
|
+
) -> rest.RESTResponse:
|
259
|
+
"""Makes the HTTP request (synchronous)
|
260
|
+
:param method: Method to call.
|
261
|
+
:param url: Path to method endpoint.
|
262
|
+
:param header_params: Header parameters to be
|
263
|
+
placed in the request header.
|
264
|
+
:param body: Request body.
|
265
|
+
:param post_params dict: Request post form parameters,
|
266
|
+
for `application/x-www-form-urlencoded`, `multipart/form-data`.
|
267
|
+
:param _request_timeout: timeout setting for this request.
|
268
|
+
:return: RESTResponse
|
269
|
+
"""
|
270
|
+
|
271
|
+
try:
|
272
|
+
# perform request and return response
|
273
|
+
response_data = self.rest_client.request(
|
274
|
+
method, url,
|
275
|
+
headers=header_params,
|
276
|
+
body=body, post_params=post_params,
|
277
|
+
_request_timeout=_request_timeout
|
278
|
+
)
|
279
|
+
|
280
|
+
except ApiException as e:
|
281
|
+
raise e
|
282
|
+
|
283
|
+
return response_data
|
284
|
+
|
285
|
+
def response_deserialize(
|
286
|
+
self,
|
287
|
+
response_data: rest.RESTResponse,
|
288
|
+
response_types_map: Optional[Dict[str, ApiResponseT]]=None
|
289
|
+
) -> ApiResponse[ApiResponseT]:
|
290
|
+
"""Deserializes response into an object.
|
291
|
+
:param response_data: RESTResponse object to be deserialized.
|
292
|
+
:param response_types_map: dict of response types.
|
293
|
+
:return: ApiResponse
|
294
|
+
"""
|
295
|
+
|
296
|
+
msg = "RESTResponse.read() must be called before passing it to response_deserialize()"
|
297
|
+
assert response_data.data is not None, msg
|
298
|
+
|
299
|
+
response_type = response_types_map.get(str(response_data.status), None)
|
300
|
+
if not response_type and isinstance(response_data.status, int) and 100 <= response_data.status <= 599:
|
301
|
+
# if not found, look for '1XX', '2XX', etc.
|
302
|
+
response_type = response_types_map.get(str(response_data.status)[0] + "XX", None)
|
303
|
+
|
304
|
+
# deserialize response data
|
305
|
+
response_text = None
|
306
|
+
return_data = None
|
307
|
+
try:
|
308
|
+
if response_type == "bytearray":
|
309
|
+
return_data = response_data.data
|
310
|
+
elif response_type == "file":
|
311
|
+
return_data = self.__deserialize_file(response_data)
|
312
|
+
elif response_type is not None:
|
313
|
+
match = None
|
314
|
+
content_type = response_data.getheader('content-type')
|
315
|
+
if content_type is not None:
|
316
|
+
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
|
317
|
+
encoding = match.group(1) if match else "utf-8"
|
318
|
+
response_text = response_data.data.decode(encoding)
|
319
|
+
return_data = self.deserialize(response_text, response_type, content_type)
|
320
|
+
finally:
|
321
|
+
if not 200 <= response_data.status <= 299:
|
322
|
+
raise ApiException.from_response(
|
323
|
+
http_resp=response_data,
|
324
|
+
body=response_text,
|
325
|
+
data=return_data,
|
326
|
+
)
|
327
|
+
|
328
|
+
return ApiResponse(
|
329
|
+
status_code = response_data.status,
|
330
|
+
data = return_data,
|
331
|
+
headers = response_data.getheaders(),
|
332
|
+
raw_data = response_data.data
|
333
|
+
)
|
334
|
+
|
335
|
+
def sanitize_for_serialization(self, obj):
|
336
|
+
"""Builds a JSON POST object.
|
337
|
+
|
338
|
+
If obj is None, return None.
|
339
|
+
If obj is SecretStr, return obj.get_secret_value()
|
340
|
+
If obj is str, int, long, float, bool, return directly.
|
341
|
+
If obj is datetime.datetime, datetime.date
|
342
|
+
convert to string in iso8601 format.
|
343
|
+
If obj is decimal.Decimal return string representation.
|
344
|
+
If obj is list, sanitize each element in the list.
|
345
|
+
If obj is dict, return the dict.
|
346
|
+
If obj is OpenAPI model, return the properties dict.
|
347
|
+
|
348
|
+
:param obj: The data to serialize.
|
349
|
+
:return: The serialized form of data.
|
350
|
+
"""
|
351
|
+
if obj is None:
|
352
|
+
return None
|
353
|
+
elif isinstance(obj, Enum):
|
354
|
+
return obj.value
|
355
|
+
elif isinstance(obj, SecretStr):
|
356
|
+
return obj.get_secret_value()
|
357
|
+
elif isinstance(obj, self.PRIMITIVE_TYPES):
|
358
|
+
return obj
|
359
|
+
elif isinstance(obj, list):
|
360
|
+
return [
|
361
|
+
self.sanitize_for_serialization(sub_obj) for sub_obj in obj
|
362
|
+
]
|
363
|
+
elif isinstance(obj, tuple):
|
364
|
+
return tuple(
|
365
|
+
self.sanitize_for_serialization(sub_obj) for sub_obj in obj
|
366
|
+
)
|
367
|
+
elif isinstance(obj, (datetime.datetime, datetime.date)):
|
368
|
+
return obj.isoformat()
|
369
|
+
elif isinstance(obj, decimal.Decimal):
|
370
|
+
return str(obj)
|
371
|
+
|
372
|
+
elif isinstance(obj, dict):
|
373
|
+
obj_dict = obj
|
374
|
+
else:
|
375
|
+
# Convert model obj to dict except
|
376
|
+
# attributes `openapi_types`, `attribute_map`
|
377
|
+
# and attributes which value is not None.
|
378
|
+
# Convert attribute name to json key in
|
379
|
+
# model definition for request.
|
380
|
+
if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')):
|
381
|
+
obj_dict = obj.to_dict()
|
382
|
+
else:
|
383
|
+
obj_dict = obj.__dict__
|
384
|
+
|
385
|
+
return {
|
386
|
+
key: self.sanitize_for_serialization(val)
|
387
|
+
for key, val in obj_dict.items()
|
388
|
+
}
|
389
|
+
|
390
|
+
def deserialize(self, response_text: str, response_type: str, content_type: Optional[str]):
|
391
|
+
"""Deserializes response into an object.
|
392
|
+
|
393
|
+
:param response: RESTResponse object to be deserialized.
|
394
|
+
:param response_type: class literal for
|
395
|
+
deserialized object, or string of class name.
|
396
|
+
:param content_type: content type of response.
|
397
|
+
|
398
|
+
:return: deserialized object.
|
399
|
+
"""
|
400
|
+
|
401
|
+
# fetch data from response object
|
402
|
+
if content_type is None:
|
403
|
+
try:
|
404
|
+
data = json.loads(response_text)
|
405
|
+
except ValueError:
|
406
|
+
data = response_text
|
407
|
+
elif re.match(r'^application/(json|[\w!#$&.+-^_]+\+json)\s*(;|$)', content_type, re.IGNORECASE):
|
408
|
+
if response_text == "":
|
409
|
+
data = ""
|
410
|
+
else:
|
411
|
+
data = json.loads(response_text)
|
412
|
+
elif re.match(r'^text\/[a-z.+-]+\s*(;|$)', content_type, re.IGNORECASE):
|
413
|
+
data = response_text
|
414
|
+
else:
|
415
|
+
raise ApiException(
|
416
|
+
status=0,
|
417
|
+
reason="Unsupported content type: {0}".format(content_type)
|
418
|
+
)
|
419
|
+
|
420
|
+
return self.__deserialize(data, response_type)
|
421
|
+
|
422
|
+
def __deserialize(self, data, klass):
|
423
|
+
"""Deserializes dict, list, str into an object.
|
424
|
+
|
425
|
+
:param data: dict, list or str.
|
426
|
+
:param klass: class literal, or string of class name.
|
427
|
+
|
428
|
+
:return: object.
|
429
|
+
"""
|
430
|
+
if data is None:
|
431
|
+
return None
|
432
|
+
|
433
|
+
if isinstance(klass, str):
|
434
|
+
if klass.startswith('List['):
|
435
|
+
m = re.match(r'List\[(.*)]', klass)
|
436
|
+
assert m is not None, "Malformed List type definition"
|
437
|
+
sub_kls = m.group(1)
|
438
|
+
return [self.__deserialize(sub_data, sub_kls)
|
439
|
+
for sub_data in data]
|
440
|
+
|
441
|
+
if klass.startswith('Dict['):
|
442
|
+
m = re.match(r'Dict\[([^,]*), (.*)]', klass)
|
443
|
+
assert m is not None, "Malformed Dict type definition"
|
444
|
+
sub_kls = m.group(2)
|
445
|
+
return {k: self.__deserialize(v, sub_kls)
|
446
|
+
for k, v in data.items()}
|
447
|
+
|
448
|
+
# convert str to class
|
449
|
+
if klass in self.NATIVE_TYPES_MAPPING:
|
450
|
+
klass = self.NATIVE_TYPES_MAPPING[klass]
|
451
|
+
else:
|
452
|
+
klass = getattr(step_rest_client.models, klass)
|
453
|
+
|
454
|
+
if klass in self.PRIMITIVE_TYPES:
|
455
|
+
return self.__deserialize_primitive(data, klass)
|
456
|
+
elif klass == object:
|
457
|
+
return self.__deserialize_object(data)
|
458
|
+
elif klass == datetime.date:
|
459
|
+
return self.__deserialize_date(data)
|
460
|
+
elif klass == datetime.datetime:
|
461
|
+
return self.__deserialize_datetime(data)
|
462
|
+
elif klass == decimal.Decimal:
|
463
|
+
return decimal.Decimal(data)
|
464
|
+
elif issubclass(klass, Enum):
|
465
|
+
return self.__deserialize_enum(data, klass)
|
466
|
+
else:
|
467
|
+
return self.__deserialize_model(data, klass)
|
468
|
+
|
469
|
+
def parameters_to_tuples(self, params, collection_formats):
|
470
|
+
"""Get parameters as list of tuples, formatting collections.
|
471
|
+
|
472
|
+
:param params: Parameters as dict or list of two-tuples
|
473
|
+
:param dict collection_formats: Parameter collection formats
|
474
|
+
:return: Parameters as list of tuples, collections formatted
|
475
|
+
"""
|
476
|
+
new_params: List[Tuple[str, str]] = []
|
477
|
+
if collection_formats is None:
|
478
|
+
collection_formats = {}
|
479
|
+
for k, v in params.items() if isinstance(params, dict) else params:
|
480
|
+
if k in collection_formats:
|
481
|
+
collection_format = collection_formats[k]
|
482
|
+
if collection_format == 'multi':
|
483
|
+
new_params.extend((k, value) for value in v)
|
484
|
+
else:
|
485
|
+
if collection_format == 'ssv':
|
486
|
+
delimiter = ' '
|
487
|
+
elif collection_format == 'tsv':
|
488
|
+
delimiter = '\t'
|
489
|
+
elif collection_format == 'pipes':
|
490
|
+
delimiter = '|'
|
491
|
+
else: # csv is the default
|
492
|
+
delimiter = ','
|
493
|
+
new_params.append(
|
494
|
+
(k, delimiter.join(str(value) for value in v)))
|
495
|
+
else:
|
496
|
+
new_params.append((k, v))
|
497
|
+
return new_params
|
498
|
+
|
499
|
+
def parameters_to_url_query(self, params, collection_formats):
|
500
|
+
"""Get parameters as list of tuples, formatting collections.
|
501
|
+
|
502
|
+
:param params: Parameters as dict or list of two-tuples
|
503
|
+
:param dict collection_formats: Parameter collection formats
|
504
|
+
:return: URL query string (e.g. a=Hello%20World&b=123)
|
505
|
+
"""
|
506
|
+
new_params: List[Tuple[str, str]] = []
|
507
|
+
if collection_formats is None:
|
508
|
+
collection_formats = {}
|
509
|
+
for k, v in params.items() if isinstance(params, dict) else params:
|
510
|
+
if isinstance(v, bool):
|
511
|
+
v = str(v).lower()
|
512
|
+
if isinstance(v, (int, float)):
|
513
|
+
v = str(v)
|
514
|
+
if isinstance(v, dict):
|
515
|
+
v = json.dumps(v)
|
516
|
+
|
517
|
+
if k in collection_formats:
|
518
|
+
collection_format = collection_formats[k]
|
519
|
+
if collection_format == 'multi':
|
520
|
+
new_params.extend((k, quote(str(value))) for value in v)
|
521
|
+
else:
|
522
|
+
if collection_format == 'ssv':
|
523
|
+
delimiter = ' '
|
524
|
+
elif collection_format == 'tsv':
|
525
|
+
delimiter = '\t'
|
526
|
+
elif collection_format == 'pipes':
|
527
|
+
delimiter = '|'
|
528
|
+
else: # csv is the default
|
529
|
+
delimiter = ','
|
530
|
+
new_params.append(
|
531
|
+
(k, delimiter.join(quote(str(value)) for value in v))
|
532
|
+
)
|
533
|
+
else:
|
534
|
+
new_params.append((k, quote(str(v))))
|
535
|
+
|
536
|
+
return "&".join(["=".join(map(str, item)) for item in new_params])
|
537
|
+
|
538
|
+
def files_parameters(
|
539
|
+
self,
|
540
|
+
files: Dict[str, Union[str, bytes, List[str], List[bytes], Tuple[str, bytes]]],
|
541
|
+
):
|
542
|
+
"""Builds form parameters.
|
543
|
+
|
544
|
+
:param files: File parameters.
|
545
|
+
:return: Form parameters with files.
|
546
|
+
"""
|
547
|
+
params = []
|
548
|
+
for k, v in files.items():
|
549
|
+
if isinstance(v, str):
|
550
|
+
with open(v, 'rb') as f:
|
551
|
+
filename = os.path.basename(f.name)
|
552
|
+
filedata = f.read()
|
553
|
+
elif isinstance(v, bytes):
|
554
|
+
filename = k
|
555
|
+
filedata = v
|
556
|
+
elif isinstance(v, tuple):
|
557
|
+
filename, filedata = v
|
558
|
+
elif isinstance(v, list):
|
559
|
+
for file_param in v:
|
560
|
+
params.extend(self.files_parameters({k: file_param}))
|
561
|
+
continue
|
562
|
+
else:
|
563
|
+
raise ValueError("Unsupported file value")
|
564
|
+
mimetype = (
|
565
|
+
mimetypes.guess_type(filename)[0]
|
566
|
+
or 'application/octet-stream'
|
567
|
+
)
|
568
|
+
params.append(
|
569
|
+
tuple([k, tuple([filename, filedata, mimetype])])
|
570
|
+
)
|
571
|
+
return params
|
572
|
+
|
573
|
+
def select_header_accept(self, accepts: List[str]) -> Optional[str]:
|
574
|
+
"""Returns `Accept` based on an array of accepts provided.
|
575
|
+
|
576
|
+
:param accepts: List of headers.
|
577
|
+
:return: Accept (e.g. application/json).
|
578
|
+
"""
|
579
|
+
if not accepts:
|
580
|
+
return None
|
581
|
+
|
582
|
+
for accept in accepts:
|
583
|
+
if re.search('json', accept, re.IGNORECASE):
|
584
|
+
return accept
|
585
|
+
|
586
|
+
return accepts[0]
|
587
|
+
|
588
|
+
def select_header_content_type(self, content_types):
|
589
|
+
"""Returns `Content-Type` based on an array of content_types provided.
|
590
|
+
|
591
|
+
:param content_types: List of content-types.
|
592
|
+
:return: Content-Type (e.g. application/json).
|
593
|
+
"""
|
594
|
+
if not content_types:
|
595
|
+
return None
|
596
|
+
|
597
|
+
for content_type in content_types:
|
598
|
+
if re.search('json', content_type, re.IGNORECASE):
|
599
|
+
return content_type
|
600
|
+
|
601
|
+
return content_types[0]
|
602
|
+
|
603
|
+
def update_params_for_auth(
|
604
|
+
self,
|
605
|
+
headers,
|
606
|
+
queries,
|
607
|
+
auth_settings,
|
608
|
+
resource_path,
|
609
|
+
method,
|
610
|
+
body,
|
611
|
+
request_auth=None
|
612
|
+
) -> None:
|
613
|
+
"""Updates header and query params based on authentication setting.
|
614
|
+
|
615
|
+
:param headers: Header parameters dict to be updated.
|
616
|
+
:param queries: Query parameters tuple list to be updated.
|
617
|
+
:param auth_settings: Authentication setting identifiers list.
|
618
|
+
:resource_path: A string representation of the HTTP request resource path.
|
619
|
+
:method: A string representation of the HTTP request method.
|
620
|
+
:body: A object representing the body of the HTTP request.
|
621
|
+
The object type is the return value of sanitize_for_serialization().
|
622
|
+
:param request_auth: if set, the provided settings will
|
623
|
+
override the token in the configuration.
|
624
|
+
"""
|
625
|
+
if not auth_settings:
|
626
|
+
return
|
627
|
+
|
628
|
+
if request_auth:
|
629
|
+
self._apply_auth_params(
|
630
|
+
headers,
|
631
|
+
queries,
|
632
|
+
resource_path,
|
633
|
+
method,
|
634
|
+
body,
|
635
|
+
request_auth
|
636
|
+
)
|
637
|
+
else:
|
638
|
+
for auth in auth_settings:
|
639
|
+
auth_setting = self.configuration.auth_settings().get(auth)
|
640
|
+
if auth_setting:
|
641
|
+
self._apply_auth_params(
|
642
|
+
headers,
|
643
|
+
queries,
|
644
|
+
resource_path,
|
645
|
+
method,
|
646
|
+
body,
|
647
|
+
auth_setting
|
648
|
+
)
|
649
|
+
|
650
|
+
def _apply_auth_params(
|
651
|
+
self,
|
652
|
+
headers,
|
653
|
+
queries,
|
654
|
+
resource_path,
|
655
|
+
method,
|
656
|
+
body,
|
657
|
+
auth_setting
|
658
|
+
) -> None:
|
659
|
+
"""Updates the request parameters based on a single auth_setting
|
660
|
+
|
661
|
+
:param headers: Header parameters dict to be updated.
|
662
|
+
:param queries: Query parameters tuple list to be updated.
|
663
|
+
:resource_path: A string representation of the HTTP request resource path.
|
664
|
+
:method: A string representation of the HTTP request method.
|
665
|
+
:body: A object representing the body of the HTTP request.
|
666
|
+
The object type is the return value of sanitize_for_serialization().
|
667
|
+
:param auth_setting: auth settings for the endpoint
|
668
|
+
"""
|
669
|
+
if auth_setting['in'] == 'cookie':
|
670
|
+
headers['Cookie'] = auth_setting['value']
|
671
|
+
elif auth_setting['in'] == 'header':
|
672
|
+
if auth_setting['type'] != 'http-signature':
|
673
|
+
headers[auth_setting['key']] = auth_setting['value']
|
674
|
+
elif auth_setting['in'] == 'query':
|
675
|
+
queries.append((auth_setting['key'], auth_setting['value']))
|
676
|
+
else:
|
677
|
+
raise ApiValueError(
|
678
|
+
'Authentication token must be in `query` or `header`'
|
679
|
+
)
|
680
|
+
|
681
|
+
def __deserialize_file(self, response):
|
682
|
+
"""Deserializes body to file
|
683
|
+
|
684
|
+
Saves response body into a file in a temporary folder,
|
685
|
+
using the filename from the `Content-Disposition` header if provided.
|
686
|
+
|
687
|
+
handle file downloading
|
688
|
+
save response body into a tmp file and return the instance
|
689
|
+
|
690
|
+
:param response: RESTResponse.
|
691
|
+
:return: file path.
|
692
|
+
"""
|
693
|
+
fd, path = tempfile.mkstemp(dir=self.configuration.temp_folder_path)
|
694
|
+
os.close(fd)
|
695
|
+
os.remove(path)
|
696
|
+
|
697
|
+
content_disposition = response.getheader("Content-Disposition")
|
698
|
+
if content_disposition:
|
699
|
+
m = re.search(
|
700
|
+
r'filename=[\'"]?([^\'"\s]+)[\'"]?',
|
701
|
+
content_disposition
|
702
|
+
)
|
703
|
+
assert m is not None, "Unexpected 'content-disposition' header value"
|
704
|
+
filename = m.group(1)
|
705
|
+
path = os.path.join(os.path.dirname(path), filename)
|
706
|
+
|
707
|
+
with open(path, "wb") as f:
|
708
|
+
f.write(response.data)
|
709
|
+
|
710
|
+
return path
|
711
|
+
|
712
|
+
def __deserialize_primitive(self, data, klass):
|
713
|
+
"""Deserializes string to primitive type.
|
714
|
+
|
715
|
+
:param data: str.
|
716
|
+
:param klass: class literal.
|
717
|
+
|
718
|
+
:return: int, long, float, str, bool.
|
719
|
+
"""
|
720
|
+
try:
|
721
|
+
return klass(data)
|
722
|
+
except UnicodeEncodeError:
|
723
|
+
return str(data)
|
724
|
+
except TypeError:
|
725
|
+
return data
|
726
|
+
|
727
|
+
def __deserialize_object(self, value):
|
728
|
+
"""Return an original value.
|
729
|
+
|
730
|
+
:return: object.
|
731
|
+
"""
|
732
|
+
return value
|
733
|
+
|
734
|
+
def __deserialize_date(self, string):
|
735
|
+
"""Deserializes string to date.
|
736
|
+
|
737
|
+
:param string: str.
|
738
|
+
:return: date.
|
739
|
+
"""
|
740
|
+
try:
|
741
|
+
return parse(string).date()
|
742
|
+
except ImportError:
|
743
|
+
return string
|
744
|
+
except ValueError:
|
745
|
+
raise rest.ApiException(
|
746
|
+
status=0,
|
747
|
+
reason="Failed to parse `{0}` as date object".format(string)
|
748
|
+
)
|
749
|
+
|
750
|
+
def __deserialize_datetime(self, string):
|
751
|
+
"""Deserializes string to datetime.
|
752
|
+
|
753
|
+
The string should be in iso8601 datetime format.
|
754
|
+
|
755
|
+
:param string: str.
|
756
|
+
:return: datetime.
|
757
|
+
"""
|
758
|
+
try:
|
759
|
+
return parse(string)
|
760
|
+
except ImportError:
|
761
|
+
return string
|
762
|
+
except ValueError:
|
763
|
+
raise rest.ApiException(
|
764
|
+
status=0,
|
765
|
+
reason=(
|
766
|
+
"Failed to parse `{0}` as datetime object"
|
767
|
+
.format(string)
|
768
|
+
)
|
769
|
+
)
|
770
|
+
|
771
|
+
def __deserialize_enum(self, data, klass):
|
772
|
+
"""Deserializes primitive type to enum.
|
773
|
+
|
774
|
+
:param data: primitive type.
|
775
|
+
:param klass: class literal.
|
776
|
+
:return: enum value.
|
777
|
+
"""
|
778
|
+
try:
|
779
|
+
return klass(data)
|
780
|
+
except ValueError:
|
781
|
+
raise rest.ApiException(
|
782
|
+
status=0,
|
783
|
+
reason=(
|
784
|
+
"Failed to parse `{0}` as `{1}`"
|
785
|
+
.format(data, klass)
|
786
|
+
)
|
787
|
+
)
|
788
|
+
|
789
|
+
def __deserialize_model(self, data, klass):
|
790
|
+
"""Deserializes list or dict to model.
|
791
|
+
|
792
|
+
:param data: dict, list.
|
793
|
+
:param klass: class literal.
|
794
|
+
:return: model object.
|
795
|
+
"""
|
796
|
+
|
797
|
+
return klass.from_dict(data)
|