Skip to content

[tcgc] add functions to help with override story#3995

Open
iscai-msft wants to merge 25 commits intoAzure:mainfrom
iscai-msft:tcgc/addReplaceDecorator
Open

[tcgc] add functions to help with override story#3995
iscai-msft wants to merge 25 commits intoAzure:mainfrom
iscai-msft:tcgc/addReplaceDecorator

Conversation

@iscai-msft
Copy link
Contributor

No description provided.

iscai-msft and others added 6 commits April 30, 2025 16:17
…arate file

- Move replaceParameter from decorators.tsp to new lib/functions.tsp
- Add replaceResponse function to replace operation return types
- Add addParameter function to add parameters to operations
- Add tests for all three functions (23 total tests)
- Add documentation page for functions (experimental)
- Update reference index to link to functions documentation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@microsoft-github-policy-service microsoft-github-policy-service bot added the lib:tcgc Issues for @azure-tools/typespec-client-generator-core library label Mar 2, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 2, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@azure-tools/typespec-client-generator-core@3995

commit: 008298e

@azure-sdk
Copy link
Collaborator

azure-sdk commented Mar 2, 2026

All changed packages have been documented.

  • @azure-tools/typespec-client-generator-core
Show changes

@azure-tools/typespec-client-generator-core - feature ✏️

Add experimental extern functions for operation transformations:,> - replaceParameter: Replace or remove a parameter in an operation,> - addParameter: Add a new parameter to an operation,> - reorderParameters: Reorder parameters of an operation according to a specified order,> ,> These functions enable composable transformations that work with @@override to customize method signatures in client SDKs.

@azure-sdk
Copy link
Collaborator

azure-sdk commented Mar 2, 2026

You can try these changes here

🛝 Playground 🌐 Website

iscai-msft and others added 4 commits March 2, 2026 17:19
- Use createClientCustomizationInput and createSdkContextForTester pattern
- Verify method parameters, optionality, types
- Verify operation-to-method parameter mappings (correspondingMethodParams)
- Test scoped overrides (Python vs C#)
- Remove complex nested namespace tests that hit TCGC edge cases

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove functions.md from tcgc reference section
- Add comprehensive @OverRide section to 04method.mdx
- Document transformation functions (replaceParameter, addParameter, replaceResponse)
- Add multi-language examples with ClientTabs

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@microsoft-github-policy-service microsoft-github-policy-service bot added the meta:website TypeSpec.io updates label Mar 17, 2026
Copy link
Member

@tadelesh tadelesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several high level concerns:

  1. In what scenario we need to add a parameter in client level? How should the added parameter be used in the client code? There will be no mapping for it on wire.
  2. Shall we only allow to remove the optional parameter? Is there any other limitation we should add?
  3. Same concern for replace. I don't think any replacement could work here.

@iscai-msft
Copy link
Contributor Author

Several high level concerns:

  1. In what scenario we need to add a parameter in client level? How should the added parameter be used in the client code? There will be no mapping for it on wire.
  2. Shall we only allow to remove the optional parameter? Is there any other limitation we should add?
  3. Same concern for replace. I don't think any replacement could work here.

Here I'm relying on the validation from @override for everything, bc these functions can't be used as anything except when passed as input to @override, so I don't think we need to add a bunch of new validations on top of @override

Copy link
Member

@tadelesh tadelesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM. In ARM, we have a brown field frequent user scenario: adjust parameter order to prevent SDK breaking change. Is it possible to add a function to help with that requirement?

@iscai-msft iscai-msft requested a review from tadelesh March 19, 2026 19:18
@tadelesh tadelesh requested a review from Copilot March 20, 2026 03:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds experimental TypeSpec extern functions to enable composable @@override-based method signature customization in generated client SDKs, along with docs and tests.

Changes:

  • Introduces replaceParameter, addParameter, and reorderParameters extern functions and exports them via $functions.
  • Adds diagnostics and Vitest coverage for the new transformation functions.
  • Documents @@override usage patterns and transformation chaining in the client library generation how-to.

Reviewed changes

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

Show a summary per file
File Description
website/src/content/docs/docs/howtos/Generate client libraries/04method.mdx Adds documentation for @@override and the new transformation functions.
packages/typespec-client-generator-core/tsconfig.build.json Excludes additional test filename patterns from build compilation.
packages/typespec-client-generator-core/test/functions/replace-parameter.test.ts Adds tests for replaceParameter behavior and scoped overrides.
packages/typespec-client-generator-core/test/functions/reorder-parameters.test.ts Adds tests for reorderParameters, chaining, and diagnostics.
packages/typespec-client-generator-core/test/functions/add-parameter.test.ts Adds tests for addParameter, chaining, and scoped overrides.
packages/typespec-client-generator-core/src/tsp-index.ts Exports implementations via $functions for TypeSpec extern function binding.
packages/typespec-client-generator-core/src/lib.ts Adds new diagnostics for replace/reorder parameter validation.
packages/typespec-client-generator-core/src/index.ts Exports $functions in addition to $decorators.
packages/typespec-client-generator-core/src/functions.ts Implements the three operation transformation functions.
packages/typespec-client-generator-core/lib/main.tsp Imports the new functions.tsp into the library surface.
packages/typespec-client-generator-core/lib/functions.tsp Declares the extern function signatures and docs in TypeSpec.
packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.ts-test.ts Adds compile-time export/signature checks for $functions.
packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.ts Extends generated defs with function implementation types.
.chronus/changes/tcgc-addReplaceDecorator-2026-2-2-16-3-32.md Adds changelog entry for the new experimental extern functions.

* This function creates a new operation with the specified parameter replaced,
* enabling composable transformations without mutating the original operation.
*
* Note: Parameter removal (using `void` as replacement) is not supported when used with `@@override`.
Copy link
Member

@tadelesh tadelesh Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I recalled correctly, we do have a case to remove optional parameter for key vault? See playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lib:tcgc Issues for @azure-tools/typespec-client-generator-core library meta:website TypeSpec.io updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants