Skip to content

[C#] Correct index consumption in dynamic-model collection patch paths - #12437

Merged
Jorge Rangel (jorgerangel-msft) merged 3 commits into
mainfrom
copilot/fix-incorrect-bytesconsumed-issue
Oct 29, 2026
Merged

Jorge Rangel (jorgerangel-msft) merged 3 commits into
mainfrom
copilot/fix-incorrect-bytesconsumed-issue

Conversation

Copilot AI commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Generated TryGetIndex counts only index digits, but collection propagators slice past the entire [index] segment. This forwards malformed child paths and breaks nested JsonPatch reads and writes.

  • Generator: Include both brackets in successful bytesConsumed; preserve parse-failure behavior.
  • Snapshots: Update the helper baseline and generated sample.
  • Regression coverage: Exercise single- and multi-digit indices, invalid indices, nested lists, and parent-to-child patch reads and writes.
Input:             [12].description
bytesConsumed:     2 → 4
Forwarded path:    $2].description → $.description

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Oct 29, 2026
Copilot AI changed the title [WIP] Fix incorrect bytesConsumed in TryGetIndex for nested JsonPatch [C#] Correct index consumption in dynamic-model collection patch paths Oct 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the collection-path forwarding fix.

No open issues 🎉

What changed in this PR

This PR fixes collection-path forwarding in generated C# dynamic models, addressing #12431 so nested JsonPatch reads and writes receive the correct child path.

Changes:

  • Count both brackets in successful TryGetIndex consumption while preserving parse-failure behavior.
  • Update the generated sample and helper baseline.
  • Add regression tests for index parsing and parent-to-child patch propagation through single and nested collections.
File Description
packages/​http-client-csharp/​generator/​TestProjects/​Local/​Sample-TypeSpec/​src/​Generated/​Internal/​ModelSerializationExtensions.cs Updates the generated helper’s consumed-byte count.
packages/​http-client-csharp/​generator/​TestProjects/​Local.Tests/​ModelSerializationExtensionsTests.cs Tests valid indices, remaining paths, and invalid inputs.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.ClientModel/​test/​Providers/​Definitions/​TestData/​ModelSerializationExtensionsDefinitionTests/​ValidateTryGetIndex.cs Updates the expected generated helper baseline.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.ClientModel/​test/​ModelReaderWriterValidation/​TestProjects/​Sample_TypeSpec/​DynamicModelTests.cs Tests collection-based patch reads and writes with single- and multi-digit indices.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.ClientModel/​src/​Providers/​ModelSerializationExtensionsDefinition.cs Emits the bracket-inclusive consumed-byte count after successful parsing.

Review effort: Balanced

@pkg-pr-new

pkg-pr-new Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@12437

commit: 65f3c2d

Copilot AI balanced review requested due to automatic review settings October 29, 2026 17:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the collection-index consumption fix supporting nested JsonPatch operations.

No open issues 🎉

Review effort: Balanced

Merged via the queue into main with commit fd7d9c8 Oct 29, 2026
31 checks passed
@jorgerangel-msft
Jorge Rangel (jorgerangel-msft) deleted the copilot/fix-incorrect-bytesconsumed-issue branch October 29, 2026 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C#] Incorrect bytesConsumed in generated TryGetIndex breaks nested JsonPatch propagation through collections

5 participants