acacode / acacode/swagger-typescript-api

Mapping schema iso Dates to js Date

Đang mở
#656 1 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ả

# Context

I understand I can use this

```
primitiveTypeConstructs: (struct) => ({
string: {
date: 'Date',
},
})
```

To make sure Schema date is mapped to js Date.
But this will just change TS type in the api response interfaces,

```
interface ResponseType {
someDate: string; // becomes Date
}
```

It will not actually make the generated api transform those date strings into a data like `const mappedDate = new Date(isoString)`

# My Question

Is there a way to make sure the actual api created already maps the dates it finds in the response to js Date.

I can think of one way of doing this which would be to write my own axios interceptor to do this. Something like this https://weblog.west-wind.com/posts/2014/jan/06/javascript-json-date-parsing-and-real-dates and then the interceptor could do
```
var date = JSON.parse(JSON.stringify(data),JSON.dateParser);
```

I am thinking about his coming from GraphQL where I can use an Apollo client transformer to auto cast all iso strings to dates.

Please let me know if there is another/better way to do this.

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.