Skip to content

Commit

Permalink
Updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelLoparev committed Mar 12, 2024
1 parent 73f2de3 commit 24a06b6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,21 @@ Schema-based validation without decorators is no longer supported by `class-vali

Due to nature of the decorators, the validated object has to be instantiated using `new Class()` syntax. If you have your class defined using class-validator decorators and you want to validate plain JS object (literal object or returned by JSON.parse), you need to transform it to the class instance via using [class-transformer](https://github.com/pleerock/class-transformer)).

## Method's arguments runtime validation

```typescript
import { ValidateArguments, IsNotEmptyArgument } from 'class-validator';

class MyClass {
@ValidateArguments
testMethod(@IsNotEmptyArgument test: string): void {
const someVariable = `${test}`;
}
}
```

When the value of `test` variable is read it will be validated in runtime. In case if it's invalid it will throw an exception.

## Samples

Take a look on samples in [./sample](https://github.com/pleerock/class-validator/tree/master/sample) for more examples of
Expand Down

0 comments on commit 24a06b6

Please sign in to comment.