-
Notifications
You must be signed in to change notification settings - Fork 811
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: Support for external message composing #1697
Conversation
Created a new Validator option field, externalMessageComposer, to support returning the supplied validation parameters inside the decorator back as an error message to allow users to create their standard custom messages, and allow them to easily create localized error messages. It is no longer the only option to write custom error messages every time using a decorator which breaks the DRY principle; the new feature helps clean code for custom error messages.
2ef8ff0
to
0da8f89
Compare
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.
I don't think we want to have a property with a mixed return type. Instead, we can return this data always under a new property.
I see this PR has no related discussion, before opening a PR please always open a discussion, detailed feature request, or bug report. PRs without related issue may be closed automatically in the future.
To clarify, I think we should implement returning the constraint metadata under a new key, but before you open a new PR please open a discussion first. |
Done! Thank you for the suggestion. |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Created a new Validator option field, externalMessageComposer, to support returning the supplied validation parameters inside the decorator back as an error message to allow users to create their standard custom messages, and allow them to easily create localized error messages. It is no longer the only option to write custom error messages every time using a decorator which breaks the DRY principle; the new feature helps clean code for custom error messages.
Description
Sample Code:
Before the feature support: Resulting Error Message inside ValidationError is:
Now if we set externalMessageComposer to true:
After the feature support and the externalMessageComposer is set to true:
Resulting Error Message inside ValidationError is now:
constraints: { minLength: '30' }
By this way; we can compose our message, as it was previosly not possible to get the validation parameter ('30').
For example; user may compose the following error message as the {1} argument ('30' in this example) is supplied within the class-validator error message.
"minLength": "{0} must be longer than or equal to {1} characters",
Checklist
Update index.md
)develop
)npm run prettier:check
passesnpm run lint:check
passesFixes
fixes #[issue number], fixes #[issue number]