openapi-generators / openapi-generators/openapi-python-client
Multiple body-types in an endpoint with same model (referenced via `$ref`) results in ambiguity in generated code
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 2k
- フォーク
- 293
- 平均マージ
- 34分
- マージ済み PR(30日)
- 1
説明
| Python Version | OpenAPI Client Generator Version |
|---|---|
| 3.11.6 | 0.18.0 |
Actual Behavior
When an endpoint has multiple body types, each referencing the same model (via a $ref key), the generator generates the same class name for each body types, which results then in the following generated code:
def _get_kwargs(
# ...
):
# ...
if isinstance(body, WritableJournalEntryRequest):
_json_body = body.to_dict()
_kwargs["json"] = _json_body
headers["Content-Type"] = "application/json"
if isinstance(body, WritableJournalEntryRequest):
_files_body = body.to_multipart()
_kwargs["files"] = _files_body
headers["Content-Type"] = "multipart/form-data"
# ...
As you can see, both if-statement's conditions will resolve to True, therefore only the last body type will be used.
Desired Behavior
The body-type should be part of the generated class name to avoid such ambiguities.
Or an if/elseif/else should be used in the template (which would result in the first one being applied ONLY).
OpenAPI Spec File
The OpenAPI spec is from Netbox, but here is the relevant snippet:
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/WritableJournalEntryRequest"
}
},
"multipart/form-data": {
"schema": {
"$ref": "#/components/schemas/WritableJournalEntryRequest"
}
}
},
"required": true
},
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、generatorがOpenAPI requestBodyのcontentエントリをどのように処理し、生成された_get_kwargs関数を生成するのかを追跡します。提供されたJSONスニペットで問題を再現し、application/jsonとmultipart/form-dataの両方に対するカバレッジを追加します。生成されたクライアントが、同一で曖昧な条件なしに正しいbody処理を選択できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- openapi, python
- 領域
- api, tooling
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100