openapi-generators / openapi-generators/openapi-python-client
An unexpected model is generated when server returns dictionary
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 2k
- フォーク
- 293
- 平均マージ
- 34分
- マージ済み PR(30日)
- 1
説明
Describe the bug
I have a web API implementer with fastAPI. I have a function that make a POST request to the server I work with. This function returns dictionary that maps string to an object called "Clipon".
@router.get("/clipon/{version}", tags=["clipon"], status_code=status.HTTP_200_OK, response_model=Dict[str, CliponMetadata])
async def get_clipon_metadata_by_clip_name_list(version: str, clip_list: List[str]):
try:
res = await db_client.get_by_clip_name_list(clip_list=clip_list, version=version)
except AssertionError as ex:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(ex))
return {clip.clip_name: clip for clip in res}
When generating the models with openapi-python-client, what is generated is a model names "clipon_metadata" (as expected), and also another unexpected model with a long name:

It's full name is "GetCliponMetadataByClipNameListCliponVersionPostResponseGetCliponMetadataByClipNameListCliponVersionPost".
I don't understand why this model is created. For example, when I change this function to return List[CliponMetadata], only the "clipon_metadata" model is created.
In this behavior, when the client make this POST request, what it gets is A response object (also generated automatically), which in it's "parsed" attribute contains the unwanted object, and the "additional_properties" attribute of "parsed" holds the desired dictionary:

Expected behavior
I'd like that only the "clipon"metadata" model will be generated.
Desktop:
- OS: Linux (Ubuntu)
- Python Version: 3.9.1
- openapi-python-client version: 0.11.1
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、response_model=Dict[str, CliponMetadata] を指定した FastAPI ルート get_clipon_metadata_by_clip_name_list を再現し、生成されたレスポンスモデルと解析された additional_properties を確認します。これを List[CliponMetadata] のレスポンスケースと比較します。dictionary レスポンスが、不要な長い名前の wrapper モデルなしで、期待される CliponMetadata モデルを生成すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- fastapi, python
- 領域
- api, tooling
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100