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

Bug Report: Incorrect Model Reference in Generated Paginated Envelope

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

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

評価

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

調査の方向性

提供された schema.yaml から始め、2 つのページネーションされたエンベロープ定義を使って生成コマンドを再現します。生成された PaginatedTransactionEnvelope を調べ、そのデータ型とデシリアライズの import を、スキーマおよび正しく生成された customer エンベロープと比較します。トランザクションデータが CustomerEntity のステータスエラーなしに TransactionEntity として解決されれば完了です。

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

説明

Bug Report: Incorrect Model Reference in Generated Paginated Envelope

Summary

openapi-python-client incorrectly generates PaginatedTransactionEnvelope with CustomerEntity instead of TransactionEntity, despite the OpenAPI schema correctly specifying TransactionEntity.

Environment

  • openapi-python-client version: 0.28.1
  • Python version: 3.13
  • Generation command:
    openapi-python-client generate \
        --path schema.yaml \
        --output-path ./generated \
        --meta none
    

Expected Behavior

The generated PaginatedTransactionEnvelope should use TransactionEntity based on this schema definition:

PaginatedTransactionEnvelope:
  allOf:
  - $ref: '#/components/schemas/PaginatedSuccessEnvelope'
  - type: object
    properties:
      data:
        type: array
        items:
          $ref: '#/components/schemas/TransactionEntity'

Expected generated code:

if TYPE_CHECKING:
    from ..models.transaction_entity import TransactionEntity
    from ..models.links import Links

@_attrs_define
class PaginatedTransactionEnvelope:
    timestamp: datetime.datetime
    path: str
    data: list[TransactionEntity]  # ✓ Correct
    links: Links

Actual Behavior

The generator produces code using CustomerEntity instead:

if TYPE_CHECKING:
    from ..models.customer_entity import CustomerEntity  # ✗ Wrong!
    from ..models.links import Links

@_attrs_define
class PaginatedTransactionEnvelope:
    timestamp: datetime.datetime
    path: str
    data: list[CustomerEntity]  # ✗ Wrong!
    links: Links
    
@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
    from ..models.customer_entity import CustomerEntity  # ✗ Wrong!
    from ..models.links import Links
    
    # ...
    for data_item_data in _data:
        data_item = CustomerEntity.from_dict(data_item_data)  # ✗ Wrong!
        data.append(data_item)

Impact

This causes runtime errors when parsing API responses:

ValueError: 'failed' is not a valid CustomerEntityStatus

The parser attempts to deserialize transaction data as customer data, failing when transaction-specific status values don't exist in the CustomerEntityStatus enum.

Additional Context

The schema also defines PaginatedCustomerEnvelope (which correctly uses CustomerEntity). The generator may be incorrectly reusing or caching the entity type across similar paginated envelope structures.

Related schema definitions:

PaginatedCustomerEnvelope:
  allOf:
  - $ref: '#/components/schemas/PaginatedSuccessEnvelope'
  - type: object
    properties:
      data:
        type: array
        items:
          $ref: '#/components/schemas/CustomerEntity'

PaginatedTransactionEnvelope:
  allOf:
  - $ref: '#/components/schemas/PaginatedSuccessEnvelope'
  - type: object
    properties:
      data:
        type: array
        items:
          $ref: '#/components/schemas/TransactionEntity'

Workaround

We've added a post-generation fix script:

sed -i '' 's/from ..models.customer_entity import CustomerEntity/from ..models.transaction_entity import TransactionEntity/g' "$FILE"
sed -i '' 's/list\[CustomerEntity\]/list[TransactionEntity]/g' "$FILE"
sed -i '' 's/CustomerEntity\.from_dict/TransactionEntity.from_dict/g' "$FILE"

Reproduction

The issue appears when:

  1. Multiple paginated envelopes are defined using allOf with shared base schemas
  2. Each envelope should use different entity types in the data array
  3. The generator confuses the entity types between envelopes
主要言語
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 を短くまとめたダイジェスト。