Generate back-compat overload when a service method gains a new optional non-body parameter#10532
Generate back-compat overload when a service method gains a new optional non-body parameter#10532
Conversation
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/bb773994-13fe-4a5a-971a-b594a6d82388 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
commit: |
…dict Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/98e4708e-374c-4348-8b5b-30e4c877bd56 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/eaa4071b-877d-4406-a1ca-63af4e8c07c5 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/fdf69480-deaf-4b00-8d8a-e88ad22e8313 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/df3eba50-228a-4ff8-88e1-756b943c65dc Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
jorgerangel-msft
left a comment
There was a problem hiding this comment.
@copilot we need to also add unit tests that exercise the scenario where there is a model body type in operation.
…naming Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/1d3d7484-11d8-4289-866b-9b8fa8f1d4a9 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/1d3d7484-11d8-4289-866b-9b8fa8f1d4a9 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Added |
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/af254bc1-2d6e-4c6f-bd54-8eebe1cdba56 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/dcc6b3ed-492d-4ad0-8452-da4e8ccfe12a Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
jorgerangel-msft
left a comment
There was a problem hiding this comment.
@copilot lets also add at least 1 test where we utilize path params mixed with query and header
…er test, refine docs Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/1c242ed5-2826-4b96-be51-1161c90ff229 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Added |
…op unused comparer, trim docs Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/47365c54-329e-421a-ba22-e8bcb81a5ec1 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/637c9d8b-3cd8-40eb-aa73-3c87be64c020 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Adding an optional parameter to a service method is non-breaking in TypeSpec but breaks generated C# clients (callers binding to the old method signature fail to resolve). The generator now mirrors the Service-Driven Evolution guidance and emits a hidden overload matching the previous contract's signature.
Changes
ClientProvider.BuildMethodsForBackCompatibility— after parameter reordering, scansLastContractView.Methodsfor previous signatures whose parameters are a same-order subset of a current method, where every extra current parameter is optional and non-body. Emits a hidden[EditorBrowsable(Never)]ScmMethodProvideroverload (sameScmMethodKindas the current method) that delegates to the current method via theThis.Invoke(string methodName, IReadOnlyList<ValueExpression> arguments)snippet, passingdefaultfor each new parameter. Async overloads delegate withoutawaitso the back-compat method itself remains non-async. The reordering and new-optional-parameter passes are factored into private helpers (ProcessBackCompatForParameterReorderingandProcessBackCompatForNewOptionalParameters) which share a singlecurrentMethodSignaturesdictionary and mutate the samematerializedMethodslist. The new-optional-parameter pass skipsScmMethodProviders withKind == CreateRequestand only generates overloads for matched candidates whoseKindisConvenienceorProtocol, inheriting thatKind/ServiceMethodfrom the current method. The candidate match collapses theScmMethodProvider/Convenience|Protocolfilter into the candidates loop's pattern match, andcurrentMethodSignatures.TryAddis reused both for dedup and to make new overloads visible to subsequent iterations (no auxiliary lists or sets).BackCompatibilityChangeCategory.SvcMethodNewOptionalParameterOverloadAdded— new category surfaced in the emitter end-of-run summary.BackCompatibility_NewOptionalNonBodyParameterAdded,BackCompatibility_MultipleNewOptionalNonBodyParametersAdded,BackCompatibility_NewOptionalNonBodyParameterAddedWithModelBody(covers anInputModelTyperequest body),BackCompatibility_NewOptionalNonBodyParameterAddedWithPathAndHeaderParameters(covers a method whose previous contract mixes a path parameter with a required query and a required header),BackCompatibility_NewOptionalBodyParameterDoesNotAddBackCompatOverload,BackCompatibility_NewRequiredParameterDoesNotAddBackCompatOverload. All six tests runTypeProviderWriter.Write()on the affected client wrapped in aFilteredMethodsTypeProviderso the expected.csfixtures underTestData/ClientProviderTests/only contain the affected operation's protocol + convenience + back-compat methods.backward-compatibility.mdshowing the full generated client (current sync/async then back-compat sync/async) with one-sentence per-overload comments, the optional default shown asdefault, theasyncmodifier on the current async method, and the back-compat delegating call using named arguments. Includes a note verifying Azure SDK parameter ordering and a note explaining why the async back-compat overload returns theTaskdirectly withoutawait.Example
Previous contract:
Current TypeSpec adds an optional
@query p2?: boolean. Generated client:Defaults are stripped from the back-compat signature to avoid ambiguous call sites with the current method.