openapi-generators / openapi-generators/openapi-python-client

Attempted to generate duplicate models with name "TypenameFieldnameItem"

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

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

主要言語
Python
スター
2k
フォーク
293
平均マージ
34分
マージ済み PR(30日)
1

説明

Describe the bug
I stumbled on a weirdly specific bug that causes the generator to attempt to generate duplicate models.

Apparently we need:

  • a OneOf type (A), which references an Object type (B)
  • An object type (B) with an array-of-object field
  • An Object type (C) for the array-of-object field
  • array-of-C and C must be declared inline inside B

OpenAPI Spec File

This works

openapi: 3.0.3
info:
  title: Minimal example for error "Attempted to generate duplicate models"
  version: 1.0.0

components:
  schemas:
    Result:
      oneOf:
        - $ref: "#/components/schemas/ResultA"
      discriminator:
        propertyName: type
        mapping:
          "A": "#/components/schemas/ResultA"

    ResultA:
      type: object
      properties:
        things:
          type: array
          items:
            $ref: "#/components/schemas/ResultAThingsItem"

    ResultAThingsItem:
      type: object
      properties:
        name:
          type: string

paths:
  /something:
    get:
      summary: Returns a list of users.
      responses:
        '200':
          description: A successful response returning the list of users.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Result'

This should be the same, but doesn't work:

openapi: 3.0.3
info:
  title: Minimal example for error "Attempted to generate duplicate models"
  version: 1.0.0

components:
  schemas:
    Result:
      oneOf:
        - $ref: "#/components/schemas/ResultA"
      discriminator:
        propertyName: type
        mapping:
          "A": "#/components/schemas/ResultA"

    ResultA:
      type: object
      properties:
        things:
          type: array
          items:
            type: object
            properties:
              name:
                type: string

paths:
  /something:
    get:
      summary: Returns a list of users.
      responses:
        '200':
          description: A successful response returning the list of users.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Result'

Output:

$ pipx run openapi-python-client generate --path=example.yaml --overwrite
Generating <...>/minimal-example-for-error-attempted-to-generate-duplicate-models-client
Warning(s) encountered while generating. Client was generated, but some pieces may be missing

WARNING parsing GET /something within default.

Cannot parse response for status code 200 (Could not find reference in parsed models or enums), response will be omitted from generated client

Reference(ref='#/components/schemas/Result')

Unable to process schema /components/schemas/Result:

Attempted to generate duplicate models with name "ResultAThingsItem"

Failure to process schema has resulted in the removal of:
/components/schemas/ResultA
/components/schemas/Result

Schema(title=None, multipleOf=None, maximum=None, exclusiveMaximum=None, minimum=None, exclusiveMinimum=None, maxLength=None, minLength=None, pattern=None, maxItems=None, minItems=None, uniqueItems=None, maxProperties=None, minProperties=None, required=None, enum=None, const=None, type=<DataType.OBJECT: 'object'>, allOf=[], oneOf=[], anyOf=[], schema_not=None, items=None, prefixItems=[], properties={'name': Schema(title=None, multipleOf=None, maximum=None, exclusiveMaximum=None, minimum=None, exclusiveMinimum=None, maxLength=None, minLength=None, pattern=None, maxItems=None, minItems=None, uniqueItems=None, maxProperties=None, minProperties=None, required=None, enum=None, const=None, type=<DataType.STRING: 'string'>, allOf=[], oneOf=[], anyOf=[], schema_not=None, items=None, prefixItems=[], properties=None, additionalProperties=None, description=None, schema_format=None, default=None, nullable=False, discriminator=None, readOnly=None, writeOnly=None, xml=None, externalDocs=None, example=None, deprecated=None)}, additionalProperties=None, description=None, schema_format=None, default=None, nullable=False, discriminator=None, readOnly=None, writeOnly=None, xml=None, externalDocs=None, example=None, deprecated=None)

If you believe this was a mistake or this tool is missing a feature you need, please open an issue at https://github.com/openapi-generators/openapi-python-client/issues/new/choose



**Desktop (please complete the following information):**
 - OS: Ubuntu 25.04
 - Python Version: 3.12.3
 - openapi-python-client version: 0.28.0

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

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

はじめの一歩

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

調査の方向性

まず、issue にある 2 つのスキーマを使って openapi-python-client generate --path=example.yaml --overwrite を実行し、次に inline の配列項目と参照されるモデルを処理するモデル生成のエントリーポイントを追跡します。inline 形式で重複した ResultAThingsItem モデルが報告されなくなり、GET レスポンスが生成されたクライアントに保持されれば完了です。

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

評価

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

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

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