2 (options?: ajv.Options): ajv.Ajv;
3 new (options?: ajv.Options): ajv.Ajv;
6 declare namespace ajv {
9 * Validate data using schema
10 * Schema will be compiled and cached (using serialized JSON as key. [json-stable-stringify](https://github.com/substack/json-stable-stringify) is used to serialize.
11 * @param {String|Object} schemaKeyRef key, ref or schema object
12 * @param {Any} data to be validated
13 * @return {Boolean} validation result. Errors from the last validation will be available in `ajv.errors` (and also in compiled schema: `schema.errors`).
15 validate(schemaKeyRef: Object | string, data: any): boolean;
17 * Create validating function for passed schema.
18 * @param {Object} schema schema object
19 * @return {Function} validating function
21 compile(schema: Object): ValidateFunction;
23 * Creates validating function for passed schema with asynchronous loading of missing schemas.
24 * `loadSchema` option should be a function that accepts schema uri and node-style callback.
26 * @param {Object} schema schema object
27 * @param {Function} callback node-style callback, it is always called with 2 parameters: error (or null) and validating function.
29 compileAsync(schema: Object, callback: (err: Error, validate: ValidateFunction) => any): void;
31 * Adds schema to the instance.
32 * @param {Object|Array} schema schema or array of schemas. If array is passed, `key` and other parameters will be ignored.
33 * @param {String} key Optional schema key. Can be passed to `validate` method instead of schema object or id/ref. One schema per instance can have empty `id` and `key`.
35 addSchema(schema: Array<Object> | Object, key?: string): void;
37 * Add schema that will be used to validate other schemas
38 * options in META_IGNORE_OPTIONS are alway set to false
39 * @param {Object} schema schema object
40 * @param {String} key optional schema key
42 addMetaSchema(schema: Object, key?: string): void;
45 * @param {Object} schema schema to validate
46 * @return {Boolean} true if schema is valid
48 validateSchema(schema: Object): boolean;
50 * Get compiled schema from the instance by `key` or `ref`.
51 * @param {String} keyRef `key` that was passed to `addSchema` or full schema reference (`schema.id` or resolved id).
52 * @return {Function} schema validating function (with property `schema`).
54 getSchema(keyRef: string): ValidateFunction;
56 * Remove cached schema(s).
57 * If no parameter is passed all schemas but meta-schemas are removed.
58 * If RegExp is passed all schemas with key/id matching pattern but meta-schemas are removed.
59 * Even if schema is referenced by other schemas it still can be removed as other schemas have local references.
60 * @param {String|Object|RegExp} schemaKeyRef key, ref, pattern to match key/ref or schema object
62 removeSchema(schemaKeyRef?: Object | string | RegExp): void;
65 * @param {String} name format name
66 * @param {String|RegExp|Function} format string is converted to RegExp; function should return boolean (true when valid)
68 addFormat(name: string, format: FormatValidator | FormatDefinition): void;
70 * Define custom keyword
72 * @param {String} keyword custom keyword, should be a valid identifier, should be different from all standard, custom and macro keywords.
73 * @param {Object} definition keyword definition object with properties `type` (type(s) which the keyword applies to), `validate` or `compile`.
75 addKeyword(keyword: string, definition: KeywordDefinition): void;
77 * Get keyword definition
79 * @param {String} keyword pre-defined or custom keyword.
80 * @return {Object|Boolean} custom keyword definition, `true` if it is a predefined keyword, `false` otherwise.
82 getKeyword(keyword: string): Object | boolean;
86 * @param {String} keyword pre-defined or custom keyword.
88 removeKeyword(keyword: string): void;
90 * Convert array of error message objects to string
91 * @param {Array<Object>} errors optional array of validation errors, if not passed errors from the instance are used.
92 * @param {Object} options optional options with properties `separator` and `dataVar`.
93 * @return {String} human readable string with all errors descriptions
95 errorsText(errors?: Array<ErrorObject>, options?: ErrorsTextOptions): string;
96 errors?: Array<ErrorObject>;
99 interface Thenable <R> {
100 then <U> (onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): Thenable<U>;
103 interface ValidateFunction {
107 parentData?: Object | Array<any>,
108 parentDataProperty?: string | number,
109 rootData?: Object | Array<any>
110 ): boolean | Thenable<boolean>;
111 errors?: Array<ErrorObject>;
119 jsonPointers?: boolean;
120 uniqueItems?: boolean;
124 unknownFormats?: boolean | string | Array<string>;
125 schemas?: Array<Object> | Object;
126 ownProperties?: boolean;
127 missingRefs?: boolean | string;
128 loadSchema?: (uri: string, cb: (err: Error, schema: Object) => any) => any;
129 removeAdditional?: boolean | string;
130 useDefaults?: boolean | string;
131 coerceTypes?: boolean | string;
132 async?: boolean | string;
133 transpile?: string | ((code: string) => string);
134 meta?: boolean | Object;
135 validateSchema?: boolean | string;
136 addUsedSchema?: boolean;
137 inlineRefs?: boolean | number;
138 passContext?: boolean;
139 loopRequired?: number;
140 multipleOfPrecision?: number;
141 errorDataPath?: string;
143 beautify?: boolean | Object;
147 type FormatValidator = string | RegExp | ((data: string) => boolean);
149 interface FormatDefinition {
150 validate: FormatValidator;
151 compare: (data1: string, data2: string) => number;
155 interface KeywordDefinition {
156 type?: string | Array<string>;
158 errors?: boolean | string;
159 // schema: false makes validate not to expect schema (ValidateFunction)
163 // one and only one of the following properties should be present
164 validate?: ValidateFunction | SchemaValidateFunction;
165 compile?: (schema: Object, parentSchema: Object) => ValidateFunction;
166 macro?: (schema: Object, parentSchema: Object) => Object;
167 inline?: (it: Object, keyword: string, schema: Object, parentSchema: Object) => string;
170 interface SchemaValidateFunction {
174 parentSchema?: Object,
176 parentData?: Object | Array<any>,
177 parentDataProperty?: string | number
178 ): boolean | Thenable<boolean>;
179 errors?: Array<ErrorObject>;
182 interface ErrorsTextOptions {
187 interface ErrorObject {
191 params: ErrorParameters;
192 // Excluded if messages set to false.
194 // These are added with the `verbose` option.
196 parentSchema?: Object;
200 type ErrorParameters = RefParams | LimitParams | AdditionalPropertiesParams |
201 DependenciesParams | FormatParams | ComparisonParams |
202 MultipleOfParams | PatternParams | RequiredParams |
203 TypeParams | UniqueItemsParams | CustomParams |
204 PatternGroupsParams | PatternRequiredParams |
205 SwitchParams | NoParams | EnumParams;
207 interface RefParams {
211 interface LimitParams {
215 interface AdditionalPropertiesParams {
216 additionalProperty: string;
219 interface DependenciesParams {
221 missingProperty: string;
226 interface FormatParams {
230 interface ComparisonParams {
232 limit: number | string;
236 interface MultipleOfParams {
240 interface PatternParams {
244 interface RequiredParams {
245 missingProperty: string;
248 interface TypeParams {
252 interface UniqueItemsParams {
257 interface CustomParams {
261 interface PatternGroupsParams {
267 interface PatternRequiredParams {
268 missingPattern: string;
271 interface SwitchParams {
275 interface NoParams {}
277 interface EnumParams {
278 allowedValues: Array<any>;