swagger-api / swagger-api/swagger-codegen

Typescript: Dates Are Not Deserialized

Open
#2,776 18 comments 17 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: TypeScript help wanted Issue: Bug
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

If you have a property in a definition that is a string with date-time format, the typescript generated model makes that property a Date type. However, the response in the client is given verbatim. It never looks for date strings and actually transforms them in to Date objects. So the project will build, but fails at runtime if you try to access Date specific methods since it's actually a string.

I imagine this relates to:
https://github.com/swagger-api/swagger-codegen/issues/1951

Since this PR focuses on deserializing dates in the response. I would suggest making those properties strings until deserialization is supported, otherwise the type checking isn't actually accurate.

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

Start by locating the TypeScript generator templates for model types and response handling, then reproduce a generated client with a string property marked date-time. Verify whether responses are returned verbatim and determine whether deserialization or string-typed models is the intended correction; done means runtime values and generated types agree.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, 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.