From fa9ccc595c7b699ab21004eab8f4dfb2c55eb149 Mon Sep 17 00:00:00 2001 From: Muhammad Sufyan Date: Tue, 16 May 2023 14:43:10 +0500 Subject: [PATCH 1/8] adds abstract type for oneOf and anyOf types --- apimatic_core_interfaces/types/__init__.py | 3 ++- apimatic_core_interfaces/types/union_type.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 apimatic_core_interfaces/types/union_type.py diff --git a/apimatic_core_interfaces/types/__init__.py b/apimatic_core_interfaces/types/__init__.py index a4622c6..04023ac 100644 --- a/apimatic_core_interfaces/types/__init__.py +++ b/apimatic_core_interfaces/types/__init__.py @@ -1,4 +1,5 @@ __all__ = [ 'http_method_enum', - 'authentication' + 'authentication', + 'union_type' ] \ No newline at end of file diff --git a/apimatic_core_interfaces/types/union_type.py b/apimatic_core_interfaces/types/union_type.py new file mode 100644 index 0000000..4609e4e --- /dev/null +++ b/apimatic_core_interfaces/types/union_type.py @@ -0,0 +1,19 @@ +from abc import ABC, abstractmethod +from apimatic_core.types.union_types.union_type_context import UnionTypeContext + + +class UnionType(ABC): + NATIVE_TYPES = [int, str, float, bool] + + def __init__(self, union_types, union_type_context: UnionTypeContext): + self._union_types = union_types + self._union_type_context = union_type_context + self.is_valid = False + + @abstractmethod + def validate(self, value): + ... + + @abstractmethod + def deserialize(self, value): + ... From a98366355940137eb2490f9a45153eb39943abc5 Mon Sep 17 00:00:00 2001 From: Muhammad Sufyan Date: Tue, 16 May 2023 16:07:07 +0500 Subject: [PATCH 2/8] updates the version of the core interfaces --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 232ceec..3a2a13f 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name='apimatic-core-interfaces', - version='0.1.3', + version='0.1.4', description='An abstract layer of the functionalities provided by apimatic-core-library, requests-client-adapter ' 'and APIMatic SDKs.', long_description=long_description, From 0c58e71ff45425855f03ef5f5dcfcb4863075108 Mon Sep 17 00:00:00 2001 From: Muhammad Sufyan Date: Mon, 22 May 2023 16:12:01 +0500 Subject: [PATCH 3/8] adds getter for context in union types --- apimatic_core_interfaces/types/union_type.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apimatic_core_interfaces/types/union_type.py b/apimatic_core_interfaces/types/union_type.py index 4609e4e..91639f1 100644 --- a/apimatic_core_interfaces/types/union_type.py +++ b/apimatic_core_interfaces/types/union_type.py @@ -1,11 +1,10 @@ from abc import ABC, abstractmethod -from apimatic_core.types.union_types.union_type_context import UnionTypeContext class UnionType(ABC): NATIVE_TYPES = [int, str, float, bool] - def __init__(self, union_types, union_type_context: UnionTypeContext): + def __init__(self, union_types, union_type_context): self._union_types = union_types self._union_type_context = union_type_context self.is_valid = False @@ -17,3 +16,6 @@ def validate(self, value): @abstractmethod def deserialize(self, value): ... + + def get_context(self): + return self._union_type_context From f182ab824bec4f5b5ce5344cda5e99bcf0c77f00 Mon Sep 17 00:00:00 2001 From: Muhammad Sufyan Date: Wed, 24 May 2023 18:27:05 +0500 Subject: [PATCH 4/8] adds errors property for invalid cases --- apimatic_core_interfaces/types/union_type.py | 1 + 1 file changed, 1 insertion(+) diff --git a/apimatic_core_interfaces/types/union_type.py b/apimatic_core_interfaces/types/union_type.py index 91639f1..3ab142a 100644 --- a/apimatic_core_interfaces/types/union_type.py +++ b/apimatic_core_interfaces/types/union_type.py @@ -8,6 +8,7 @@ def __init__(self, union_types, union_type_context): self._union_types = union_types self._union_type_context = union_type_context self.is_valid = False + self.errors = [] @abstractmethod def validate(self, value): From 6c69c159e69b9045d5801e3b63877c16506e4be2 Mon Sep 17 00:00:00 2001 From: Muhammad Sufyan Date: Wed, 31 May 2023 12:39:23 +0500 Subject: [PATCH 5/8] adds OAF error messages for no type matched and more than 1 type matched --- apimatic_core_interfaces/types/union_type.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apimatic_core_interfaces/types/union_type.py b/apimatic_core_interfaces/types/union_type.py index 3ab142a..7ece14d 100644 --- a/apimatic_core_interfaces/types/union_type.py +++ b/apimatic_core_interfaces/types/union_type.py @@ -3,12 +3,14 @@ class UnionType(ABC): NATIVE_TYPES = [int, str, float, bool] + NONE_MATCHED_ERROR_MESSAGE = 'We could not match any acceptable types against the given JSON.' + MORE_THAN_1_MATCHED_ERROR_MESSAGE = 'There are more than one acceptable type matched against the given JSON.' def __init__(self, union_types, union_type_context): self._union_types = union_types self._union_type_context = union_type_context self.is_valid = False - self.errors = [] + self.error_messages = None @abstractmethod def validate(self, value): From da5cb5b40f411c79ca39637be24c665d79dd3999 Mon Sep 17 00:00:00 2001 From: Muhammad Sufyan Date: Mon, 5 Jun 2023 17:10:58 +0500 Subject: [PATCH 6/8] adds documentation for UnionType interface in the README --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bce5006..8f37182 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,12 @@ pip install apimatic-core-interfaces ``` ## Interfaces -| Name | Description | -|--------------------------------------------------------------------------- |------------------------------------------------------------------------------------------| -| [`HttpClient`](apimatic_core_interfaces/client/http_client.py) | To save both Request and Response after the completion of response | -| [`ResponseFactory`](apimatic_core_interfaces/factories/response_factory.py)| To convert the client-adapter response into a custom HTTP response | -| [`Authentication`](apimatic_core_interfaces/types/authentication.py) | To setup methods for the validation and application of the required authentication scheme| +| Name | Description | +|-----------------------------------------------------------------------------|-------------------------------------------------------------------------------------------| +| [`HttpClient`](apimatic_core_interfaces/client/http_client.py) | To save both Request and Response after the completion of response | +| [`ResponseFactory`](apimatic_core_interfaces/factories/response_factory.py) | To convert the client-adapter response into a custom HTTP response | +| [`Authentication`](apimatic_core_interfaces/types/authentication.py) | To setup methods for the validation and application of the required authentication scheme | +| [`UnionType`](apimatic_core_interfaces/types/union_type.py) | To setup methods for the validation and deserialization of OneOf/AnyOf union types | ## Enumerations From adc8fb7a362a836a531b58d5f4fc7963c9b79cbe Mon Sep 17 00:00:00 2001 From: Muhammad Sufyan Date: Wed, 7 Jun 2023 16:53:55 +0500 Subject: [PATCH 7/8] updated from list to set --- apimatic_core_interfaces/types/union_type.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apimatic_core_interfaces/types/union_type.py b/apimatic_core_interfaces/types/union_type.py index 7ece14d..87fdfc3 100644 --- a/apimatic_core_interfaces/types/union_type.py +++ b/apimatic_core_interfaces/types/union_type.py @@ -10,7 +10,7 @@ def __init__(self, union_types, union_type_context): self._union_types = union_types self._union_type_context = union_type_context self.is_valid = False - self.error_messages = None + self.error_messages = set() @abstractmethod def validate(self, value): From 609e253feb542e5220da59f8fbe79a28af5f480d Mon Sep 17 00:00:00 2001 From: Muhammad Sufyan Date: Fri, 9 Jun 2023 12:21:35 +0500 Subject: [PATCH 8/8] removed error message since these are kept in core library project --- apimatic_core_interfaces/types/union_type.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/apimatic_core_interfaces/types/union_type.py b/apimatic_core_interfaces/types/union_type.py index 87fdfc3..0c6f740 100644 --- a/apimatic_core_interfaces/types/union_type.py +++ b/apimatic_core_interfaces/types/union_type.py @@ -3,8 +3,6 @@ class UnionType(ABC): NATIVE_TYPES = [int, str, float, bool] - NONE_MATCHED_ERROR_MESSAGE = 'We could not match any acceptable types against the given JSON.' - MORE_THAN_1_MATCHED_ERROR_MESSAGE = 'There are more than one acceptable type matched against the given JSON.' def __init__(self, union_types, union_type_context): self._union_types = union_types