Skip to content

Commit 91b5af6

Browse files
feat(union-types): adds support for OneOf and AnyOf (#20)
This commit adds support for union-types that are OneOf and AnyOf types by providing the base type by the name of the UnionType which is an abstract class. This concrete implementation of this class are OneOf, AnyOf and LeafType classes which are part of the core library.
1 parent 3d696b1 commit 91b5af6

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ pip install apimatic-core-interfaces
1515
```
1616

1717
## Interfaces
18-
| Name | Description |
19-
|--------------------------------------------------------------------------- |------------------------------------------------------------------------------------------|
20-
| [`HttpClient`](apimatic_core_interfaces/client/http_client.py) | To save both Request and Response after the completion of response |
21-
| [`ResponseFactory`](apimatic_core_interfaces/factories/response_factory.py)| To convert the client-adapter response into a custom HTTP response |
22-
| [`Authentication`](apimatic_core_interfaces/types/authentication.py) | To setup methods for the validation and application of the required authentication scheme|
18+
| Name | Description |
19+
|-----------------------------------------------------------------------------|-------------------------------------------------------------------------------------------|
20+
| [`HttpClient`](apimatic_core_interfaces/client/http_client.py) | To save both Request and Response after the completion of response |
21+
| [`ResponseFactory`](apimatic_core_interfaces/factories/response_factory.py) | To convert the client-adapter response into a custom HTTP response |
22+
| [`Authentication`](apimatic_core_interfaces/types/authentication.py) | To setup methods for the validation and application of the required authentication scheme |
23+
| [`UnionType`](apimatic_core_interfaces/types/union_type.py) | To setup methods for the validation and deserialization of OneOf/AnyOf union types |
2324

2425

2526
## Enumerations
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
__all__ = [
22
'http_method_enum',
3-
'authentication'
3+
'authentication',
4+
'union_type'
45
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from abc import ABC, abstractmethod
2+
3+
4+
class UnionType(ABC):
5+
NATIVE_TYPES = [int, str, float, bool]
6+
7+
def __init__(self, union_types, union_type_context):
8+
self._union_types = union_types
9+
self._union_type_context = union_type_context
10+
self.is_valid = False
11+
self.error_messages = set()
12+
13+
@abstractmethod
14+
def validate(self, value):
15+
...
16+
17+
@abstractmethod
18+
def deserialize(self, value):
19+
...
20+
21+
def get_context(self):
22+
return self._union_type_context

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
setup(
1414
name='apimatic-core-interfaces',
15-
version='0.1.3',
15+
version='0.1.4',
1616
description='An abstract layer of the functionalities provided by apimatic-core-library, requests-client-adapter '
1717
'and APIMatic SDKs.',
1818
long_description=long_description,

0 commit comments

Comments
 (0)