acacode / acacode/swagger-typescript-api

Nullability issue when description of field contains the string ' null'

オープン
#479 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
TypeScript
スター
4.1k
フォーク
436
PR マージ指標
30日以内にマージされた PR はありません

説明

Greetings, and thanks for the awesome work on a great package.

I encountered a strange bug today where one field in my enormous schema (12k+ lines) was set with `nullable: true`, but the generated type did not end up nullable.

I tracked it down to this bit of [code](https://github.com/acacode/swagger-typescript-api/blob/79274ac391f6f5d12ebc2e3773c5bf6783f7312e/src/schema-parser/schema-utils.js#L57)

```
isNullMissingInType = (schema, type) => {
const { nullable, type: schemaType } = schema || {};
return (
(nullable || !!_.get(schema, "x-nullable") || schemaType === this.config.Ts.Keyword.Null) &&
_.isString(type) &&
!type.includes(` ${this.config.Ts.Keyword.Null}`) &&
!type.includes(`${this.config.Ts.Keyword.Null} `)
);
};
```

Due to a description value of 'If has no mortgage then null, else contains mortgage details' the field would get generated without the null type. I don't have a lot of context for what is going on in the above but would be happy to submit a PR with a bit of assistance as to the fix.

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

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

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

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