Preserve generated model operator parameter names - #11670
Preserve generated model operator parameter names#11670Jorge Rangel (jorgerangel-msft) with Copilot wants to merge 11 commits into
Conversation
|
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>
commit: |
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
There was a problem hiding this comment.
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 result → response).
Changes:
- Recursively runs back-compat processing for a type’s
SerializationProvidersso operator/member signature preservation applies to generated serialization partials. - Updates
MrwSerializationTypeDefinitionback-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>
Jorge Rangel (jorgerangel-msft)
left a comment
There was a problem hiding this comment.
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>
Added in 1c7536a: a new |
There was a problem hiding this comment.
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, whileCSharpGen.cs:98-122writes both every top-level provider and each provider's serializers, andLibraryVisitor.cs:21-85visits both paths. This causes every model serialization file to be added and processed twice and can make non-idempotent visitors run twice. KeepTypeProvidersunique and instead recurse intoSerializationProviderswhen 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>
Generated model conversion operators could rename parameters from a previous contract, causing CP0017 API compatibility failures.