Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

String Binary File is just expecting BytesIO and not filename and mime-type

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

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
openapi, python
領域
api

調査の方向性

生成された types.py と issue に示されている File.from_dict コードから始め、レスポンスまたはリクエストのパース中にバイナリ文字列スキーマがどのように表現されるかを追跡します。提示された FileRequest のアップロードケースを再現し、結果の File がバイナリデータだけでなく、payload、filename、MIME type も保持していることを確認します。

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

説明

🐞bug

I have Java OpenAPI server which provides an upload endpoint (POST) that expect as schema a FileRequest ( schema = @Schema(implementation = FileRequest.class))

The FileRequest looks like:

@Value.Immutable
@JsonDeserialize(builder = com.mydata.request.FileRequest.Builder.class)
public abstract class FileRequest implements FileFields {
    @Schema(type = "string", format = "binary", description = "File")
    @JsonProperty
    public abstract String file();

    public static class Builder extends ImmutableFileRequest.Builder {

    }
}

Looking at the generated code, the models looks good. This is the relevant part on types.py:

@attr.s(auto_attribs=True)
class File:
    """ Contains information for file uploads """

    payload: BinaryIO
    file_name: Optional[str] = None
    mime_type: Optional[str] = None

    def to_tuple(self) -> FileJsonType:
        """ Return a tuple representation that httpx will accept for multipart/form-data """
        return self.file_name, self.payload, self.mime_type


T = TypeVar("T")

However, looking at the upload endpoint request, it doesn't expect the Optional values above:


    @classmethod
    def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
        d = src_dict.copy()

        _file = d.pop("file", UNSET)
        file: Union[Unset, File]
        if isinstance(_file,  Unset):
            file = UNSET
        else:
            file = File(
             payload = BytesIO(_file)
        )

Notice that the File expects only the binary data, losing the filename and mimetype.

Expected behavior

I would expect that the generated code would look something like below, which I patched and am using currently:

        else:
            file = File(
             payload = BytesIO(_file['payload']),
                file_name=_file['filename']
        )

Desktop (please complete the following information):

  • OS: Linux, but irrelevant
  • openapi-python-client version: 0.11.1
  • Python 3.8.10
  • openapi: 3.0.1
主要言語
Python
スター
2k
フォーク
293
平均マージ
34分
マージ済み PR(30日)
1

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

openapi-generators/openapi-python-client のほかの issue

openapi-generators/openapi-python-client の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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