Skip to content

Commit 89b3f40

Browse files
feat(union-types): adds support for OneOf and AnyOf (#41)
This commit adds support for union types that are OneOf and AnyOf types. There are 4 new classes (OneOf, AnyOf, LeafType, UnionTypeContext) that are participating as generic algorithms for validating requests and responses containing union types. You can read more about union types [here](https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/). By using those classes, the Python core library now has the handling for union types. This also adds support for the serialization of nested maps and arrays.
1 parent f338272 commit 89b3f40

44 files changed

Lines changed: 3732 additions & 132 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,28 @@ pip install apimatic-core
6666
| [`EndpointLogger`](apimatic_core/logger/endpoint_logger.py) | A class to provide logging for an HTTP request |
6767

6868
## Types
69-
| Name | Description |
70-
|------------------------------------------------------------------------------|------------------------------------------------------------------------------|
71-
| [`SerializationFormats`](apimatic_core/types/array_serialization_format.py) | An Enumeration of Array serialization formats |
72-
| [`DateTimeFormat`](apimatic_core/types/datetime_format.py ) | An Enumeration of Date Time formats |
73-
| [`ErrorCase`](apimatic_core/types/error_case.py ) | A class to represent Exception types |
74-
| [`FileWrapper`](apimatic_core/types/file_wrapper.py) | A wrapper to allow passing in content type for file uploads |
75-
| [`Parameter`](apimatic_core/types/parameter.py ) | A class to represent information about a Parameter passed in an endpoint |
76-
| [`XmlAttributes`](apimatic_core/types/xml_attributes.py ) | A class to represent information about a XML Parameter passed in an endpoint |
69+
| Name | Description |
70+
|-------------------------------------------------------------------------------|------------------------------------------------------------------------------|
71+
| [`SerializationFormats`](apimatic_core/types/array_serialization_format.py) | An Enumeration of Array serialization formats |
72+
| [`DateTimeFormat`](apimatic_core/types/datetime_format.py ) | An Enumeration of Date Time formats |
73+
| [`ErrorCase`](apimatic_core/types/error_case.py ) | A class to represent Exception types |
74+
| [`FileWrapper`](apimatic_core/types/file_wrapper.py) | A wrapper to allow passing in content type for file uploads |
75+
| [`Parameter`](apimatic_core/types/parameter.py ) | A class to represent information about a Parameter passed in an endpoint |
76+
| [`XmlAttributes`](apimatic_core/types/xml_attributes.py ) | A class to represent information about a XML Parameter passed in an endpoint |
77+
| [`OneOf`](apimatic_core/types/union_types/one_of.py ) | A class to represent information about OneOf union types |
78+
| [`AnyOf`](apimatic_core/types/union_types/any_of.py ) | A class to represent information about AnyOf union types |
79+
| [`LeafType`](apimatic_core/types/union_types/leaf_type.py ) | A class to represent the case information in an OneOf or AnyOf union type |
7780

7881
## Utilities
79-
| Name | Description |
80-
|--------------------------------------------------------------------|--------------------------------------------------------------------------------------|
81-
| [`ApiHelper`](apimatic_core/utilities/api_helper.py) | A Helper Class with various functions associated with making an API Call |
82-
| [`AuthHelper`](apimatic_core/utilities/auth_helper.py) | A Helper Class with various functions associated with authentication in API Calls |
83-
| [`ComparisonHelper`](apimatic_core/utilities/comparison_helper.py) | A Helper Class used for the comparison of expected and actual API response |
84-
| [` FileHelper`](apimatic_core/utilities/file_helper.py) | A Helper Class for files |
85-
| [`XmlHelper`](apimatic_core/utilities/xml_helper.py ) | A Helper class that holds utility methods for xml serialization and deserialization. |
82+
| Name | Description |
83+
|--------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------|
84+
| [`ApiHelper`](apimatic_core/utilities/api_helper.py) | A Helper Class with various functions associated with making an API Call |
85+
| [`AuthHelper`](apimatic_core/utilities/auth_helper.py) | A Helper Class with various functions associated with authentication in API Calls |
86+
| [`ComparisonHelper`](apimatic_core/utilities/comparison_helper.py) | A Helper Class used for the comparison of expected and actual API response |
87+
| [`FileHelper`](apimatic_core/utilities/file_helper.py) | A Helper Class for files |
88+
| [`XmlHelper`](apimatic_core/utilities/xml_helper.py ) | A Helper class that holds utility methods for xml serialization and deserialization. |
89+
| [`DateTimeHelper`](apimatic_core/utilities/datetime_helper.py ) | A Helper class that holds utility methods for validation of different datetime formats. |
90+
| [`UnionTypeHelper`](apimatic_core/utilities/union_type_helper.py ) | A Helper class that holds utility methods for deserialization and validation of OneOf/AnyOf union types. |
8691

8792
## Links
8893
* [apimatic-core-interfaces](https://pypi.org/project/apimatic-core-interfaces/)

apimatic_core/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
'utilities',
1010
'factories',
1111
'types',
12-
'logger'
12+
'logger',
13+
'exceptions'
1314
]

apimatic_core/authentication/multiple/auth_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def with_auth_managers(self, auth_managers):
3838

3939
return self
4040

41-
def is_valid(self):
41+
def is_valid(self): # pragma: no cover
4242
...
4343

4444
def apply(self, http_request):
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
__all__ = [
2+
'oneof_validation_exception',
3+
'anyof_validation_exception'
4+
]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
class AnyOfValidationException(Exception):
3+
def __init__(self, message):
4+
self.message = message
5+
super().__init__(self.message)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
class OneOfValidationException(Exception):
3+
def __init__(self, message):
4+
self.message = message
5+
super().__init__(self.message)

apimatic_core/http/configurations/http_client_configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from apimatic_core.factories.http_response_factory import HttpResponseFactory
33

44

5-
class HttpClientConfiguration(object):
5+
class HttpClientConfiguration(object): # pragma: no cover
66
"""A class used for configuring the SDK by a user.
77
"""
88

apimatic_core/http/http_callback.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ class HttpCallBack(object):
99
1010
"""
1111

12-
def on_before_request(self,
13-
request):
12+
def on_before_request(self, request): # pragma: no cover
1413
"""The controller will call this method before making the HttpRequest.
1514
1615
Args:
@@ -19,8 +18,7 @@ def on_before_request(self,
1918
"""
2019
raise NotImplementedError("This method has not been implemented.")
2120

22-
def on_after_response(self,
23-
http_response):
21+
def on_after_response(self, http_response): # pragma: no cover
2422
"""The controller will call this method after making the HttpRequest.
2523
2624
Args:

apimatic_core/http/request/http_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def add_header(self, name, value):
5656
"""
5757
self.headers[name] = value
5858

59-
def add_parameter(self, name, value):
59+
def add_parameter(self, name, value): # pragma: no cover
6060
""" Add a parameter to the HttpRequest.
6161
6262
Args:

apimatic_core/request_builder.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def __init__(
2626
self._additional_query_params = {}
2727
self._multipart_params = []
2828
self._body_param = None
29-
self._should_wrap_body_param = None
3029
self._body_serializer = None
3130
self._auth = None
3231
self._array_serialization_format = SerializationFormats.INDEXED
@@ -90,10 +89,6 @@ def body_param(self, body_param):
9089
self._body_param = body_param.get_value()
9190
return self
9291

93-
def should_wrap_body_param(self, should_wrap_body_param):
94-
self._should_wrap_body_param = should_wrap_body_param
95-
return self
96-
9792
def body_serializer(self, body_serializer):
9893
self._body_serializer = body_serializer
9994
return self
@@ -184,8 +179,6 @@ def process_body_params(self):
184179
self.add_additional_form_params()
185180
return ApiHelper.form_encode_parameters(self._form_params, self._array_serialization_format)
186181
elif self._body_param is not None and self._body_serializer:
187-
if self._should_wrap_body_param:
188-
return self._body_serializer(self.resolve_body_param(), self._should_wrap_body_param)
189182
return self._body_serializer(self.resolve_body_param())
190183
elif self._body_param is not None and not self._body_serializer:
191184
return self.resolve_body_param()

0 commit comments

Comments
 (0)