loopbackio / loopbackio/loopback-next

Invalid TS models when properties are nullable

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

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

bug CLI OpenAPI
主要言語
TypeScript
スター
5.1k
フォーク
1.1k
平均マージ
2日 21時間
マージ済み PR(30日)
27

説明

Hi! It seems the openapi connector is not setting the correct TS type when setting true the nullable flag

For example, with the following JSON OpenAPI definition model:

      "TestObject": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "nullable": true,
             "default": null,
            "description": "Test property",
            "example": null
          },

It creates a model with the following property:

  @property({jsonSchema: {
  type: [
    'string',
    'null',
  ],
  default: null,
  description: 'Specific endpoint for this queue, if not specified, the generic endpoint for this service will be used',
}})
  endpoint?: string = null;

Obviously, as endpoint is set as string, it throws a TS Check error in build time:
error TS2322: Type 'null' is not assignable to type 'string | undefined'.

Why isn't setting the property type correctly, whereas in the type annotation seems to be aware of it?

Thanks!

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

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

はじめの一歩

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

調査の方向性

まず、nullable: true と default: null を持つプロパティについて、OpenAPI コネクターの TypeScript モデル生成を追跡します。生成されたプロパティのアノテーションを宣言された型と比較し、その後、関連するモデル生成のチェックまたは TypeScript ビルドを実行します。nullable プロパティが TS2322 なしで null を受け入れれば完了です。

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

評価

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

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

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