OpenAPITools / OpenAPITools/openapi-generator
[BUG] [typescript] incorrect `Date` serialization for `format: date`
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The current implementation uses non-UTC methods to serialize dates using format: date.
This approach causes incompatibility with deserialization, which expects a UTC date.
Here's a screenshot that demonstrates the issue
openapi-generator version
Tested 7.1.0 and master. Not a regression.
Generation Details
openapi-generator-cli generate --generator-name="typescript" --additional-properties="enumPropertyNaming=original,modelPropertyNaming=original"
Steps to reproduce
Generate any spec file containing a date field with format: date.
Related issues/PRs
I couldn't find any issue or PR mentioning this.
Suggest a fix
Replace current serialization implementation with a solution that is used in other TS generators
I'll create a PR with proposed changes later today.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with modules/openapi-generator/src/main/resources/typescript/model/ObjectSerializer.mustache at the referenced serialization code, then compare the analogous logic in typescript-fetch/apis.mustache. Generate a TypeScript client from a spec containing a date field with format: date and verify that serialization produces a UTC-compatible value that deserialization can read.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100