Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 19, 2026

Fix Encode Metadata Propagation for Merge Patch Properties

  • Understand the repository structure and build system
  • Analyze how encode metadata is extracted from model properties
  • Identify that encode is read using getEncode(context.program, type) where type is a ModelProperty
  • Discover that TypeSpec creates derived ModelProperty objects with sourceProperty when implicitOptionality is used
  • Create comprehensive test cases to validate the fix (arrays, datetime, duration)
  • Apply fix to check sourceProperty when encode data is not found on derived properties
  • Fix applies to both array encoding and other encoding types (datetime, duration, bytes, int)
  • Run tests to verify the fix works correctly
  • Run code review and security checks
Original prompt

This section details on the original issue you should resolve

<issue_title>[TCGC] encode missing for patched model</issue_title>
<issue_description>### Describe the bug

The encode metadata is not propagated or honored for optional properties when constructing the Merge Patch update model, causing emitters to generate non-encoded serialization paths for optionals.

Reproduction

TypeSpec

import "@typespec/http";
using Http;

@service(#{ title: "Array Encoding Test Service" })
namespace Encode.Array;

model Widget {
    @visibility(Lifecycle.Read)
    id: string;

    @encode(ArrayEncoding.commaDelimited)
    requiredColors: string[];

    @encode(ArrayEncoding.spaceDelimited)
    optionalColors?: string[];

}

@route("/widgets")
@tag("Widgets")
interface Widgets {
    /** Update a widget */
  @patch update(
    @path id: Widget.id,
    @body widget: MergePatchUpdate<Widget>,
  ): Widget;
}

Need to check whether encode is applied to WidgetMergePatchUpdate.optionalColors.

Checklist

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 19, 2026 06:03
Co-authored-by: tadelesh <1726438+tadelesh@users.noreply.github.com>
Co-authored-by: tadelesh <1726438+tadelesh@users.noreply.github.com>
Copilot AI requested a review from tadelesh January 19, 2026 06:25
Copilot stopped work on behalf of tadelesh due to an error January 19, 2026 06:25
@microsoft-github-policy-service microsoft-github-policy-service bot added the lib:tcgc Issues for @azure-tools/typespec-client-generator-core library label Jan 19, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 19, 2026

Open in StackBlitz

npm i https://pkg.pr.new/Azure/typespec-azure/@azure-tools/typespec-client-generator-core@3797

commit: 0f5209f

@tadelesh tadelesh marked this pull request as ready for review January 19, 2026 07:18
@tadelesh tadelesh changed the title [WIP] Fix encode propagation for optional properties in Merge Patch Fix encode propagation for optional properties in Merge Patch Jan 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lib:tcgc Issues for @azure-tools/typespec-client-generator-core library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TCGC] encode missing for patched model

2 participants