Skip to content

[TCGC] Fix File type contentType/accept header inconsistencies#4030

Merged
iscai-msft merged 10 commits intomainfrom
copilot/fix-inconsistency-file-support
Mar 23, 2026
Merged

[TCGC] Fix File type contentType/accept header inconsistencies#4030
iscai-msft merged 10 commits intomainfrom
copilot/fix-inconsistency-file-support

Conversation

Copy link
Contributor

Copilot AI commented Mar 11, 2026

Three bugs in File type handling: (1) contentType param typed as string instead of constant for File uploads with specific content types, (2) response contentType header has serializedName: undefined, (3) accept param is string instead of enum for multi-content-type downloads.

Changes

  • Separate File type branch in createContentTypeOrAcceptHeader: The original content type/accept logic is preserved unchanged (json/text/octet-stream → constant for contentType; any single value → constant for accept). A new else if branch is added specifically for File type bodies (bodyKind === "file"), which follows the File's content type constraints to create a constant (single content type) or anonymous enum (multiple content types) for both contentType and accept params. This cleanly separates File-specific handling from the general content type logic.
  • Response header serializedName fallback: Added fallback in getSdkHttpResponseAndExceptions — when getHeaderFieldName returns undefined (File's contentTypeProperty lacks @header), maps to "Content-Type"
  • Enum accept for multiple content types: When a File body has multiple content types, creates an anonymous SdkEnumType with values instead of defaulting to string
// Issue 1: contentType was string, now constant (File body branch)
op upload(@body file: File<"image/png">): void;

// Issue 2: response contentType header serializedName was undefined
op download(): File<"application/json", string>;

// Issue 3: accept was string, now enum with two values (File body branch)
op downloadMultiple(): File<"image/png" | "image/jpeg">;
Original prompt

This section details on the original issue you should resolve

<issue_title>[TCGC] Inconsistency for File support</issue_title>
<issue_description>Building uploadFileSpecificContentType the sdkMethod.parameters includes param contentType as string when it should be a constant. note that it is constant kind in the TypeSpec.Http.File type.

Building downloadFileJsonContentType, in the sdkMethod.operation.responses array, the contentType response header has its serializedName set to undefined.

In downloadFileMultipleContentTypes, the accept header param has type string but I believe it should be the anonymous enum containing image/png and image/jpeg values</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…erializedName for response headers, enum accept for multiple content types

Co-authored-by: tadelesh <1726438+tadelesh@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service bot added the lib:tcgc Issues for @azure-tools/typespec-client-generator-core library label Mar 11, 2026
Co-authored-by: tadelesh <1726438+tadelesh@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix inconsistency in File support parameters and responses [TCGC] Fix File type contentType/accept header inconsistencies Mar 11, 2026
@tadelesh tadelesh changed the base branch from release/march-2026 to main March 11, 2026 05:39
Copy link
Member

@tadelesh tadelesh left a comment

Choose a reason for hiding this comment

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

@copilot Resolve comment and check if all tests pass.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 23, 2026

Open in StackBlitz

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

commit: 0028cda

Copy link
Contributor Author

Copilot AI commented Mar 23, 2026

@copilot Resolve comment and check if all tests pass.

Resolved — added test in 83414bc confirming File responses with single content type produce constant accept headers. All 1211 tests pass.

Copilot AI requested a review from tadelesh March 23, 2026 08:34
Copilot AI requested a review from tadelesh March 23, 2026 09:02
Copilot AI and others added 2 commits March 23, 2026 09:28
…am/file for both contentType and accept

Co-authored-by: tadelesh <1726438+tadelesh@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/725ace9d-fc57-4a06-a779-127f17121c65
Copilot AI requested a review from tadelesh March 23, 2026 09:36
…File type branch for constant/enum

Co-authored-by: tadelesh <1726438+tadelesh@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/e4a8a52d-745c-4d6d-9e9d-e47477ad5e1f
@tadelesh tadelesh marked this pull request as ready for review March 23, 2026 10:01
Copilot AI requested a review from tadelesh March 23, 2026 10:04
@azure-sdk
Copy link
Collaborator

All changed packages have been documented.

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

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

Fix File support inconsistencies: contentType is now constant for File uploads with specific content types, response contentType header serializedName is set correctly, and accept header uses enum for multiple content types

Copilot AI requested a review from tadelesh March 23, 2026 10:09
@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website

@iscai-msft iscai-msft added this pull request to the merge queue Mar 23, 2026
Merged via the queue into main with commit 5775163 Mar 23, 2026
23 checks passed
@iscai-msft iscai-msft deleted the copilot/fix-inconsistency-file-support branch March 23, 2026 17:34
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] Inconsistency for File support

4 participants