Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Feature/backing store support #137

Merged
merged 7 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions .github/workflows/build_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,22 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pipenv
pipenv install -r requirements-dev.txt
pip install -r requirements-dev.txt
- name: Check code format
run: |
pipenv run yapf -dr kiota_serialization_json
yapf -dr kiota_serialization_json
- name: Check import order
run: |
pipenv run isort kiota_serialization_json
isort kiota_serialization_json
- name: Lint with Pylint
run: |
pipenv run pylint kiota_serialization_json --disable=W --rcfile=.pylintrc
pylint kiota_serialization_json --disable=W --rcfile=.pylintrc
- name: Static type checking with Mypy
run: |
pipenv run mypy kiota_serialization_json
mypy kiota_serialization_json
- name: Run tests with Pytest
run: |
pipenv run pytest
pytest

publish:
name: Publish distribution to PyPI
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.4.0] - 2023-07-27

### Added

### Changed
- Enabled backing store support

## [0.3.7] - 2023-07-04

### Added
Expand Down
54 changes: 0 additions & 54 deletions Pipfile

This file was deleted.

2 changes: 1 addition & 1 deletion kiota_serialization_json/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION: str = '0.3.7'
VERSION: str = '0.4.0'
59 changes: 35 additions & 24 deletions kiota_serialization_json/json_parse_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@

class JsonParseNode(ParseNode, Generic[T, U]):

on_before_assign_field_values: Optional[Callable[[Parsable], None]] = None
on_after_assign_field_values: Optional[Callable[[Parsable], None]] = None

def __init__(self, node: Any) -> None:
"""
Args:
node (Any): The JsonElement\
to initialize the node with
"""
self._json_node = node
self._on_before_assign_field_values: Optional[Callable[[Parsable], None]] = None
self._on_after_assign_field_values: Optional[Callable[[Parsable], None]] = None

def get_child_node(self, identifier: str) -> Optional[ParseNode]:
"""Gets a new parse node for the given identifier
Expand All @@ -41,7 +40,7 @@ def get_child_node(self, identifier: str) -> Optional[ParseNode]:
raise ValueError("identifier cannot be None or empty.")

if isinstance(node := self._json_node, dict) and identifier in node:
return JsonParseNode(node[identifier])
return self._create_new_node(node[identifier])
return None

def get_str_value(self) -> Optional[str]:
Expand Down Expand Up @@ -142,7 +141,7 @@ def get_collection_of_primitive_values(self, primitive_type: Any) -> Optional[Li

def func(item):
generic_type = primitive_type if primitive_type else type(item)
current_parse_node = JsonParseNode(item)
current_parse_node = self._create_new_node(item)
if generic_type in primitive_types:
method = getattr(current_parse_node, f'get_{generic_type.__name__.lower()}_value')
return method()
Expand All @@ -160,7 +159,7 @@ def get_collection_of_object_values(self, factory: ParsableFactory) -> List[U]:
if isinstance(self._json_node, list):
return list(
map(
lambda x: JsonParseNode(x).get_object_value(factory), # type: ignore
lambda x: self._create_new_node(x).get_object_value(factory), # type: ignore
self._json_node,
)
)
Expand All @@ -172,7 +171,9 @@ def get_collection_of_enum_values(self, enum_class: K) -> List[Optional[K]]:
List[K]: The collection of enum values
"""
if isinstance(self._json_node, list):
return list(map(lambda x: JsonParseNode(x).get_enum_value(enum_class), self._json_node))
return list(
map(lambda x: self._create_new_node(x).get_enum_value(enum_class), self._json_node)
)
return []

def get_enum_value(self, enum_class: K) -> Optional[K]:
Expand Down Expand Up @@ -203,11 +204,11 @@ def get_object_value(self, factory: ParsableFactory) -> U:
"""

result = factory.create_from_discriminator_value(self)
if self.on_before_assign_field_values:
self.on_before_assign_field_values(result)
if on_before := self.on_before_assign_field_values:
on_before(result)
self._assign_field_values(result)
if self.on_after_assign_field_values:
self.on_after_assign_field_values(result)
if on_after := self.on_after_assign_field_values:
on_after(result)
return result

def get_bytes_value(self) -> Optional[bytes]:
Expand All @@ -220,35 +221,39 @@ def get_bytes_value(self) -> Optional[bytes]:
return None
return base64_string.encode("utf-8")

def get_on_before_assign_field_values(self) -> Optional[Callable[[Parsable], None]]:
"""Gets the callback called before the node is deserialized.
Returns:
Callable[[Parsable], None]: the callback called before the node is deserialized.
"""
return self.on_before_assign_field_values

def get_on_after_assign_field_values(self) -> Optional[Callable[[Parsable], None]]:
@property
def on_before_assign_field_values(self) -> Optional[Callable[[Parsable], None]]:
"""Gets the callback called before the node is deserialized.
Returns:
Callable[[Parsable], None]: the callback called before the node is deserialized.
"""
return self.on_after_assign_field_values
return self._on_before_assign_field_values

def set_on_before_assign_field_values(self, value: Callable[[Parsable], None]) -> None:
@on_before_assign_field_values.setter
def on_before_assign_field_values(self, value: Callable[[Parsable], None]) -> None:
"""Sets the callback called before the node is deserialized.
Args:
value (Callable[[Parsable], None]): the callback called before the node is
deserialized.
"""
self.on_before_assign_field_values = value
self._on_before_assign_field_values = value

def set_on_after_assign_field_values(self, value: Callable[[Parsable], None]) -> None:
@property
def on_after_assign_field_values(self) -> Optional[Callable[[Parsable], None]]:
"""Gets the callback called before the node is deserialized.
Returns:
Callable[[Parsable], None]: the callback called before the node is deserialized.
"""
return self._on_after_assign_field_values

@on_after_assign_field_values.setter
def on_after_assign_field_values(self, value: Callable[[Parsable], None]) -> None:
"""Sets the callback called after the node is deserialized.
Args:
value (Callable[[Parsable], None]): the callback called after the node is
deserialized.
"""
self.on_after_assign_field_values = value
self._on_after_assign_field_values = value

def _assign_field_values(self, item: U) -> None:
"""Assigns the field values to the model object"""
Expand Down Expand Up @@ -306,3 +311,9 @@ def try_get_anything(self, value: Any) -> Any:
pass
return value
raise ValueError(f"Unexpected additional value type {type(value)} during deserialization.")

def _create_new_node(self, node: Any) -> JsonParseNode:
new_node: JsonParseNode = JsonParseNode(node)
new_node.on_before_assign_field_values = self.on_before_assign_field_values
new_node.on_after_assign_field_values = self.on_after_assign_field_values
return new_node
Loading