acacode / acacode/swagger-typescript-api

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

Aberta
#479 0 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
TypeScript
Estrelas
4.1k
Forks
436
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

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.

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.