Skip to content

Preserve generated model operator parameter names - #11670

Draft
Jorge Rangel (jorgerangel-msft) with Copilot wants to merge 11 commits into
mainfrom
copilot/handle-back-compat-model-operators
Draft

Preserve generated model operator parameter names#11670
Jorge Rangel (jorgerangel-msft) with Copilot wants to merge 11 commits into
mainfrom
copilot/handle-back-compat-model-operators

Conversation

Copilot AI commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Generated model conversion operators could rename parameters from a previous contract, causing CP0017 API compatibility failures.

  • Back compatibility
    • Match explicit conversion operators against the last contract by signature.
    • Restore the published parameter name for JSON and XML model operators.
    • Keep the current name when no matching contract exists.
public static explicit operator AcknowledgeResult(Response result)

@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.

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 Aug 14, 2026
@pkg-pr-new

pkg-pr-new Bot commented Aug 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: ec58d8a

Copilot AI changed the title [WIP] Fix back compatibility in generated model operator parameter names Preserve generated model operator parameter names Aug 14, 2026
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copilot AI and others added 2 commits August 14, 2026 17:29
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copilot AI and others added 2 commits August 14, 2026 18:34
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>

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.

Pull request overview

This PR updates the C# client generator’s back-compat processing so generated serialization type providers also participate, ensuring public conversion operator parameter names are preserved from the last published contract (preventing CP0017 APICompat breaks like resultresponse).

Changes:

  • Recursively runs back-compat processing for a type’s SerializationProviders so operator/member signature preservation applies to generated serialization partials.
  • Updates MrwSerializationTypeDefinition back-compat method handling to run the base back-compat logic specifically for generated operator methods.
  • Adds tests + baseline assets verifying operator parameter names are preserved when a last-contract exists, and left as-is when it doesn’t.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/TypeProvider.cs Ensures back-compat processing is applied to serialization providers, not only top-level providers.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs Applies base back-compat method logic to operator methods to preserve prior parameter names without introducing overloads.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/MrwSerializationTypeDefinitionTests.cs Adds coverage for parameter name preservation with/without a last-contract baseline.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/MrwSerializationTypeDefinitionTests/ExplicitClientResultOperatorPreservesLastContractParameterName/MockInputModel.cs Provides last-contract input defining the published operator parameter name (result).
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/MrwSerializationTypeDefinitionTests/ExplicitClientResultOperatorPreservesLastContractParameterName.cs Expected generated output verifying the preserved operator parameter name when last-contract is present.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/MrwSerializationTypeDefinitionTests/ExplicitClientResultOperatorKeepsCurrentParameterNameWithoutLastContract.cs Expected generated output verifying current parameter name is kept when no last-contract exists.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…providers

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

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.

Copilot I'd like to see a unit test where TestTypePRovider is setup with serialiation provider that has back compat operators. Then we process both types for back compat and validate the generated code looks as expected

…ator test

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

Copilot AI commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

Copilot I'd like to see a unit test where TestTypePRovider is setup with serialiation provider that has back compat operators. Then we process both types for back compat and validate the generated co...

Added in 1c7536a: a new TypeProviderTests unit test sets up a TestTypeProvider with a serialization provider that has an explicit operator, processes both providers for back-compat, and validates generated code via TestData baselines.

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.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

Suppressed comments (1)

packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/ScmOutputLibrary.cs:97

  • Adding serialization providers as top-level providers duplicates them: each remains in its model's SerializationProviders, while CSharpGen.cs:98-122 writes both every top-level provider and each provider's serializers, and LibraryVisitor.cs:21-85 visits both paths. This causes every model serialization file to be added and processed twice and can make non-idempotent visitors run twice. Keep TypeProviders unique and instead recurse into SerializationProviders when running back-compatibility processing.
                ..serializationTypes,

…en traversal

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
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.

Handle Back Compat In Generated Model Operators Param Names

3 participants