-
-
Notifications
You must be signed in to change notification settings - Fork 220
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
[✨Feature Request]: add support aliases #163
Comments
Thank you for sharing this idea. At the moment I am not sure if we should implement this. Is there a schema library that supports this feature? |
I am closing this issue due to inactivity. I welcome feedback if there is still interest in this feature. |
Hi Fabian. I want to contribute back to this issue since aliases are features of validation libraries in other languages. However, I haven't seen this behavior used in TS validation libs which was pretty surprising. Examples: Here's an example of a Pydantic model with aliases: class TestModel(BaseModel):
static_field: Optional[float] = 0.0
aliased_field: Optional[float] = Field(
default=0.0,
alias=AliasChoices("aliased_field", "dynamic_field")
) And from here, if |
It is possible to implement it as a transformation action. Here is an example API: import * as v from './dist/index.js';
const Schema = v.pipe(
v.object({
email: v.pipe(v.string(), v.email()),
name: v.pipe(v.string(), v.nonEmpty()),
}),
v.aliasKey('name', 'first_name')
);
// Now input will be: { email: string, name: string }
// And output will be: { email: string, first_name: string } Issue #981 is partly related. |
Sorry, that's a bit hard to understand from my end. So, |
Yes, Here is some context:
|
Thanks for the context. I'll take a look at it, but I don't believe I'm skilled enough in TS to properly PR this action. Can you consider reopening the issue and maybe someone else will take it up before I can? |
Yes, don't worry. We could look into this when working on #981. |
@fabian-hiller @PandaWorker It would be possible to actually write the alias action if there was some way to pass the original object or some custom object via parse/safeParse config or global config. |
How about adding such functionality?
The text was updated successfully, but these errors were encountered: