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

Commit

Permalink
Merge pull request #43 from microsoft/shem/fix_form_serialization_con…
Browse files Browse the repository at this point in the history
…tent_writing_error

remove null checks for key/value in write_object_value
  • Loading branch information
shemogumbe authored Aug 21, 2024
2 parents e345d77 + 6667f01 commit 5c3db6e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

## [0.1.1] - 2024-02-21

### Added
- Added a check to prevent form serialization from supporting nested
### Removed
- Removed a null check for keys during the serialization process.

### Changed


## [0.1.0] - 2024-02-21

### Added
Expand Down
2 changes: 1 addition & 1 deletion kiota_serialization_form/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION: str = '0.1.0'
VERSION: str = '0.1.1'
39 changes: 21 additions & 18 deletions kiota_serialization_form/form_serialization_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class FormSerializationWriter(SerializationWriter):

def __init__(self) -> None:
self.writer: str = ""
self.depth = 0

self._on_start_object_serialization: Optional[Callable[[Parsable, SerializationWriter],
None]] = None
Expand Down Expand Up @@ -186,24 +187,26 @@ def write_object_value(
additional_values_to_merge (tuple[Parsable]): The additional values to merge to the
main value when serializing an intersection wrapper.
"""
if key and (value or additional_values_to_merge):
temp_writer = self._create_new_writer()

if value:
self._serialize_value(temp_writer, value)

if additional_values_to_merge:
for additional_value in filter(lambda x: x is not None, additional_values_to_merge):
self._serialize_value(temp_writer, additional_value)
if on_after := self.on_after_object_serialization:
on_after(additional_value)

if value and self._on_after_object_serialization:
self._on_after_object_serialization(value)

if len(self.writer) > 0:
self.writer += "&"
self.writer += f"{quote_plus(key.strip())}={temp_writer.writer}"
if self.depth > 0:
raise Exception("Form serialization does not support nested objects.")
self.depth += 1
temp_writer = self._create_new_writer()

if value is not None:
self._serialize_value(temp_writer, value)

for additional_value in filter(lambda x: x is not None, additional_values_to_merge):
self._serialize_value(temp_writer, additional_value)
if on_after := self.on_after_object_serialization:
on_after(additional_value)

if value and self._on_after_object_serialization:
self._on_after_object_serialization(value)

if len(self.writer) > 0:
self.writer += "&"
self.writer += f"{quote_plus(key.strip()) if key is not None else ''}={temp_writer.writer}"
self.depth -= 1

def write_null_value(self, key: Optional[str]) -> None:
"""Writes a null value for the specified key.
Expand Down

0 comments on commit 5c3db6e

Please sign in to comment.