question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Schema example in README.md not work

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Reactions:10
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

17reactions
NoNameProvidedcommented, Aug 3, 2020

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.

10reactions
Gbuompriscocommented, Aug 28, 2021

Why not at least update the README and say “Don’t even try”? Also spent a whole day debugging this 😐

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found