Skip to content

fix(http-client-java): honor response replacements - #12156

Merged
Weidong Xu (weidongxu-microsoft) merged 11 commits into
microsoft:mainfrom
weidongxu-microsoft:java-new-spector-coverage-10-12
Oct 13, 2026
Merged

Weidong Xu (weidongxu-microsoft) merged 11 commits into
microsoft:mainfrom
weidongxu-microsoft:java-new-spector-coverage-10-12

Conversation

@weidongxu-microsoft

Copy link
Copy Markdown
Contributor

Summary

Honor void and raw-byte response replacements for basic Java client operations. Preserve HTTP metadata, exception handling, and Azure protocol responses.

Update the tracked sync/async clients and add Spector coverage for the response-replacement scenarios introduced in #12137.

The _specs_ client updates and tests are isolated in a separate commit so they can be excluded if the namespace needs to change.

Validation

Emitter build, lint, formatting, and all 39 emitter tests passed. Targeted Java mapper/template and Azure Spector tests passed, along with native ClientCore and Azure model-response-overload checks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 605e4237-1133-48b0-827b-01786c98f301
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 605e4237-1133-48b0-827b-01786c98f301
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:java Issue for the Java client emitter: @typespec/http-client-java label Oct 12, 2026
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • ✅ @typespec/http-client-java
Show changes

@typespec/http-client-java - fix ✏️

Honor void and raw-byte response replacements in generated Java clients, preserving types used by typed response headers. Fix raw-byte conversion for text responses.

@azure-sdk-automation

azure-sdk-automation Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 605e4237-1133-48b0-827b-01786c98f301
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 605e4237-1133-48b0-827b-01786c98f301
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 605e4237-1133-48b0-827b-01786c98f301
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 605e4237-1133-48b0-827b-01786c98f301

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Response replacement detection can misclassify parameter-only overrides and mishandles bodyless byte replacements.

5 open findings
What changed in this PR

Adds Java emitter support for TCGC void and raw-byte response replacements while preserving protocol responses.

Changes:

  • Carries response overrides through the emitter and generator.
  • Updates generated Azure clients and adds unit/Spector coverage.
  • Documents the behavior and adds a fix changeset.
File Description
packages/​http-client-java/​README.md Documents response replacement.
.../​ResponseReplacementTests.java Tests generated sync/async clients.
.../​responsereplacement_metadata.json Updates generated metadata.
.../​ResponseReplacementClient.java Updates generated sync API.
.../​ResponseReplacementAsyncClient.java Updates generated async API.
.../​models/​Widget.java Removes unused generated model.
.../​models/​package-info.java Removes obsolete model package metadata.
.../​ClientMethodMapperTests.java Tests replacement return-type mapping.
.../​ConvenienceSyncMethodTemplate.java Handles synchronous void conversion.
.../​ConvenienceAsyncMethodTemplate.java Handles asynchronous void conversion.
.../​ClientMethodsReturnDescription.java Maps convenience response overrides.
.../​ConvenienceApi.java Adds the response override model.
.../​response-replacement.tsp Defines replacement test scenarios.
.../​code-model.test.ts Characterizes flavor-specific output.
.../​common/​operation.ts Extends the emitter code model.
.../​code-model-builder.ts Detects and emits response replacements.
.chronus/​changes/​http-client-java-response-replacement.md Records the fix.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/http-client-java/emitter/src/code-model-builder.ts
Comment thread packages/http-client-java/emitter/src/code-model-builder.ts Outdated
Comment thread packages/http-client-java/emitter/src/code-model-builder.ts
…ents

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 605e4237-1133-48b0-827b-01786c98f301

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment thread packages/http-client-java/emitter/src/code-model-builder.ts
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 605e4237-1133-48b0-827b-01786c98f301
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 605e4237-1133-48b0-827b-01786c98f301

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Typed-header visibility regresses for Azure model overloads, and committed Spector execution coverage is missing.

1 open finding
2 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Derive response-header model tracking independently of replacement convenience …

packages/​http-client-java/​emitter/​src/​code-model-builder.ts:2480

Disabling trackConvenienceApi for a replacement also disables header-schema tracking below. In Azure V1 with max-overload: model, the generated ResponseBase<Headers, ...> still publicly exposes typed headers, but enum/model header schemas are no longer promoted to public usage; ClientMapper.java:611-618 requires that promotion for public typed-header models. Derive trackResponseHeadersAsModel directly from the presence/options of op.convenienceApi instead.

    let trackConvenienceApi: boolean = Boolean(op.convenienceApi) && !replaceConvenienceResponse;
    const trackResponseHeadersAsModel =
      trackConvenienceApi &&
      (op.convenienceApi?.responseHeadersAsModel === true ||
        (this.isAzureV1() && this.options["max-overload"] === "model"));

🧠 Review effort: Balanced

Comment thread packages/http-client-java/emitter/src/code-model-builder.ts
Comment thread packages/http-client-java/emitter/src/code-model-builder.ts Outdated
Comment thread packages/http-client-java/emitter/src/code-model-builder.ts
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 605e4237-1133-48b0-827b-01786c98f301
Copilot AI balanced review requested due to automatic review settings October 13, 2026 07:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The implementation preserves protocol behavior, includes focused regression coverage, and addresses the previously identified edge cases.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 605e4237-1133-48b0-827b-01786c98f301
Copilot AI balanced review requested due to automatic review settings October 13, 2026 07:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The cross-layer behavior, diagnostics, generated output, and relevant edge cases are consistently covered.

0 open findings

🧠 Review effort: Balanced

Merged via the queue into microsoft:main with commit 2aa1b6a Oct 13, 2026
36 checks passed
@weidongxu-microsoft
Weidong Xu (weidongxu-microsoft) deleted the java-new-spector-coverage-10-12 branch October 13, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:java Issue for the Java client emitter: @typespec/http-client-java

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants