Skip to content
This repository was archived by the owner on Aug 24, 2026. It is now read-only.

feat: support composed types in write_object_value - #88

Merged
Vincent Biret (baywet) merged 4 commits into
microsoft:mainfrom
andreaTP:feat/composed-type-support
Aug 20, 2026
Merged

feat: support composed types in write_object_value#88
Vincent Biret (baywet) merged 4 commits into
microsoft:mainfrom
andreaTP:feat/composed-type-support

Conversation

@andreaTP

Copy link
Copy Markdown
Contributor

Based on: microsoft/kiota-ruby#106

Update write_object_value to accept variadic additional_values_to_merge for intersection type serialization and handle ComposedTypeWrapper by serializing directly into the current writer instead of a temp.

Refactor write_collection_of_object_values to create its own temp writers instead of delegating to write_object_value, since the nil-key path now serializes into self.

Update write_object_value to accept variadic additional_values_to_merge
for intersection type serialization and handle ComposedTypeWrapper by
serializing directly into the current writer instead of a temp.

Refactor write_collection_of_object_values to create its own temp
writers instead of delegating to write_object_value, since the nil-key
path now serializes into self.
Comment thread lib/microsoft_kiota_serialization_json/json_serialization_writer.rb Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the JSON serialization writer to properly support composed types (union/intersection wrappers) by allowing write_object_value to merge multiple Parsable instances and to serialize nil-key object values directly into the current writer (instead of via a temporary writer). It also refactors collection serialization to avoid contaminating the parent writer under the new nil-key behavior, and adds dedicated specs covering these composed-type scenarios.

Changes:

  • Extend write_object_value to accept variadic additional_values_to_merge and merge them during serialization (intersection support).
  • Change write_object_value(nil, ...) behavior to serialize directly into the current writer (enabling composed wrappers to work without needing to handle a returned temp writer).
  • Refactor write_collection_of_object_values to always serialize items into per-item temp writers, returning them when key is nil.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/microsoft_kiota_serialization_json/json_serialization_writer.rb Implements composed-type support in write_object_value and refactors object-collection serialization to use temp writers.
spec/json_serialization_writer_composed_type_spec.rb Adds coverage for composed types (union/intersection) and updated nil-key serialization semantics.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread spec/json_serialization_writer_composed_type_spec.rb Outdated
Delegate to write_object_value instead of creating temp
JsonSerializationWriter instances directly, aligning with how other
Kiota language implementations handle collection serialization.
Also removes redundant require and adds ComposedTypeWrapper polyfill
for the test suite.

@baywet Vincent Biret (baywet) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making the changes!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

lib/microsoft_kiota_serialization_json/json_serialization_writer.rb:155

  • The keyed path temporarily writes each element into @writer[key] and then deletes it to capture the value. This mutates the parent writer during serialization; if an element raises during serialize, @writer can be left in a partially mutated state (and any prior @writer[key] value is overwritten). It’s also extra work compared to building each element in an isolated temp writer.
        @writer[key] = values.map do |v|
          write_object_value(key, v)
          @writer.delete(key)
        end

Comment thread lib/microsoft_kiota_serialization_json/json_serialization_writer.rb
Centralizes temp writer creation into a private helper shared by
write_object_value and write_collection_of_object_values, eliminating
the fragile write-then-delete pattern from the keyed collection path.
@andreaTP

Copy link
Copy Markdown
Contributor Author

Should be ready for final review.

@baywet

Copy link
Copy Markdown
Member

Andrea Peruffo (@andreaTP) I'm not sure why but the abstractions dependency update is not coming through dependabot. Can you also add that as part of your PR please?

Requires v0.16.0 which includes ComposedTypeWrapper, ParseNodeHelper,
and the updated write_object_value signature needed for composed type
support. Removes the test polyfill that was standing in for these.
@sonarqubecloud

Copy link
Copy Markdown

@baywet Vincent Biret (baywet) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making the changes!

@baywet
Vincent Biret (baywet) enabled auto-merge (squash) August 20, 2026 16:44
@baywet
Vincent Biret (baywet) merged commit 7afc1d9 into microsoft:main Aug 20, 2026
24 checks passed
@andreaTP

Copy link
Copy Markdown
Contributor Author

Let me know when this one is released so that I'll unblock the kiota PR 🙏

@baywet

Copy link
Copy Markdown
Member

Andrea Peruffo (@andreaTP) it's out! https://rubygems.org/gems/microsoft_kiota_serialization_json/versions/0.11.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants