Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date Object Incompatibility with json-schema-to-ts Type Generation #106

Open
2 tasks done
mmdalix opened this issue Nov 9, 2024 · 3 comments · May be fixed by #103
Open
2 tasks done

Date Object Incompatibility with json-schema-to-ts Type Generation #106

mmdalix opened this issue Nov 9, 2024 · 3 comments · May be fixed by #103
Labels
help wanted Extra attention is needed

Comments

@mmdalix
Copy link

mmdalix commented Nov 9, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

5.1.0

Plugin version

4.0.0

Node.js version

20.11.1

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

24.1.0

Description

When working with fastify and its response serializer (fast-json-stringify), I noticed an inconsistency with how date objects are handled between fast-json-stringify and json-schema-to-ts.

The fast-json-stringify serializer allows me to directly provide a Date object, which is then correctly serialized to a date-time string format in the response. However, json-schema-to-ts requires the type definition to explicitly expect a string, not a Date, even though the JSON schema specifies a date-time format.

Example Schema:
response: { 200: { type: 'object', properties: { createdAt: { type: 'string', format: "date-time" }, } } }

Link to code that reproduces the bug

No response

Expected Behavior

It would be helpful if json-schema-to-ts could accommodate Date objects when a JSON schema property is set to a date-time format, matching the behavior of fast-json-stringify.

@mcollina
Copy link
Member

I do not have an idea on how this could be achieved, but a PR that implemented this would be amazing.

@mcollina mcollina added the help wanted Extra attention is needed label Nov 10, 2024
@bcomnes
Copy link

bcomnes commented Dec 18, 2024

I think I added support for a fix/workaround in this PR: #103

Using the deserialize type option on the serializer lets you return Date objects.

@bcomnes bcomnes linked a pull request Dec 18, 2024 that will close this issue
4 tasks
@mikaelkaron
Copy link

Wow @bcomnes - really firing on all cylinders today, this is the second issue I had with this plugin that you are fixing today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
4 participants