acacode / acacode/swagger-typescript-api
Nullability issue when description of field contains the string ' null'
- 主要语言
- 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 还没有评估数据。