OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript-fetch] Usage of Date(string) constructor yields Invalid Date on Edge
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)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
actual:
When converting JSON to JS objects on client side, date strings are converted to date objects using heavily discouraged Date(string) constructor. This causes issues on Edge, even for dates conforming to RFC3339 (eg. "1996-12-19T16:39:57-08:00").
expected:
Instead, some other date-parsing solution not depending on browser features should be implemented.
openapi-generator version
1.0.7-4.2.1
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: sample
version: 1.0.0
paths:
/sample:
get:
responses:
200:
description: ok
content:
application/json:
schema:
type: object
properties:
myDate:
type: string
format: date-time
Command line used for generation
"supportsES6": true,
"modelPropertyNaming": "original",
"typescriptThreePlus": true
Steps to reproduce
Generate code based on above spec. Open generated class for response object. Observe that new Date(json['myDate']) constructor is used. Using such constructor causes issues in Edge (Edge instead of Date object throws "Invalid Date").
Suggest a fix
Not sure about the best option, but for now - to avoid date library lock-in - I'm going with custom parsing of RFC3339 string and using Date constructor passing individual date/time components (sample PR soon).
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
Generate the sample typescript-fetch client with the listed options and inspect the generated response class's date-time conversion. Reproduce the Invalid Date behavior in Edge, then evaluate a browser-independent RFC3339 parsing approach and verify that generated date-time values remain valid there.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, 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