Skip to content

fix: support primitive members in composed types - #142

Merged
Vincent Biret (baywet) merged 1 commit into
microsoft:mainfrom
andreaTP:fix/composed-type-primitive-members
Aug 27, 2026
Merged

fix: support primitive members in composed types#142
Vincent Biret (baywet) merged 1 commit into
microsoft:mainfrom
andreaTP:fix/composed-type-primitive-members

Conversation

@andreaTP

Copy link
Copy Markdown
Contributor

Composed-type support was implemented and tested for object members only; every existing spec uses a Parsable. The primitive paths were written speculatively and never had a consumer, so three defects went unnoticed until a generator emitted them (microsoft/kiota#8065).

Deserialization could not discriminate. JsonParseNode's scalar getters coerce -- get_string_value is to_s, get_number_value is to_i -- so every getter answers for any payload and a union always selected its first member. Rather than making the existing getters type-strict, which would break clients that rely on coercion, add try_get_string_value / try_get_boolean_value / try_get_number_value / try_get_float_value. These return nil unless the node really is that type. Integer and Float stay distinct because JSON already distinguishes 1 from 1.0.

Serialization discarded scalars. write_*_value(nil, value) returned the value without storing it, so a composed type whose selected member was a primitive serialized to {}. A nil key now means "this scalar is the document"; the writer keeps a root value and get_serialized_content emits it. The guards also tested falsiness rather than nil, so writing false raised.

write_object_value dropped members after a leading nil: return unless value discarded the remaining arguments, losing every member of an intersection whose first member was unset. It now compacts before writing.

Adds specs for each, including a false value and a leading-nil intersection.

@andreaTP
Andrea Peruffo (andreaTP) requested a review from a team as a code owner August 26, 2026 14:40
@andreaTP
Andrea Peruffo (andreaTP) force-pushed the fix/composed-type-primitive-members branch 2 times, most recently from 30d8392 to ebda42f Compare August 27, 2026 09:46
- scalar readers return nil on a type mismatch, matching dotnet and Python
- get_collection_of_primitive_values dispatched on the class, so no branch ever matched
- write_*_value(nil, value) discarded the scalar instead of storing it
@andreaTP
Andrea Peruffo (andreaTP) force-pushed the fix/composed-type-primitive-members branch from ebda42f to e1ee161 Compare August 27, 2026 10:10

@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) merged commit 2a64b1d into microsoft:main Aug 27, 2026
71 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants