acacode / acacode/swagger-typescript-api

Support for dates

オープン
#105 コメント 11 件 リアクション 11 件 担当者 1 名 @js2me が担当を希望しています GitHub で見る
enhancement
主要言語
TypeScript
スター
4.1k
フォーク
436
PR マージ指標
30日以内にマージされた PR はありません

説明

## Problem

Currently this library seems to ignore `format` information on data types. Most formats just add some metadata, so they are fine to skip, but `format: date-time` actually has semantic meaning that _could_ be understood by a typescript client.

Right now, if we have a model definition like this:

```json
"SomeType": {
"properties": {
"created": {
"type": "string",
"format": "date-time"
}
}
}
```

it generates this kind of model:

```ts
interface SomeType {
created: string;
}
```

There is no way for the client to know that this string represents a date. It would be really useful if it could generate this model instead:

```ts
interface SomeType {
created: Date;
}
```

## Implementation

I realize that adding custom data transformations is tricky and probably outside the scope of this library. But making only dates work might actually be possible.

Serializing data would be relatively straightforward. [JSON serialization](https://github.com/acacode/swagger-typescript-api/blob/master/src/templates/defaults/http-client.mustache#L75) would just work. For [form serialization](https://github.com/acacode/swagger-typescript-api/blob/master/src/templates/defaults/http-client.mustache#L77-L81) there would need to be a special case for `Date` instances.

The main challenge for implementation seems to make [safeParseResponse](https://github.com/acacode/swagger-typescript-api/blob/master/src/templates/defaults/http-client.mustache#L77-L81) work, because type information is not available at run-time. I think the only way to make that work is generate a custom parser per API type. Is that outside the scope of this library too?

## Further steps

I'd be happy to lend a hand if you think this would be a useful addition to the library. I am aware that templates can be customized, so I might also be able to work around this if necessary.

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

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

評価

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

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

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