Skip to content

Fix default file upload Content-Type - #5306

Merged
iscai-msft merged 6 commits into
Azure:mainfrom
iscai-msft:iscai-msft-fix-wildcard-content-type
Aug 27, 2026
Merged

iscai-msft merged 6 commits into
Azure:mainfrom
iscai-msft:iscai-msft-fix-wildcard-content-type

Conversation

@iscai-msft

@iscai-msft iscai-msft commented Aug 25, 2026 •

Copy link
Copy Markdown
Member

Fixes #5288

Summary

  • Treat */* from @typespec/http as the unconstrained File content-type marker, not a concrete request Content-Type value.
  • For generated file upload clients without an explicit content type, expose Content-Type as an optional string with client default application/octet-stream.
  • Keep download Accept: */* behavior unchanged.
  • Update the file upload regression test and add a Chronus change entry.

Validation

  • mise exec -- pnpm exec oxlint packages/typespec-client-generator-core/src/http.ts packages/typespec-client-generator-core/test/methods/file.test.ts --deny-warnings
  • mise exec -- pnpm --filter @azure-tools/typespec-client-generator-core test -- methods/file.test.ts (blocked locally: this worktree has an unavailable/broken core submodule, so package imports from @typespec/* and @azure-tools/typespec-azure-core could not resolve)

iscai-msft and others added 3 commits April 30, 2025 16:17
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 6a785543-019d-4b0c-9750-5affcfc900ee
@github-actions

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

Use an optional string with an application/octet-stream client default for file uploads without an explicit content type.

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

Copilot-Session: 6a785543-019d-4b0c-9750-5affcfc900ee
@pkg-pr-new

pkg-pr-new Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 72bc2e7

@github-actions

github-actions Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

📦 Package size report

✅ No notable package size changes compared to the base branch.

13 package(s) with no notable change
Package Packed (base → head) Δ Packed Unpacked (base → head) Δ Unpacked
@azure-tools/typespec-client-generator-core 229.25 KB → 229.48 KB +229 B (+0.1%) 1.23 MB → 1.23 MB +937 B (+0.1%)
@azure-tools/azure-http-specs 146.63 KB → 146.71 KB +80 B (+0.1%) 1.16 MB → 1.16 MB +415 B (+0.0%)
@azure-tools/typespec-java 13.51 MB → 13.51 MB +32 B (+0.0%) 15.03 MB → 15.03 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 129.43 KB → 129.43 KB — 702.77 KB → 702.77 KB —
@azure-tools/typespec-azure-portal-core 42.40 KB → 42.40 KB — 192.91 KB → 192.91 KB —
@azure-tools/typespec-azure-resource-manager 171.92 KB → 171.92 KB — 1.04 MB → 1.04 MB —
@azure-tools/typespec-azure-rulesets 5.16 KB → 5.16 KB — 32.09 KB → 32.09 KB —
@azure-tools/typespec-go 259.66 KB → 259.66 KB — 1.33 MB → 1.33 MB —
@azure-tools/typespec-metadata 15.91 KB → 15.91 KB — 62.26 KB → 62.26 KB —
@azure-tools/typespec-python 42.22 KB → 42.22 KB — 164.91 KB → 164.91 KB —
@azure-tools/typespec-ts 527.17 KB → 527.17 KB — 2.54 MB → 2.54 MB —

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.

@azure-sdk-automation

Copy link
Copy Markdown
Contributor

You can try these changes here

🛝 Playground 🌐 Website

Content-Type header/param doc string embedded the raw contentTypes
array, which for the default File case is ["*/*"]. Since that
parameter is now surfaced to clients (no longer a hidden constant),
downstream generators (e.g. Java) emit this doc text inside a
/** ... */ block comment, where the literal */ prematurely closes
the comment and corrupts the generated file. Omit the unconstrained
*/* marker from the doc text.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6a785543-019d-4b0c-9750-5affcfc900ee
…Java emitter instead

The */* content-type doc filtering was a workaround. The actual bug is
in the Java emitter (microsoft/typespec, packages/http-client-java),
where parameter descriptions are XML-escaped but not comment-escaped
before being written into Javadoc, so a literal */ can prematurely
close a generated /** ... */ block. That fix will be made directly in
microsoft/typespec; this PR keeps the TCGC-side doc string unfiltered.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6a785543-019d-4b0c-9750-5affcfc900ee

@weidongxu-microsoft Weidong Xu (weidongxu-microsoft) 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.

LGTM

Java will need to do a release and check any GA lib need customize for this behavior change.

om singhal (Om-singhaI) pushed a commit to Om-singhaI/typespec that referenced this pull request Aug 27, 2026
…osoft#11766)

## Summary
Fixes generated Java code corruption when a Javadoc table cell
(parameter name/type/description, or response header
name/type/description) contains a literal `*/` sequence.

## Root cause
Values written into the optional-parameters and response-headers Javadoc
tables are escaped for XML special characters via
`CodeNamer.escapeXmlComment`, but never comment-escaped. When a value
embeds `*/` (for example, TCGC's Content-Type parameter doc for an
unconstrained `Http.File` content type, whose `contentTypes` array is
`["*/*"]`), the literal `*/` prematurely closes the surrounding
generated `/** ... */` Javadoc block. This corrupts the rest of the
generated Java file and breaks compilation with a long cascade of parser
errors.

## Fix
`CodeNamer.escapeComment` already exists and correctly escapes `*/` to
`*&microsoft#47;`, but it wasn't applied consistently. This change centralizes
the escaping in the shared `ClientMethodTemplateBase#javadocTable`
helper so every cell value (not just parameter descriptions) is
protected, alongside the existing XML escaping.

## Context
Found while fixing Azure/typespec-azure#5288
(Azure/typespec-azure#5306), where making the Content-Type parameter for
default `Http.File` bodies client-visible (previously hidden as a
constant) surfaced this latent Javadoc-escaping bug in CI.

---------

Co-authored-by: iscai-msft <isabellavcai@gmail.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6a785543-019d-4b0c-9750-5affcfc900ee
@iscai-msft
iscai-msft added this pull request to the merge queue Aug 27, 2026
Merged via the queue into Azure:main with commit f7f21e2 Aug 27, 2026
42 of 44 checks passed
@iscai-msft
iscai-msft deleted the iscai-msft-fix-wildcard-content-type branch August 27, 2026 18:44
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.

[Bug]: Content-Type as */* is incorrect

4 participants