acacode / acacode/swagger-typescript-api

`nullable: true` ignored if `type: object` and a property has `nullable: true`

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

説明

# What's wrong?
Hello again. I have a situation where I had an object with `nullable: true` and all was working well, then I needed to add some properties that had `nullable: true` and for some reason the ` | null` on the main object was removed from the types.

__This Schema:__
```yaml
MyDomainObjectSchema:
required:
- user
properties:
user:
type: object
nullable: true
required:
- id
- displayName
- email
properties:
id:
type: string
displayName:
type: string
email:
type: string
nullable: true
```

__Produces the following incorrect type:__
```typescript
export interface MyDomainObjectSchema {
user: {
id: string;
displayName: string;
email: string | null;
}; // where is the union with `null`?
}
```

## What works

If there are no properties that are nullable then the parent object is correctly typed as shown below:
__This Schema:__
```yaml
MyDomainObjectSchema:
required:
- user
properties:
user:
type: object
nullable: true
required:
- id
- displayName
- email
properties:
id:
type: string
displayName:
type: string
email:
type: string
# removing `nullable: true` here fixes the incorrect behavior
# nullable: true
```
__Produces the following correct result:__

```typescript
export interface MyDomainObjectSchema {
user: {
id: string;
displayName: string;
email: string;
} | null;
}
```

# What is expected

I expect that `nullable: true` will always apply to an object schema regardless of the properties and their conditions. I expect the original YAML schema provided would produce the following type:

```typescript
export interface MyDomainObjectSchema {
user: {
id: string;
displayName: string;
email: string | null;
} | null;
}
```

Thanks for the hard work on this. We're still happy to have it to work with :)

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

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

評価

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

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

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