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

fix(zod): date format now respects useDates override #1406

Merged
merged 2 commits into from
May 29, 2024

Conversation

TommoLeedsy
Copy link
Contributor

@TommoLeedsy TommoLeedsy commented May 28, 2024

Status

READY

Description

This PR fixes #1402 and respects the useDates override when generating the zod specification.

@melloware melloware added the zod Zod related issue label May 28, 2024
@melloware
Copy link
Collaborator

Looks like tests are failing with...

Error: generated/zod/circularReferences.ts(30,29): error TS2339: Property 'date' does not exist on type 'ZodString'.
Error: generated/zod/coerce.ts(30,36): error TS2339: Property 'coerce' does not exist on type 'ZodString'.
Error: generated/zod/preprocess.ts(31,29): error TS2339: Property 'date' does not exist on type 'ZodString'.
Error: generated/zod/strict-mode.ts(30,2[9](https://github.com/anymaniax/orval/actions/runs/9276296526/job/25523055915?pr=1406#step:11:10)): error TS2339: Property 'date' does not exist on type 'ZodString'.

@TommoLeedsy
Copy link
Contributor Author

@melloware Yep already on it, didn't run the generated locally as I didn't know they existed aha

Copy link

@RyoNkmr RyoNkmr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you(and I'm so sorry)

Comment on lines 135 to 152
if (!context.output.override.useDates) {
functions.push([type as string, undefined]);
}
functions.push(['date', undefined]);
break;
}

functions.push([type as string, undefined]);

if (schema.format === 'date-time') {
functions.push(['datetime', undefined]);
if (!context.output.override.useDates) {
functions.push([type as string, undefined], ['datetime', undefined]);
} else {
functions.push(['date', undefined]);
}
break;
}

functions.push([type as string, undefined]);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me.
and if i had to say, it can makes this simple to handle useDates first like:

      if (
        context.output.override.useDates &&
        (schema.format === 'date' || schema.format === 'date-time')
      ) {
        functions.push(['date', undefined]);
        break;
      }

      functions.push([type as string, undefined]);

      if (schema.format === 'date') {
        functions.push(['date', undefined]);
        break;
      }

      if (schema.format === 'date-time') {
        functions.push(['datetime', undefined]);
        break;
      }

Copy link
Collaborator

@melloware melloware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments from @RyoNkmr

@TommoLeedsy
Copy link
Contributor Author

@melloware @RyoNkmr This should be ready for re-review, all the tests now pass and the requested changes were made.

@melloware melloware merged commit 36ebf4f into orval-labs:master May 29, 2024
2 checks passed
@melloware melloware added this to the 6.30.0 milestone May 29, 2024
@TommoLeedsy TommoLeedsy deleted the fix/zod-data-format branch May 29, 2024 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
zod Zod related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Zod: type string format date should be "YYYY-MM-DD"
3 participants