-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat(schema): add alias()
method that makes it easier to define multiple aliases for a given path
#12491
Conversation
…tiple aliases for a given path Fix #12368
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, with some minor details
changes to the types still need to be done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Would also be great if we make the API support arrays of strings as follows:
const schema = new Schema({
avatar: { type: String, alias: ['avatarURL', 'avatarImageURL'] }
});
Also, would be nice if we could have TS types and tests for those changes.
Co-authored-by: hasezoey <[email protected]>
Co-authored-by: hasezoey <[email protected]>
also just to be sure, where is checked that a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fix #12368
Summary
One approach we recommend for renaming fields from API requests is using aliases. Here's an example of using an alias to convert the GitHub API's
avatar_url
response toavatar
in Mongoose. But right now there's no way to define multiple aliases for a single field. This PR adds a new schema method, so you can do something likeschema.alias('avatar', ['avatar_url', 'photo'])
.Examples