acacode / acacode/swagger-typescript-api

Non generic syntax for generating types with discriminators

Đang mở
#677 0 bình luận 1 reaction 0 người được giao Xem trên GitHub
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ả

I am generating zod schemas based on types generated by swagger-typescript-api. The schema generation doesn't work well with generics so I was wondering if it would be possible to have an alternative way of generating types with discriminators?

Today, this is the syntax it seems:
```
export type Value = BaseValue &
(
| BaseValueTypeMapping<"Type1", Value1>
| BaseValueTypeMapping<"Type2", Value2>
| BaseValueTypeMapping<"Type3", Value3>;

export type Value1 = BaseValue;

export type Value2 = BaseValue ;

export type Value3 = BaseValue ;

interface BaseValue {
$type: string;
value: number;
}

type BaseValueTypeMapping = {
$type: Key;
} & Type;
```

It would be nice if it was possible to just generate the types with discriminators like so:

```
export type Value = BaseValue &
(
| Value1
| Value2
| Value3 ;

export type Value1 = BaseValue & {
$type: "Type1"
};

export type Value2 = BaseValue & {
$type: "Type2"
};

export type Value3 = BaseValue & {
$type: "Type3"
};

interface BaseValue {
$type: string;
value: number;
}
```

Is this possible?

Thanks

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á.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.