-
-
Notifications
You must be signed in to change notification settings - Fork 144
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
Runtime variable default values (with tags.default) #963
Comments
The default tag has been designed to support only the JSON schema generation. |
Would there be another way to get a runtime variable to be a default value to a property in a type? We want it to be coming from the runtime, as the default value is different depending on the environment. With zod, we do it like so:
Is there an equivalent of that in Typia? |
No |
Is it something you would consider a good addition? Due to the runtime validation aspect of Typia it does feel logically to me to also have runtime default values instead of just static ones, but it might just be me or just out of scope |
I'm planning to implement the default value filling feature through transformer (raw data to class instance). It is not a matter even the target type is not a class type, but cannot sure when I can start it. |
Hello! We're exploring migrating our zod based DTOs to typia/nestia, but while doing a bit of exploring I ran into the following case which I couldn't quite solve yet.
We have an input model that requires a
chainId
to be passed.chainId
is a number, but only valid numbers from an environment variable are acceptable. We currently handling that like so and it works perfect!Question
What I couldn't figure out however, is how to pass a default value to the
chainId
that also comes from a runtime environment, for example: an environment variable. The reason we would want this, is becauseprocess.env.SUPPORTED_IDS
will be completely different per environment we run our application.In the snippet above, you can see that we simply pass a hardcoded
13337
number now:Is it somehow possible for typia to process default values based on a runtime variable? or is that outside of the scope for this project? Sorry if it has been asked before, but I couldn't quite find an issue related.
To clarify, we would want something like this, which currently (for obvious reasons) wouldn't quite work
I could technically see it work in similar fashion to how
tags.TagBase
handlesvalidate
, so something like adefault
option to call during runtime, of which the return value gets used as the default value.Something like:
Let me know if you like this idea, I could give it a swing at developing a PR.
The text was updated successfully, but these errors were encountered: