Skip to content

Commit

Permalink
some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AmauryD committed Jul 6, 2022
1 parent f66f4da commit 1e743c2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Add the following to your tsconfig.json
All decorators accept an object of options that apply to the type being used, for a full list of options please refer to the fastest-validator [documentation](https://www.npmjs.com/package/fastest-validator).

**@Schema(strict=false, messages={})** - Schema decorator.
**@Schema({ strict = false, async = false }, messages={})** - Schema decorator.

**@Field({})** - Generic decorator, no default properties set. Will apply all options to the schema.

Expand Down Expand Up @@ -143,7 +144,7 @@ All decorators accept an object of options that apply to the type being used, fo

```ts
@Custom({
check (value: number, errors: {type: string}[]){
check (value: number, errors: {type: string, actual: number}[]){
if (value % 2 !== 0) {
errors.push({ type: "even", actual : value });
}
Expand Down
6 changes: 1 addition & 5 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,11 +841,7 @@ describe("Custom async", () => {
})
prop!: unknown;
}

/**
* $$async key is removed for unknown reason from schema object at compile()
* https://github.com/icebob/fastest-validator/blob/a746f9311d3ebeda986e4896d39619bfc925ce65/lib/validator.js#L176
*/

expect(getSchema(Test)).toEqual({
$$strict: false,
$$async: true,
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export function Schema (schemaOptions?: StrictMode | SchemaOptions, messages = {

/**
* Make a copy of the schema, in order to keep the original from being overriden or deleted by fastest-validator
* $$async key is removed from schema object at compile()
* https://github.com/icebob/fastest-validator/blob/a746f9311d3ebeda986e4896d39619bfc925ce65/lib/validator.js#L176
*/
Reflect.defineMetadata(COMPILE_KEY, v.compile({...s}), target);
return target;
Expand Down Expand Up @@ -132,6 +134,7 @@ export function Nested (options: any | any[] = {}): any {
const props = Object.assign({}, getSchema(t));
const strict = props.$$strict || false;
delete props.$$strict;
// never $$async in nested
delete props.$$async;
updateSchema(target, key, { ...options, props, strict, type: "object" });
};
Expand Down

0 comments on commit 1e743c2

Please sign in to comment.