[REQ][typescript-fetch] Name downloaded files from Content-Disposition (return a File instead of an anonymous Blob)

オープン
#24,956 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
typescript
領域
api, tooling

調査の方向性

まず、typescript-fetch の BlobApiResponse 実装と、typescript/http/http.mustache にある既存のファイル名処理を確認します。生成されたメソッドが BlobApiResponse.value() をどのように利用するかを確認し、そのうえで、完成した動作が Blob との互換性を維持し、要求されたファイル名を公開し、Content-Disposition の filename の両形式を処理することを検証します。

索引モデルが issue の本文から書いたものです。

説明

Enhancement: Feature

For an operation whose response is a file (isResponseFile), the typescript-fetch runtime returns the body through BlobApiResponse.value():

export class BlobApiResponse {
    constructor(public raw: Response) {}
    async value(): Promise<Blob> {
        return await this.raw.blob();
    };
}

The name the server advertises in Content-Disposition (attachment; filename="invoice-2026-09.pdf") is dropped. Any client that wants to save the download under its real name has to bypass the generated method, call the xxxRaw() variant, read raw.headers and parse the header itself, and every project ends up with its own copy of that parsing.

Every other runtime in this repository already does it for the user:

  • typescript generator: ResponseContext.getBodyAsFile() returns new File([data], fileName, { type }) with fileName read from content-disposition (typescript/http/http.mustache).
  • Java (okhttp-gson, jersey2/3, apache-httpclient, feign, native, vertx): prepareDownloadFile names the temp file from Content-Disposition.
  • Python (api_client.mustache, __deserialize_file): idem.
  • C# (ClientUtils, FileParameter): idem.

typescript-fetch is the exception.

Describe the solution you'd like

Keep BlobApiResponse, make it return a File named after Content-Disposition (empty name when the header is absent, type taken from the blob):

async value(): Promise<File> {
    const blob = await this.raw.blob();
    return new File([blob], parseContentDispositionFilename(this.raw.headers) ?? '', { type: blob.type });
}

plus an exported parseContentDispositionFilename(headers) handling the RFC 5987 filename*=UTF-8''... form first and the plain filename= form otherwise.

Backward compatible: File extends Blob, so the generated methods still satisfy their declared Promise<Blob> return type and existing callers keep working; callers that want the name read file.name.

Describe alternatives you've considered

  • A new FileApiResponse next to BlobApiResponse: forces a template change in apis.mustache and a choice for the user, for no benefit since a File is a Blob.
  • Exposing only the helper and leaving value() unchanged: still leaves every user to call the raw variant.
  • Doing it in application code: that is what we do today, duplicated per project.

Additional context

File is a global in browsers and in Node.js 20+ (the CI matrix of the typescript-fetch samples runs Node 20).

PR: https://github.com/OpenAPITools/openapi-generator/pull/24957

主要言語
Java
スター
26.9k
フォーク
7.8k
平均マージ
2日 10時間
マージ済み PR(30日)
180

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

OpenAPITools/openapi-generator のほかの issue

OpenAPITools/openapi-generator の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。