Skip to content

[client-generator-core] Allow @clientOption value to reference a TypeSpec model - #5276

Merged
Chenjie Shi (tadelesh) merged 6 commits into
Azure:mainfrom
iscai-msft:iscai-msft-client-options-model-values
Aug 21, 2026
Merged

[client-generator-core] Allow @clientOption value to reference a TypeSpec model#5276
Chenjie Shi (tadelesh) merged 6 commits into
Azure:mainfrom
iscai-msft:iscai-msft-client-options-model-values

Conversation

@iscai-msft

Copy link
Copy Markdown
Member

Fixes #5256

Summary

Extends the @clientOption decorator so its value parameter can reference a TypeSpec model, in addition to the previously supported string, boolean, and number literal values.

@clientOption("composes", OpenAICreateResponseOptions, "csharp")
model FoundryCreateResponseOptions {}

Changes

  • lib/decorators.tsp: updated @clientOption's value parameter type to unknown | valueof unknown and added an example/description covering model reference values.
  • src/internal-utils.ts: getDecoratorArgValue now routes Model kind decorator arguments through getClientTypeWithDiagnostics (same path already used for EnumMember), so a referenced model is resolved into its SdkType, preserving any customizations such as @alternateType.
  • generated-defs/Azure.ClientGenerator.Core.ts: regenerated via pnpm gen-extern-signature.
  • Added tests in test/decorators/client-option.test.ts covering:
    • A model reference as the value, verified via getClientOptions.
    • That @alternateType customizations on the referenced model are preserved when resolving the value.
  • Added a changeset entry.

Testing

  • pnpm vitest run in packages/typespec-client-generator-core — 1405 passed, 2 skipped.
  • pnpm build and pnpm lint pass.

Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com

iscai-msft and others added 3 commits April 30, 2025 16:17
Extends the @clientoption decorator so its value parameter can accept a
reference to a TypeSpec model, in addition to the previously supported
string, boolean, and number literal values. The referenced model is
resolved through TCGC's type conversion pipeline, preserving any
customizations (such as @alternateType) so scoped emitters can resolve
the referenced model via getClientOptions.

Fixes Azure#5256

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ions-model-values

# Conflicts:
#	packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.ts
#	packages/typespec-client-generator-core/lib/decorators.tsp
@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

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

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

@clientOption's value can now reference a TypeSpec model, in addition to string, boolean, and number literal values. The referenced model (including customizations such as @alternateType) is preserved and resolved so scoped emitters can access it via getClientOptions.

@pkg-pr-new

pkg-pr-new Bot commented Aug 20, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 252860d

@github-actions

github-actions Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

📦 Package size report

✅ No notable package size changes compared to the base branch.

13 package(s) with no notable change
Package Packed (base → head) Δ Packed Unpacked (base → head) Δ Unpacked
@azure-tools/typespec-client-generator-core 228.33 KB → 229.25 KB +948 B (+0.4%) 1.23 MB → 1.23 MB +3.38 KB (+0.3%)
@azure-tools/typespec-java 13.51 MB → 13.51 MB -189 B (-0.0%) 15.03 MB → 15.03 MB +65 B (+0.0%)
@azure-tools/typespec-go 258.42 KB → 258.44 KB +29 B (+0.0%) 1.32 MB → 1.32 MB +95 B (+0.0%)
@azure-tools/typespec-python 42.20 KB → 42.22 KB +21 B (+0.0%) 164.85 KB → 164.91 KB +65 B (+0.0%)
@azure-tools/typespec-ts 527.17 KB → 527.17 KB -1 B (-0.0%) 2.54 MB → 2.54 MB
@azure-tools/azure-http-specs 146.63 KB → 146.63 KB 1.16 MB → 1.16 MB
@azure-tools/typespec-autorest 80.93 KB → 80.93 KB 395.06 KB → 395.06 KB
@azure-tools/typespec-autorest-canonical 7.42 KB → 7.42 KB 26.00 KB → 26.00 KB
@azure-tools/typespec-azure-core 129.43 KB → 129.43 KB 702.77 KB → 702.77 KB
@azure-tools/typespec-azure-portal-core 42.40 KB → 42.40 KB 192.91 KB → 192.91 KB
@azure-tools/typespec-azure-resource-manager 171.92 KB → 171.92 KB 1.04 MB → 1.04 MB
@azure-tools/typespec-azure-rulesets 5.16 KB → 5.16 KB 32.09 KB → 32.09 KB
@azure-tools/typespec-metadata 15.91 KB → 15.91 KB 62.26 KB → 62.26 KB

Packed = gzipped .tgz published to npm. Unpacked = total extracted size. 🆕 added, 🗑️ removed. Packages from the core/ submodule are not included.
🔴 grew · 🟢 shrank — only changes of at least 512 B and 0.5% are marked.

@azure-sdk-automation

Copy link
Copy Markdown
Contributor

You can try these changes here

🛝 Playground 🌐 Website

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 43cc5590-eb34-4c28-bdcd-36f6365474be
@microsoft-github-policy-service microsoft-github-policy-service Bot added the meta:website TypeSpec.io updates label Aug 21, 2026
@tadelesh
Chenjie Shi (tadelesh) added this pull request to the merge queue Aug 21, 2026
Keep the kebab-case emitter option access required by the current Options type.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 43cc5590-eb34-4c28-bdcd-36f6365474be
@microsoft-github-policy-service microsoft-github-policy-service Bot added emitter:go Issues for @azure-tools/typespec-go emitter labels Aug 21, 2026
Merged via the queue into Azure:main with commit b6b445f Aug 21, 2026
1 check passed
github-actions Bot added a commit to jhendrixMSFT/typespec-azure that referenced this pull request Aug 21, 2026
- Add emit-content-type-header emitter option to typespec-go reference docs
- Update @clientoption decorator docs: signature now accepts model references
  (value: unknown | valueof unknown), updated parameter descriptions and added
  example for model reference usage
- Update 12clientOptions.mdx: reflect new getClientOptions API (takes SDK type
  and option name, returns single value), add structured value type example,
  update scope description to mention decorator-requires-scope warning
- Update 04method.mdx: document that @convenientAPI and @protocolAPI require a
  language scope (java/csharp) and produce decorator-requires-scope warning if omitted

Reflects upstream changes from Azure/typespec-azure:
- Azure#5261: Add emit-content-type-header emitter option
- Azure#5276: Allow @clientoption value to reference a TypeSpec model
- Azure#5119: Add decorator-requires-scope validation for @convenientAPI and @clientoption
- Azure#5267: Update language scope and overload guidance

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
github-actions Bot added a commit to l0lawrence/typespec-azure that referenced this pull request Aug 21, 2026
- typespec-go: add emit-content-type-header emitter option (Azure#5261)
- TCGC decorators.md: update @clientoption value type to support model references (Azure#5276)
- TCGC guideline.md: clarify generate-convenience/protocol-methods scope warning (Azure#5267)
- howtos/04method.mdx: update protocol/convenience method scoping guidance (Azure#5267)
- howtos/03client.mdx: add note about operation name uniqueness requirements (Azure#5267)
- howtos/12clientOptions.mdx: update @clientoption value type and scope documentation (Azure#5267)

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:go Issues for @azure-tools/typespec-go emitter 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.

[client-generator-core] Allow clientOptions values to reference models

2 participants