acacode / acacode/swagger-typescript-api

Omit readonly properties from PATCH requestContent

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

If a schema is referenced as the requestContent to an API, the generated RequestBody should omit readonly properties.

Given a user:

```ts
export interface User {
readonly id: number
name: string
readonly email: string
}
```

When this type is referenced to be the input to a PATCH request, the input argument should omit readonly properties.

It should be possible to do some Typescript magic to strip readonly properties, like mentioned in https://stackoverflow.com/a/49579497/2240706.

```ts
type IfEquals =
(() => T extends X ? 1 : 2) extends
(() => T extends Y ? 1 : 2) ? A : B;

type WritableKeys = {
[P in keyof T]-?: IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, P>
}[keyof T];

type ReadonlyKeys = {
[P in keyof T]-?: IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, never, P>
}[keyof T];

type OmitReadonly = Pick>;
```

It would then be a case of updating the generated code to declare the argument as `OmitReadonly`

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.