Skip to content

Param alias#10039

Open
radhgupta wants to merge 13 commits intomicrosoft:mainfrom
radhgupta:paramAlias
Open

Param alias#10039
radhgupta wants to merge 13 commits intomicrosoft:mainfrom
radhgupta:paramAlias

Conversation

@radhgupta
Copy link
Member

This pull request introduces support for the @paramAlias decorator in the C# HTTP client generator, enabling client parameters to be referenced by an alias when specified. The changes ensure that aliasing is respected throughout code generation, parameter matching, and testing, improving consistency and correctness when using parameter aliases in client models and operations.

Support for @paramAlias decorator:

  • Added paramAlias property to the InputMethodParameter type and ensured it is serialized/deserialized correctly in the generator input and output.

Parameter matching and code generation improvements:

  • Modified logic in ClientProvider and RestClientProvider to consider both parameter names and aliases when determining shared parameters between parent and subclient, and when mapping client parameters to operation parameters.
    Testing enhancements:

  • Added unit tests to verify correct handling of paramAlias in client initialization and parameter matching, including scenarios where aliases are present or absent.
    Test infrastructure updates:

  • Extended InputFactory.MethodParameter to accept a paramAlias argument for easier test setup and validation.

@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 16, 2026
@github-actions
Copy link
Contributor

No changes needing a change description found.

@JoshLove-msft
Copy link
Contributor

JoshLove-msft commented Mar 16, 2026

Can we add an E2E example in the sample tsp?

…ameter bug

Add an E2E example demonstrating @paramAlias with @clientInitialization in
the Sample-TypeSpec project. The Notebooks interface shows a client parameter
'notebook' aliased to the operation's 'notebookName' path parameter.

Fix a bug in GetAllClientParameters() where operation parameters superseded
by a client parameter via @paramAlias/@clientInitialization were not being
deduplicated, causing duplicate constructor parameters in generated code.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 16, 2026

Open in StackBlitz

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

commit: 791050b

radhgupta and others added 2 commits March 16, 2026 14:36
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
radhgupta and others added 4 commits March 17, 2026 10:29
Add three tests in ClientProviderTests.cs for paramAlias on regular
(non-subclient) clients:
- Aliased parameter deduplicates correctly (1 field, not 2)
- Without alias, both distinct parameters are kept
- Same-name parameters deduplicate by name even without alias

Also fix GetAllClientParameters() to include paramAlias values when
building the client parameter name set for deduplication.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add test verifying that generated operation methods do not include
parameters that match an aliased client parameter, since those are
sourced from the client field instead.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Previously, alias names were added to the parent parameter name set,
which could accidentally match unrelated parameters that happen to
share the same name. Now we use IsParameterAliasedByParent() to only
match when a parent parameter's ParamAlias directly references the
parameter in question.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JoshLove-msft
Copy link
Contributor

I think you may need to sync from main and regen

- Remove IsParameterAliasedByParent, inline alias handling into name sets
- Reuse IsSupersededByClientParameter in HasAccessorOnlyParameters and
  subclient constructor arg logic
- Add alias to clientParamNames in GetAllClientParameters so the
  IsParameterAliasedByParent call is no longer needed

Co-authored-by: Copilot <223556219+Copilot@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.

2 participants