swagger-api / swagger-api/swagger-codegen

[Typescript] Inconsistently handling format of date.

Open
#8,577 0 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Within the supported typescript frameworks, typescript-fetch and typescript-jquery support format date by transforming it into a javascript Date, while typescript-node and typescript-angular leave them as strings. It would be good to handle format date consistently across Typescript.

Swagger declaration file content or url
{
  "name": "myDate",
  "type": "string",
  "format": "date",
}
Suggest a fix/enhancement

I suggest if the format is a date, we should just leave it as a string following the typescript-node and typescript-angular examples. My concern of turning a YYYY-MM-DD string into a Javascript Date is that depending on your timezone, using toIsoString has the potential to roll your date forward or backwards a day as discussed here.

I encountered a bug in the typescript-fetch library where the code it generates requires an input parameter of a string, but then tries to call a function on it as if it is a Javascript Date object. The fix I suggested would solve this issue as well.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Compare the TypeScript generator behavior in typescript-fetch, typescript-jquery, typescript-node, and typescript-angular for fields declared with string format date. Start by locating how each generator transforms or preserves that format. Done means the supported TypeScript frameworks handle date values consistently and no generated client calls date methods on a string.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.