acacode / acacode/swagger-typescript-api
Nullability issue when description of field contains the string ' null'
- Ngôn ngữ chính
- TypeScript
- Star
- 4.1k
- Fork
- 436
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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.
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Đánh giá
Issue này chưa được đánh giá.