Skip to content

http-client-java, support File in multipart and request body#9602

Merged
weidongxu-microsoft merged 8 commits intomicrosoft:mainfrom
weidongxu-microsoft:http-client-java_support-file
Feb 6, 2026
Merged

http-client-java, support File in multipart and request body#9602
weidongxu-microsoft merged 8 commits intomicrosoft:mainfrom
weidongxu-microsoft:http-client-java_support-file

Conversation

@weidongxu-microsoft
Copy link
Contributor

@weidongxu-microsoft weidongxu-microsoft commented Feb 6, 2026

fix #9509

For request body / response body of non-multipart op, they are treated as bytes of unknown mediaType, generated as BinaryData.

For multipart, they are treated as usually, in HttpPart<> of File, generated as ##FileDetails.
The difference is that

model FileSpecificContentType extends File {
  filename: string;
  contentType: "image/png";
}

now can be written as

TypeSpec.Http.File<"image/png">

(the only difference is that former defined a name of FileSpecificContentType, so Java will use this directly; while latter the File kind of be a template name, and Java cannot directly use it as it could conflict with another e.g. File<"application/text">)

PR #9530 only supported the case we see in ARM, on File in response body

tested on tsp from #9513 (http-specs is not released)

@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 Feb 6, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

All changed packages have been documented.

  • @typespec/http-client-java
Show changes

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

Support File in multipart and request body.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 6, 2026

Open in StackBlitz

npm i https://pkg.pr.new/microsoft/typespec/@typespec/http@9602
npm i https://pkg.pr.new/microsoft/typespec/@typespec/http-client@9602
npm i https://pkg.pr.new/microsoft/typespec/@typespec/http-client-java@9602

commit: 1be15ad

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends File type support in the http-client-java emitter to cover multipart and request body scenarios. Previously, PR #9530 only supported File in response body for ARM cases. This PR adds the missing support for File in request bodies and refines the handling of File properties (filename and contentType) in multipart scenarios.

Changes:

  • Extended code-model-builder.ts to detect and process File types in request bodies (similar to existing response body handling)
  • Modified external-schemas.ts to improve handling of constant vs non-constant filename and contentType properties with better default value logic
  • Removed ClientInitializationTests.java test file (unrelated to File support)

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
packages/http-client-java/emitter/src/code-model-builder.ts Added File detection logic for request bodies, renamed variables for clarity (responseIsFile → responseBodyIsFile, requestBodyIsFile), and widened processBinarySchema signature from SdkBuiltInType to SdkType
packages/http-client-java/emitter/src/external-schemas.ts Refactored filename and contentType property handling to better support constant types with default values, addressing TypeSpec.Http.File<"image/png"> scenarios
packages/http-client-java/generator/http-client-generator-test/src/test/java/azure/clientgenerator/core/clientinitialization/ClientInitializationTests.java Deleted test file containing client initialization tests unrelated to File support
.chronus/changes/http-client-java_support-file-2026-1-6-12-16-2.md Added changeset documenting the feature addition
Comments suppressed due to low confidence (1)

packages/http-client-java/generator/http-client-generator-test/src/test/java/azure/clientgenerator/core/clientinitialization/ClientInitializationTests.java:1

  • The deletion of ClientInitializationTests.java appears to be unrelated to the purpose of this PR, which is to support File in multipart and request body. This test file contained tests for various client initialization scenarios (header parameters, path parameters, mixed parameters, etc.) that have nothing to do with File type support.

This deletion seems accidental or perhaps part of a code generation cleanup that should be handled separately. If this deletion is intentional, it should be explained in the PR description. Otherwise, this file should be restored.

@azure-sdk
Copy link
Collaborator

azure-sdk commented Feb 6, 2026

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@weidongxu-microsoft weidongxu-microsoft added this pull request to the merge queue Feb 6, 2026
Merged via the queue into microsoft:main with commit 4d31f6e Feb 6, 2026
31 checks passed
@weidongxu-microsoft weidongxu-microsoft deleted the http-client-java_support-file branch February 6, 2026 06:48
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.

http-client-java, support File type

3 participants