-
Notifications
You must be signed in to change notification settings - Fork 67
[tcgc] add @clientOption decorator
#3827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| changeKind: feature | ||
| packages: | ||
| - "@azure-tools/typespec-client-generator-core" | ||
| --- | ||
|
|
||
| Add `@clientOption` flag for experimental, language-specific flags |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1022,3 +1022,28 @@ extern dec clientDoc( | |
| mode: EnumMember, | ||
| scope?: valueof string | ||
| ); | ||
|
|
||
| /** | ||
| * Pass experimental flags or options to emitters without requiring TCGC reshipping. | ||
| * This decorator is intended for temporary workarounds or experimental features and requires | ||
| * suppression to acknowledge its experimental nature. | ||
| * | ||
| * **Warning**: This decorator always emits a warning that must be suppressed, and an additional | ||
| * warning if no scope is provided (since options are typically language-specific). | ||
| * | ||
| * @param target The type you want to apply the option to. | ||
| * @param name The name of the option (e.g., "enableFeatureFoo"). | ||
| * @param value The value of the option. Can be any type; emitters will cast as needed. | ||
| * @param scope Specifies the target language emitters that the decorator should apply. If not set, the decorator will be applied to all language emitters by default. | ||
| * You can use "!" to exclude specific languages, for example: !(java, python) or !java, !python. | ||
| * | ||
| * @example Apply an experimental option for Python | ||
| * ```typespec | ||
| * #suppress "@azure-tools/typespec-client-generator-core/client-option" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Show example of the suppression with a message |
||
| * @clientOption("enableFeatureFoo", true, "python") | ||
| * model MyModel { | ||
| * prop: string; | ||
| * } | ||
| * ``` | ||
| */ | ||
| extern dec clientOption(target: unknown, name: valueof string, value: unknown, scope?: valueof string); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we limit the value to value type? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -402,6 +402,14 @@ export function getTypeDecorators( | |
| getDecoratorArgValue(context, decorator.args[i].jsValue, type, decoratorName), | ||
| ); | ||
| } | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tadelesh is there a reason we didn't filter raw decorators by scope before? I think we should because we only want actionable decorator values for a language emitter
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, that's a logic missing. Good catch. Thanks for the fix. |
||
| // Filter by scope - only include decorators that match the current emitter or have no scope | ||
| const scopeArg = decoratorInfo.arguments["scope"]; | ||
| if (scopeArg !== undefined && scopeArg !== context.emitterName) { | ||
| // Skip this decorator if it has a scope that doesn't match the current emitter | ||
| continue; | ||
| } | ||
|
|
||
| retval.push(decoratorInfo); | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a link to the website with a dedicated place where we can define what are the options and values