Skip to content

[TCGC] Handle encodedAs from @encode for all types - #5146

Merged
iscai-msft merged 7 commits into
mainfrom
iscai-msft-fix-tcgc-encoded-as-handling
Aug 7, 2026
Merged

[TCGC] Handle encodedAs from @encode for all types#5146
iscai-msft merged 7 commits into
mainfrom
iscai-msft-fix-tcgc-encoded-as-handling

Conversation

@iscai-msft

@iscai-msft iscai-msft commented Aug 3, 2026

Copy link
Copy Markdown
Member

Fix

Fixes #3659

The @encode decorator's encodedAs parameter was not being taken into account correctly for all types. For example, @encode("abc", int32) on a string property was silently ignored — no encode or wireType was set.

Changes

  • Added optional wireType?: SdkBuiltInType to SdkBuiltInType interface so encode wire type info is available for all built-in types (previously only datetime/duration had wireType)
  • Extended addEncodeInfo to handle @encode for string, url, int*, boolean, and bytes types:
    • Sets encode from the encoding name
    • Sets wireType from the encodedAs type parameter
  • Added tests for:
    • @encode("abc", int32) on string properties (new case from the issue)
    • wireType assertions on existing int/boolean encode tests

Set wireType from the encodedAs parameter of @encode for integer,
boolean, and bytes types. Previously only datetime and duration types
populated wireType from the encode decorator.

Fixes #3659

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

github-actions Bot commented Aug 3, 2026

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 - fix ✏️

Add wireType to SdkBuiltInType interface and populate it from the encodedAs parameter of @encode for integer, boolean, and bytes types. Previously, wireType was only set for datetime and duration types.

@pkg-pr-new

pkg-pr-new Bot commented Aug 3, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 316a79a

@azure-sdk-automation

Copy link
Copy Markdown
Contributor

You can try these changes here

🛝 Playground 🌐 Website

iscai-msft and others added 3 commits August 3, 2026 14:58
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Extend addEncodeInfo to handle string and url types with @encode,
so that @encode("abc", int32) on a string property correctly sets
encode="abc" and wireType=int32. Also preserve the existing behavior
for int/boolean encoded as string.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@iscai-msft iscai-msft changed the title [TCGC] Add wireType to SdkBuiltInType for @encode encodedAs support [TCGC] Handle encodedAs from @encode for all types Aug 4, 2026
Add test that mirrors the issue's playground example with both
@encode(ArrayEncoding.commaDelimited) on string[] and
@encode("abc", int32) on string in the same model. Also add
valueType.encode verification to existing array encode test.

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

@tadelesh Chenjie Shi (tadelesh) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you help to check if this will impact lanague's emitter before merge?

@iscai-msft
iscai-msft enabled auto-merge August 6, 2026 15:56
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

📦 Package size report

4 packages changed size compared to the base branch.

Package Packed (base → head) Δ Packed Unpacked (base → head) Δ Unpacked
@azure-tools/typespec-client-generator-core 225.96 KB → 226.14 KB +185 B (+0.1%) 1.22 MB → 1.22 MB +987 B (+0.1%)
@azure-tools/typespec-java 13.51 MB → 13.51 MB -124 B (-0.0%) 15.03 MB → 15.03 MB
@azure-tools/typespec-azure-portal-core 42.26 KB → 42.26 KB +2 B (+0.0%) 192.36 KB → 192.36 KB
@azure-tools/typespec-ts 524.66 KB → 524.66 KB -1 B (-0.0%) 2.53 MB → 2.53 MB
41 unchanged package(s)
Package Packed (base → head) Δ Packed Unpacked (base → head) Δ Unpacked
@azure-tools/azure-http-specs 146.21 KB → 146.21 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 127.87 KB → 127.87 KB 695.48 KB → 695.48 KB
@azure-tools/typespec-azure-resource-manager 171.18 KB → 171.18 KB 1.04 MB → 1.04 MB
@azure-tools/typespec-azure-rulesets 5.15 KB → 5.15 KB 31.73 KB → 31.73 KB
@azure-tools/typespec-go 242.43 KB → 242.43 KB 1.24 MB → 1.24 MB
@azure-tools/typespec-metadata 15.91 KB → 15.91 KB 62.26 KB → 62.26 KB
@azure-tools/typespec-python 46.21 KB → 46.21 KB 180.83 KB → 180.83 KB
@typespec/asset-emitter 33.73 KB → 33.73 KB 158.67 KB → 158.67 KB
@typespec/bundler 11.31 KB → 11.31 KB 41.97 KB → 41.97 KB
@typespec/compiler 762.04 KB → 762.04 KB 3.88 MB → 3.88 MB
@typespec/emitter-framework 273.87 KB → 273.87 KB 1.50 MB → 1.50 MB
@typespec/events 8.96 KB → 8.96 KB 35.22 KB → 35.22 KB
@typespec/graphql 131.35 KB → 131.35 KB 544.77 KB → 544.77 KB
@typespec/html-program-viewer 53.96 KB → 53.96 KB 218.99 KB → 218.99 KB
@typespec/http 103.94 KB → 103.94 KB 511.18 KB → 511.18 KB
@typespec/http-canonicalization 74.18 KB → 74.18 KB 478.11 KB → 478.11 KB
@typespec/http-client 56.52 KB → 56.52 KB 281.75 KB → 281.75 KB
@typespec/http-client-js 219.98 KB → 219.98 KB 1.06 MB → 1.06 MB
@typespec/http-server-csharp 100.97 KB → 100.97 KB 409.91 KB → 409.91 KB
@typespec/http-server-js 259.10 KB → 259.10 KB 1.27 MB → 1.27 MB
@typespec/http-specs 182.16 KB → 182.16 KB 1.26 MB → 1.26 MB
@typespec/json-schema 31.66 KB → 31.66 KB 155.69 KB → 155.69 KB
@typespec/library-linter 4.35 KB → 4.35 KB 12.71 KB → 12.71 KB
@typespec/mutator-framework 71.87 KB → 71.87 KB 462.42 KB → 462.42 KB
@typespec/openapi 20.62 KB → 20.62 KB 91.67 KB → 91.67 KB
@typespec/openapi3 160.96 KB → 160.96 KB 824.53 KB → 824.53 KB
@typespec/playground 59.09 KB → 59.09 KB 239.02 KB → 239.02 KB
@typespec/prettier-plugin-typespec 157.35 KB → 157.35 KB 817.89 KB → 817.89 KB
@typespec/protobuf 94.53 KB → 94.53 KB 400.95 KB → 400.95 KB
@typespec/rest 24.18 KB → 24.18 KB 125.95 KB → 125.95 KB
@typespec/spec-api 46.54 KB → 46.54 KB 210.02 KB → 210.02 KB
@typespec/spec-coverage-sdk 41.83 KB → 41.83 KB 190.89 KB → 190.89 KB
@typespec/spector 139.66 KB → 139.66 KB 590.91 KB → 590.91 KB
@typespec/sse 5.66 KB → 5.66 KB 19.01 KB → 19.01 KB
@typespec/streams 4.12 KB → 4.12 KB 12.47 KB → 12.47 KB
@typespec/tspd 97.82 KB → 97.82 KB 430.99 KB → 430.99 KB
@typespec/versioning 36.69 KB → 36.69 KB 201.84 KB → 201.84 KB
@typespec/xml 9.41 KB → 9.41 KB 39.14 KB → 39.14 KB
tmlanguage-generator 5.00 KB → 5.00 KB 15.32 KB → 15.32 KB

Packed = gzipped .tgz published to npm. Unpacked = total extracted size. 🆕 added, 🗑️ removed.

@iscai-msft
iscai-msft added this pull request to the merge queue Aug 7, 2026
Merged via the queue into main with commit f1171f5 Aug 7, 2026
42 of 44 checks passed
@iscai-msft
iscai-msft deleted the iscai-msft-fix-tcgc-encoded-as-handling branch August 7, 2026 17:17
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TCGC] encodedAs from @encode is not taken into account correctly

2 participants