-
Notifications
You must be signed in to change notification settings - Fork 2
feat(union-types): adds support for OneOf and AnyOf #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
b25b906
adds design implementation for OneOf and AnyOf along with some unit t…
sufyankhanrao 4d9838e
Add tests in one_of.py
9cd6056
Adding complex type array cases
f4ab053
add tests for complex type dictionary cases
ad3b578
added array of dictionary and dict of array complex types tests
251dbed
Update requirements.txt
hamzashoukat94 3d7659c
Update setup.py
hamzashoukat94 b1a566b
adds support for discriminator and date & time validator for OAF alon…
sufyankhanrao ff61946
Merge branch 'add-type-combinator-support' of https://github.com/apim…
sufyankhanrao d3da798
added handling for case when generate models setting is false during …
sufyankhanrao 48b3d86
fixed array of map and map of array cases for oneof and added guard c…
sufyankhanrao 3fd4bcd
fixed issues in APIHelper and updated test cases accordingly
sufyankhanrao 001b261
Add enum simple and array cases in One of and replicated one cases in…
496d0ee
Merge branch 'add-type-combinator-support' of https://github.com/apim…
7a63c19
added fixes and refactored code
sufyankhanrao 0f5ed3c
merge conflicts resolved
sufyankhanrao ba5e7d5
added apply apply_datetime_converter utility method in ApiHelper class
sufyankhanrao cdd4b88
added validation for OAF and unit tests for APIHelper
sufyankhanrao e8f5c77
added validation for OAF types in model while serialization
sufyankhanrao 40944b3
Fixed all tests in one of and any of, check for completion of test co…
8d93674
Merge branch 'add-type-combinator-support' of https://github.com/apim…
7c1a689
added fixes to the unit tests for OAF
sufyankhanrao 01397ad
refactored oneOf and anyOf classes and added optional or nullable tes…
sufyankhanrao a1d663b
added value in the validation error message and handled optional null…
sufyankhanrao 5b10f12
Merge branch 'main' into add-type-combinator-support
sufyankhanrao bf2dd58
Update requirements.txt
sufyankhanrao 2b212f8
Update requirements.txt
sufyankhanrao 141344a
fixed boolean and int type matching
sufyankhanrao dae6c12
Merge branch 'add-type-combinator-support' of https://github.com/apim…
sufyankhanrao e0171dd
refactored code based on result from code climate
sufyankhanrao 5ca1933
applied refactoring based on code-climate
sufyankhanrao e38b57e
reverted refactoring
sufyankhanrao c3243e9
added documentation for newly added classes in the README
sufyankhanrao f8a48f3
refactored code to reduce cognitive complexity
sufyankhanrao 3aa0395
refactored code to reduce cognitive complexity
sufyankhanrao c8636ae
refactored code
sufyankhanrao 515c759
refactored code to reduce cognitive complexity
sufyankhanrao dfeda28
refactored code
sufyankhanrao 1eb097e
refactored code
sufyankhanrao 1238d57
refactored code
sufyankhanrao 0e9b529
refactored code
sufyankhanrao c1a38ac
refactored code
sufyankhanrao 3d89bf4
refactored code
sufyankhanrao 355933a
added new datetime and other primitive types false negative tests to …
1e8637f
Merge branch 'add-type-combinator-support' of https://github.com/apim…
c70386f
fixed datetime handling and added unit tests
sufyankhanrao 9d04669
tests refactoring
0655d16
Merge branch 'add-type-combinator-support' of https://github.com/apim…
611db30
fixed some issues
sufyankhanrao f754623
Merge branch 'add-type-combinator-support' of https://github.com/apim…
sufyankhanrao dcad4ad
Add oneof/anyof nested cases
ab6baec
Merge branch 'add-type-combinator-support' of https://github.com/apim…
6149494
complete one of/ any coverage to 100%
0341c8b
remove no coverage checks in deepcopy method.
f416f2a
fixed validation error messages compilation for AnyOf types and remov…
sufyankhanrao bc47ef1
added files in init file in test package
sufyankhanrao b192fd9
added missing unit tests and removed unused properties in request bui…
sufyankhanrao 3098455
applied suggestion after the first review
sufyankhanrao 7180854
Merge branch 'main' into add-type-combinator-support
sufyankhanrao 6aa5b6c
Update setup.py
sufyankhanrao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,5 +9,6 @@ | |
| 'utilities', | ||
| 'factories', | ||
| 'types', | ||
| 'logger' | ||
| 'logger', | ||
| 'exceptions' | ||
| ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| __all__ = [ | ||
| 'oneof_validation_exception', | ||
| 'anyof_validation_exception' | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
|
|
||
| class AnyOfValidationException(Exception): | ||
| def __init__(self, message): | ||
| self.message = message | ||
| super().__init__(self.message) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
|
|
||
| class OneOfValidationException(Exception): | ||
| def __init__(self, message): | ||
| self.message = message | ||
| super().__init__(self.message) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,5 +4,6 @@ | |
| 'error_case', | ||
| 'file_wrapper', | ||
| 'array_serialization_format', | ||
| 'xml_attributes' | ||
| 'xml_attributes', | ||
| 'union_types' | ||
| ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| __all__ = [ | ||
| "any_of", | ||
| "one_of", | ||
| "union_type_context", | ||
| "leaf_type" | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| from apimatic_core_interfaces.types.union_type import UnionType | ||
| from apimatic_core.types.union_types.union_type_context import UnionTypeContext | ||
| from apimatic_core.utilities.union_type_helper import UnionTypeHelper | ||
|
|
||
|
|
||
| class AnyOf(UnionType): | ||
|
|
||
| def __init__(self, union_types, union_type_context: UnionTypeContext = UnionTypeContext()): | ||
| super(AnyOf, self).__init__(union_types, union_type_context) | ||
| self.collection_cases = None | ||
|
|
||
| def validate(self, value): | ||
| context = self._union_type_context | ||
| UnionTypeHelper.update_nested_flag_for_union_types(self._union_types) | ||
| is_optional_or_nullable = UnionTypeHelper.is_optional_or_nullable_case(context, | ||
| [nested_type.get_context() | ||
| for nested_type in self._union_types]) | ||
|
|
||
| if value is None and is_optional_or_nullable: | ||
| self.is_valid = True | ||
| return self | ||
|
|
||
| if value is None: | ||
| self.is_valid = False | ||
| self.error_messages = UnionTypeHelper.process_errors(value, self._union_types, self.error_messages, | ||
| self.get_context().is_nested, False) | ||
| return self | ||
|
|
||
| self._validate_value_against_case(value, context) | ||
|
|
||
| if not self.is_valid: | ||
| self.error_messages = UnionTypeHelper.process_errors(value, self._union_types, self.error_messages, | ||
| self.get_context().is_nested, False) | ||
|
|
||
| return self | ||
|
|
||
| def deserialize(self, value): | ||
| if value is None: | ||
| return None | ||
|
|
||
| return UnionTypeHelper.deserialize_value(value, self._union_type_context, self.collection_cases, | ||
| self._union_types) | ||
|
|
||
| def _validate_value_against_case(self, value, context): | ||
| if context.is_array() and context.is_dict() and context.is_array_of_dict(): | ||
| self.is_valid, self.collection_cases = UnionTypeHelper.validate_array_of_dict_case(self._union_types, value, | ||
| False) | ||
| elif context.is_array() and context.is_dict(): | ||
| self.is_valid, self.collection_cases = UnionTypeHelper.validate_dict_of_array_case(self._union_types, value, | ||
| False) | ||
| elif context.is_array(): | ||
| self.is_valid, self.collection_cases = UnionTypeHelper.validate_array_case(self._union_types, value, False) | ||
| elif context.is_dict(): | ||
| self.is_valid, self.collection_cases = UnionTypeHelper.validate_dict_case(self._union_types, value, False) | ||
| else: | ||
| self.is_valid = UnionTypeHelper.get_matched_count(value, self._union_types, False) >= 1 | ||
|
|
||
| def __deepcopy__(self, memo={}): | ||
| copy_object = AnyOf(self._union_types, self._union_type_context) | ||
| copy_object.is_valid = self.is_valid | ||
| copy_object.collection_cases = self.collection_cases | ||
| copy_object.error_messages = self.error_messages | ||
| return copy_object |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.