Skip to content

Handle enum value order changes using LastContractView#9906

Queued
Copilot wants to merge 9 commits intomainfrom
copilot/fix-enum-order-handling
Queued

Handle enum value order changes using LastContractView#9906
Copilot wants to merge 9 commits intomainfrom
copilot/fix-enum-order-handling

Conversation

Copy link
Contributor

Copilot AI commented Mar 4, 2026

  • Move BuildEnumValuesForBackCompatibility to TypeProvider as protected internal virtual
  • Remove IsIntValueType check — applies to all fixed enum types
  • Perform single Update call at end of ProcessTypeForBackCompatibility
  • Revert string init value change in test data
  • Remove explicit initialization values — let compiler auto-assign based on order
  • Remove code comment from BuildEnumValuesForBackCompatibility
  • Run eng/scripts/Generate.ps1
Original prompt

This section details on the original issue you should resolve

<issue_title>LastContractView - handle eunm value order changes</issue_title>
<issue_description>Generator should be able to mitigate the breaking changes of enum order change to avoid custom code
such as https://github.com/Azure/azure-sdk-for-net/pull/53793/files#diff-2cb7c6853530fb07e8cf57678ea6093784b9d342b63785ad34a5b478e2962b4b</issue_description>

<agent_instructions>You are a .NET expert. Apply the fix for this but it should only be scoped to int enums. WRite proper unit tests exercising the scenario and also rerun ./eng/scripts/Generate.ps1 once you confirm all tests pass.</agent_instructions>

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

@jorgerangel-msft @live1206 - just to get clarity, in the example you linked the generated enum was
public enum KeyVaultCreateMode
    {
        /// <summary> recover. </summary>
        /// <summary> Recover. </summary>
        Recover,
        /// <summary> default. </summary>
        /// <summary> Default. </summary>
        Default,
    }

?</comment_new>
<comment_new>@live1206
@jorgerangel-msft Yes, the order of enum value changed from previous GA version.</comment_new>


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Add backward compatibility logic in FixedEnumProvider.BuildEnumValues() to
preserve enum member order and initialization values from the last contract
for int-based fixed enums. This avoids breaking changes when the spec
reorders enum values.

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
@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 Mar 4, 2026
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix LastContractView to handle enum value order changes Handle int enum value order changes using LastContractView Mar 4, 2026
…ackCompatibility

Move BuildEnumValuesForBackCompatibility to be a protected internal virtual
method on TypeProvider, invoked from ProcessTypeForBackCompatibility when
the type is an EnumProvider. FixedEnumProvider overrides it. Removed the
IsIntValueType guard so string enums are also covered.

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copilot AI changed the title Handle int enum value order changes using LastContractView Handle enum value order changes using LastContractView Mar 4, 2026
…data

- TypeProvider.ProcessTypeForBackCompatibility: perform a single Update
  call at the end of the method instead of two separate calls.
- BackCompat_StringEnumOrderPreserved test data: changed from a C# enum
  to a static class with const string fields so the test data has actual
  string initialization values.

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
…it values)

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 4, 2026

Open in StackBlitz

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

commit: d05b029

…let compiler auto-assign

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

No changes needing a change description found.

@jorgerangel-msft jorgerangel-msft added this pull request to the merge queue Mar 4, 2026
Any commits made after this event will not be merged.
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.

LastContractView - handle eunm value order changes

3 participants