Replies: 5 comments
-
Hello @shawncarr , Moreover, since version 16.3.0 I no longer use classes for creating custom types in favor of the zod's native API, and I'm suggesting you to consider it as well. Instead of classes, you can use:
Thus, you can base your custom type on already available types through additional checks, so that they will be depicted properly. Let me know what you think about that approach. Examples of z.customexpress-zod-api/src/schema-helpers.ts Lines 5 to 8 in de94703 Custom + safe parsingexpress-zod-api/src/upload-schema.ts Lines 11 to 28 in de94703 Refinement + transformationexpress-zod-api/src/date-out-schema.ts Lines 10 to 13 in de94703 Refinement + transformation + pipingexpress-zod-api/src/date-in-schema.ts Lines 10 to 14 in de94703 |
Beta Was this translation helpful? Give feedback.
-
I'm not sure what exactly your const makeDecimalSchema =
(fraction = 2) =>
z.string()
.regex(/^\d+\.\d+$/)
.refine((str) => str.split(".")[1].length === fraction) In case you also want it to be automatically transformed into number, then you can add: .transform((str) => parseFloat(str)) and optionally pipe it into a number type to ensure it's not .pipe(z.number()) Thus your schema could be depicted by a generator as a string with regex for the input flow, and as a number for the output, @shawncarr |
Beta Was this translation helpful? Give feedback.
-
Update on this topic. |
Beta Was this translation helpful? Give feedback.
-
The PR where I'm making this feature: Most likely it will not be released immediately in v19.0.0, but rather in v19.1.0. |
Beta Was this translation helpful? Give feedback.
-
🚀 Version 19.1.0 having the feature is published, @shawncarr && @kotsmile |
Beta Was this translation helpful? Give feedback.
-
In our project, we have a couple of custom
ZodType
s to handle specific requirements we have. For example, we have ZodDecimal which validates that the inputted data doesn't exceed decimal place value limits. Which does work great, but if we generate an integration or documentation for eachZodDecimal
typed property we get:amount: any
Which while not wrong, is not right and not helpful on the client side.
What would be nice is if as part of
IntegrationParams
there was an option foradditionalProducers
which you would pass tozodToTS
to be used to extend therules
property.rules: { ...producers, ...(additionalProducers ?? {}),
Of course something similar for Documentation and additional depicters
Beta Was this translation helpful? Give feedback.
All reactions