UNPKG

2.1 kBTypeScriptView Raw
1/**
2 * Validation schema is a decorator-free way of validation of your objects.
3 * Also using validation schemas makes this library to be easily used with es6/es5.
4 */
5export interface ValidationSchema {
6 /**
7 * Schema name. This is required, because we tell validator to validate by this schema using its name.
8 */
9 name: string;
10 /**
11 * Validated properties.
12 */
13 properties: {
14 /**
15 * Name of the object's property to be validated which holds an array of validation constraints.
16 */
17 [propertyName: string]: {
18 /**
19 * Validation type. Should be one of the ValidationTypes value.
20 */
21 type: string;
22 /**
23 * Validator name.
24 */
25 name?: string;
26 /**
27 * Constraints set by validation type.
28 */
29 constraints?: any[];
30 /**
31 * Error message used to be used on validation fail.
32 * You can use "$value" to use value that was failed by validation.
33 * You can use "$constraint1" and "$constraint2" keys in the message string,
34 * and they will be replaced with constraint values if they exist.
35 * Message can be either string, either a function that returns a string.
36 * Second option allows to use values and custom messages depend of them.
37 */
38 message?: string | ((value?: any, constraint1?: any, constraint2?: any) => string);
39 /**
40 * Specifies if validated value is an array and each of its item must be validated.
41 */
42 each?: boolean;
43 /**
44 * Indicates if validation must be performed always, no matter of validation groups used.
45 */
46 always?: boolean;
47 /**
48 * Validation groups used for this validation.
49 */
50 groups?: string[];
51 /**
52 * Specific validation type options.
53 */
54 options?: any;
55 }[];
56 };
57}
58
\No newline at end of file