OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVASCRIPT] constructFromObject redundantly re-initializes fields belonging to the parent

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

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

Issue: Bug
主要言語
Java
スター
26.8k
フォーク
7.7k
PR マージ指標
PR 指標を取得中

説明

Description

In MyObject.js :

    static constructFromObject(data, obj) {
        if (data) {
            obj = obj || new MyModel();
            BaseModel.constructFromObject(data, obj);

            if (data.hasOwnProperty('myProperty')) {
                obj['myProperty'] = ApiClient.convertToType(data['myProperty'], 'String');
            }
            if (data.hasOwnProperty('baseProprty')) {
                obj['baseProprty'] = ApiClient.convertToType(data['baseProprty'], 'String');
            }
        }
        return obj;
    }

In BaseObject.js :

    static constructFromObject(data, obj) {
        if (data) {
            obj = obj || new BaseModel();

            if (data.hasOwnProperty('baseProperty')) {
                obj['baseProperty'] = ApiClient.convertToType(data['baseProperty'], 'String');
            }
        }
        return obj;
    }

baseProperty is initialized from the call to BaseModel.constructFromObject and then initialized again after the properties unique to the derived object.

openapi-generator version

7.2.0

OpenAPI declaration file content or url
components:
    schemas:
      BaseModel:
        type: object
        properties:
          baseProperty:
            type: string
      MyModel:
        allOf:
          - $ref: "#/components/schemas/BaseModel"
        type: object
        properties:
          myProperty:
            type: string

Generation Details

I used the Gradle plugin with the "javascript" generatorName

Steps to reproduce

Define a schema using allOf (without discriminators) and generate JavaScript models.

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

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

はじめの一歩

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

調査の方向性

生成された MyObject.js と BaseObject.js の例から始め、提供された allOf スキーマを JavaScript ジェネレーターと Gradle プラグインで使用して問題を再現します。constructFromObject が継承プロパティをどのように処理するかを追跡し、その後モデルを再生成して、親のフィールドが重複して初期化されなくなったことを確認します。

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

評価

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

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

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