Skip to content
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

Error messages not present in the generated JSON #40

Open
yab94 opened this issue Jul 1, 2020 · 4 comments
Open

Error messages not present in the generated JSON #40

yab94 opened this issue Jul 1, 2020 · 4 comments

Comments

@yab94
Copy link

yab94 commented Jul 1, 2020

Hi,
It would be great to include the error message inside the generated JSON.
Example:
@isemail({}, {message: "Please fill a correct email"})

Actualy the generated JSON doesn't contains the message.

@epiphone
Copy link
Owner

epiphone commented Jul 4, 2020

Which JSON Schema property do you propose using here?

@yab94
Copy link
Author

yab94 commented Jul 4, 2020

Hi Epiphone,

I would like your code to fill this JSON property :

ValidationSchema.properties.propertyName.message

This can be done by adding this block of code at line 128 of src/index.ts.

    let items = _.isFunction(converter) ? converter(meta, options) : converter

    if(meta.message) {
      items = {
        ...items,
        message: meta.message,
      } 
    }

My goal is that the backend can generates a rules file based on decorators and then the frontend can receives these rules to validate with the same rules that the backend without any differences between front and back rules. And all these rules will be coded with decorators in backend entities (typeorm) only once.
I just want to share the validation rules between front and back, and i wan't to include the error message in the transfered schema.
This transfert will be done just by a simple REST API like "GET /api/v1/books/rules".

@epiphone
Copy link
Owner

epiphone commented Jul 6, 2020

There's no message property in JSON Schema though, is there? I think supporting non-schema properties is outside the scope of this library. You might want to try using one of the provided extension points or going with a fork.

@yab94
Copy link
Author

yab94 commented Jul 6, 2020

Hi,
I am speaking about this message :
https://github.com/typestack/class-validator#validation-messages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants