Schema example in README.md not work
See original GitHub issueI just copy and paste, change object value and try to trigger errors…but result shows empty array… please help, give me some clues… i was trapped by this in hours…thank you
----------- terminal info --------------- [] Validation succeed.
import {ValidationSchema, registerSchema, validate} from "class-validator";
export let UserValidationSchema: ValidationSchema = { // using interface here is not required, its just for type-safety
name: "myUserSchema", // this is required, and must be unique
properties: {
firstName: [{
type: "minLength", // validation type. All validation types are listed in ValidationTypes class.
constraints: [2]
}, {
type: "maxLength",
constraints: [20]
}],
lastName: [{
type: "minLength",
constraints: [2]
}, {
type: "maxLength",
constraints: [20]
}],
email: [{
type: "isEmail"
}]
}
};
registerSchema(UserValidationSchema);
const user = { firstName: "1", secondName: "1", email: "johnycage.com" };
validate("myUserSchema", user).then(errors => {
console.log(errors)
if (errors.length > 0) {
console.log("Validation failed: ", errors);
} else {
console.log("Validation succeed.");
}
});
Issue Analytics
- State:
- Created 3 years ago
- Reactions:10
- Comments:17 (5 by maintainers)
Top Results From Across the Web
Markdown: Guide for the simple markup language - IONOS
Find out all about this simple markup language Markdown. In the tutorial, you'll learn the most important elements and discover what's ...
Read more >Documentation Style Guide - GitLab Docs
Documentation Style Guide. This document defines the standards for GitLab documentation, including grammar, formatting, word use, and more.
Read more >How to display Table in README.md file in Github?
md files from Azure DevOps Wiki and most all tables came across and render just fine. That's without the "preceding blank line" and...
Read more >Source of README.md - json-schema - European Commission
env file to store your credentials, so you don't have to enter them every time you run the publish command. Example: EBSI_ENV=pilot KID="did: ......
Read more >Relative urls in readme.md files only work half the time ... - Jira
In my readme.md file, I link to the getting_started.md document like so: ... This will of course work only for a projects with...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
FYI, soon we I will open a discussion about removing the schema validation functionality at all from class-validator. There are libraries dedicated for that, so we should not roll our own but focus on the decorator based validation.
Why not at least update the README and say “Don’t even try”? Also spent a whole day debugging this 😐