Skip to content

feat(tcgc): support overriding method responses - #5173

Open
iscai-msft wants to merge 13 commits into
Azure:mainfrom
iscai-msft:iscai-msft-support-response-overrides
Open

feat(tcgc): support overriding method responses#5173
iscai-msft wants to merge 13 commits into
Azure:mainfrom
iscai-msft:iscai-msft-support-response-overrides

Conversation

@iscai-msft

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

Copy link
Copy Markdown
Member

fixes #3542

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

Copilot-Session: 8aca8827-bea2-4bf5-ae80-c87bebeedcbd
iscai-msft added 2 commits August 6, 2026 11:08
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 8aca8827-bea2-4bf5-ae80-c87bebeedcbd
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 8aca8827-bea2-4bf5-ae80-c87bebeedcbd
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

❌ There is undocummented changes. Run chronus add to add a changeset or click here.

The following packages have changes but are not documented.

  • @azure-tools/typespec-java

The following packages have already been documented:

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

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

Allow @override to replace a client method response and add the replaceResponse customization function.

@pkg-pr-new

pkg-pr-new Bot commented Aug 6, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 07be39c

@azure-sdk-automation

Copy link
Copy Markdown
Contributor

You can try these changes here

🛝 Playground 🌐 Website

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

Copilot-Session: 8aca8827-bea2-4bf5-ae80-c87bebeedcbd
Comment thread .chronus/changes/replace-client-response-2026-08-06-10-49-09.md Outdated
iscai-msft and others added 3 commits August 7, 2026 12:38
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 8aca8827-bea2-4bf5-ae80-c87bebeedcbd
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>\nCopilot-Session: 8aca8827-bea2-4bf5-ae80-c87bebeedcbd
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

📦 Package size report

4 packages changed size, +10.55 KB (+0.1%) packed overall.

Package Packed (base → head) Δ Packed Unpacked (base → head) Δ Unpacked
@azure-tools/typespec-go 251.13 KB → 258.42 KB +7.28 KB (+2.9%) 🔴 1.28 MB → 1.32 MB +42.72 KB (+3.3%) 🔴
@azure-tools/typespec-python 46.22 KB → 42.20 KB -4.02 KB (-8.7%) 🟢 180.83 KB → 164.85 KB -15.98 KB (-8.8%) 🟢
@azure-tools/typespec-client-generator-core 226.81 KB → 229.08 KB +2.26 KB (+1.0%) 🔴 1.22 MB → 1.23 MB +8.88 KB (+0.7%) 🔴
@azure-tools/typespec-azure-resource-manager 171.29 KB → 171.92 KB +649 B (+0.4%) 1.04 MB → 1.04 MB +7.63 KB (+0.7%) 🔴
9 package(s) with no notable change
Package Packed (base → head) Δ Packed Unpacked (base → head) Δ Unpacked
@azure-tools/typespec-java 13.51 MB → 13.51 MB +3.14 KB (+0.0%) 15.03 MB → 15.03 MB +4.68 KB (+0.0%)
@azure-tools/typespec-ts 526.37 KB → 527.17 KB +819 B (+0.2%) 2.53 MB → 2.54 MB +2.33 KB (+0.1%)
@azure-tools/azure-http-specs 146.21 KB → 146.63 KB +434 B (+0.3%) 1.16 MB → 1.16 MB +1.20 KB (+0.1%)
@azure-tools/typespec-azure-core 129.41 KB → 129.43 KB +22 B (+0.0%) 702.62 KB → 702.77 KB +153 B (+0.0%)
@azure-tools/typespec-azure-portal-core 42.40 KB → 42.40 KB +2 B (+0.0%) 192.87 KB → 192.91 KB +43 B (+0.0%)
@azure-tools/typespec-azure-rulesets 5.16 KB → 5.16 KB +1 B (+0.0%) 32.09 KB → 32.09 KB
@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-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.

iscai-msft added 2 commits August 10, 2026 15:00
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>\nCopilot-Session: 8aca8827-bea2-4bf5-ae80-c87bebeedcbd
iscai-msft added 3 commits August 10, 2026 15:15
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>\nCopilot-Session: 8aca8827-bea2-4bf5-ae80-c87bebeedcbd
name: string;
}

@post op create(): Widget | Error;

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.

Java does not support union of 2 unrelated models...

Comment on lines +52 to +53
op customizedCreate(): DeleteResult;
@@override(TestService.create, TestService.customizedCreate);

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.

Why is this allowed?


const baseServiceMethod = diagnostics.pipe(
getSdkBasicServiceMethod<TServiceOperation>(context, operation, client),
getSdkBasicServiceMethod<TServiceOperation>(context, operation, client, false),

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.

Why here we pass false? This flag looks quick hacky to me.


@post op create(): Widget;

op customizedCreate(): DeleteResult;

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.

Please pay attention to the usage and serialization info of new response model.

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.

as well as the usage for original model.

* ```
*/
#suppress "experimental-feature" "replaceResponse uses extern fn which is experimental but provides essential response transformation functionality"
extern fn replaceResponse(operation: Reflection.Operation, response: unknown): Reflection.Operation;

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.

When we replace the response, how could we know how to map the method level response to the HTTP level response?

Re-applies the fix reverted in 35b427d. Verified this duplicate-body
failure is introduced by this PR's pageable/response-override
classification changes (confirmed clean compile on main, failing on
this branch), not a pre-existing Java fixture bug, so the fix belongs
here.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8aca8827-bea2-4bf5-ae80-c87bebeedcbd
op groupExcludeBodyCustomization(
...TspTest.MethodOverride.GroupExcludeBody,
options?: TspTest.MethodOverride.GroupQueryOptions,
@query options?: TspTest.MethodOverride.GroupQueryOptions,

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.

Emm, I am OK if this is only to unblock. But unsure why? What if we group query and header parameter in the model?

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

Labels

emitter:java Issues for @azure-tools/typespec-java emitter 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] do we want to allow users to @override to a different response?

4 participants