Fix merge-patch deletion for record values - #11695
Open
Vivek JM (vivekjm) wants to merge 2 commits into
Open
Conversation
Vivek JM (vivekjm)
requested review from
catalinaperalta,
iscai-msft,
Laurent Mazuel (lmazuel),
Mark Cowlishaw (markcowl) and
Timothee Guerin (timotheeguerin)
as code owners
August 16, 2026 06:57
|
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. |
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Enables MergePatchUpdate-transformed Record properties to accept null values so clients can delete individual record keys via merge patch semantics.
Changes:
- Update merge-patch transformation so record indexer values become nullable (
T | null). - Add/adjust tests to assert record element/indexer value types are nullable unions.
- Add Chronus change entry documenting the fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/http/src/merge-patch.ts | Makes record indexer values nullable to represent per-key deletion in merge patches. |
| packages/http/test/merge-patch.test.ts | Adds and updates tests validating nullable record values and related visibility transforms. |
| .chronus/changes/merge-patch-null-record-values-2026-08-16.md | Documents the behavioral fix for @typespec/http. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (2)
packages/http/src/merge-patch.ts:506
- Deduping via
types.includes(type)makesnullableRecordValueO(n²) in the number of variants when flattening larger unions. Consider tracking aSet<Type>for membership checks while still building an array forunion.create(...)to keep variant collection O(n).
function nullableRecordValue(realm: Realm, type: Type): Union {
const types: Type[] = [];
addType(type);
addType($(realm).intrinsic.null);
return $(realm).union.create(types);
function addType(type: Type): void {
if ($(realm).union.is(type)) {
for (const variant of type.variants.values()) {
addType(variant.type);
}
} else if (!types.includes(type)) {
types.push(type);
}
}
}
packages/http/test/merge-patch.test.ts:1026
- This test checks null-ness via direct reference equality to
$(runner.program).intrinsic.null, while other helpers (e.g.,checkNullableUnion) detect null intrinsics by kind/name. To avoid brittle failures if null intrinsics aren’t guaranteed to be referentially identical, consider using the same intrinsic check pattern here (e.g.,$(program).intrinsic.is(...)andnamecomparison).
expect(
[...recordValue.variants.values()].filter(
(variant) => variant.type === $(runner.program).intrinsic.null,
),
).toHaveLength(1);
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Recordvalue types nullable for JSON Merge Patch requestsnulldeletion branchFixes #11533.
Root cause
MergePatchUpdatemade the record property itself nullable, allowing an entire map to be cleared, but only transformed the record's value when it was a complex merge-patch subject. A scalar value such asRecord<string>therefore remainedstring, so{ "tags": { "a": null } }could not represent deletion of one key.Testing
pnpm --filter '@typespec/http...' run buildpnpm --filter @typespec/http exec vitest run test/merge-patch.test.ts— 38 tests passedpnpm --filter @typespec/http run buildpnpm exec prettier --check packages/http/src/merge-patch.ts packages/http/test/merge-patch.test.ts .chronus/changes/merge-patch-null-record-values-2026-08-16.mdpnpm --filter @typespec/http run lintgit diff --checkLocal setup note: the first focused test invocation ran before the HTTP package and its optional Streams dependency were built, so package resolution failed before any assertions executed. Building the HTTP dependency closure resolved that bootstrap issue; the focused suite and all checks above then passed.