acacode / acacode/swagger-typescript-api
Nullability issue when description of field contains the string ' null'
- Dominant language
- TypeScript
- Stars
- 4.1k
- Forks
- 436
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.