2 (options?: ajv.Options): ajv.Ajv;
3 new(options?: ajv.Options): ajv.Ajv;
4 ValidationError: typeof AjvErrors.ValidationError;
5 MissingRefError: typeof AjvErrors.MissingRefError;
6 $dataMetaSchema: object;
9 declare namespace AjvErrors {
10 class ValidationError extends Error {
11 constructor(errors: Array<ajv.ErrorObject>);
14 errors: Array<ajv.ErrorObject>;
19 class MissingRefError extends Error {
20 constructor(baseId: string, ref: string, message?: string);
21 static message: (baseId: string, ref: string) => string;
25 missingSchema: string;
29 declare namespace ajv {
30 type ValidationError = AjvErrors.ValidationError;
32 type MissingRefError = AjvErrors.MissingRefError;
36 * Validate data using schema
37 * Schema will be compiled and cached (using serialized JSON as key, [fast-json-stable-stringify](https://github.com/epoberezkin/fast-json-stable-stringify) is used to serialize by default).
38 * @param {string|object|Boolean} schemaKeyRef key, ref or schema object
39 * @param {Any} data to be validated
40 * @return {Boolean} validation result. Errors from the last validation will be available in `ajv.errors` (and also in compiled schema: `schema.errors`).
42 validate(schemaKeyRef: object | string | boolean, data: any): boolean | PromiseLike<any>;
44 * Create validating function for passed schema.
45 * @param {object|Boolean} schema schema object
46 * @return {Function} validating function
48 compile(schema: object | boolean): ValidateFunction;
50 * Creates validating function for passed schema with asynchronous loading of missing schemas.
51 * `loadSchema` option should be a function that accepts schema uri and node-style callback.
53 * @param {object|Boolean} schema schema object
54 * @param {Boolean} meta optional true to compile meta-schema; this parameter can be skipped
55 * @param {Function} callback optional node-style callback, it is always called with 2 parameters: error (or null) and validating function.
56 * @return {PromiseLike<ValidateFunction>} validating function
58 compileAsync(schema: object | boolean, meta?: Boolean, callback?: (err: Error, validate: ValidateFunction) => any): PromiseLike<ValidateFunction>;
60 * Adds schema to the instance.
61 * @param {object|Array} schema schema or array of schemas. If array is passed, `key` and other parameters will be ignored.
62 * @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`.
63 * @return {Ajv} this for method chaining
65 addSchema(schema: Array<object> | object, key?: string): Ajv;
67 * Add schema that will be used to validate other schemas
68 * options in META_IGNORE_OPTIONS are alway set to false
69 * @param {object} schema schema object
70 * @param {string} key optional schema key
71 * @return {Ajv} this for method chaining
73 addMetaSchema(schema: object, key?: string): Ajv;
76 * @param {object|Boolean} schema schema to validate
77 * @return {Boolean} true if schema is valid
79 validateSchema(schema: object | boolean): boolean;
81 * Get compiled schema from the instance by `key` or `ref`.
82 * @param {string} keyRef `key` that was passed to `addSchema` or full schema reference (`schema.id` or resolved id).
83 * @return {Function} schema validating function (with property `schema`). Returns undefined if keyRef can't be resolved to an existing schema.
85 getSchema(keyRef: string): ValidateFunction | undefined;
87 * Remove cached schema(s).
88 * If no parameter is passed all schemas but meta-schemas are removed.
89 * If RegExp is passed all schemas with key/id matching pattern but meta-schemas are removed.
90 * Even if schema is referenced by other schemas it still can be removed as other schemas have local references.
91 * @param {string|object|RegExp|Boolean} schemaKeyRef key, ref, pattern to match key/ref or schema object
92 * @return {Ajv} this for method chaining
94 removeSchema(schemaKeyRef?: object | string | RegExp | boolean): Ajv;
97 * @param {string} name format name
98 * @param {string|RegExp|Function} format string is converted to RegExp; function should return boolean (true when valid)
99 * @return {Ajv} this for method chaining
101 addFormat(name: string, format: FormatValidator | FormatDefinition): Ajv;
103 * Define custom keyword
105 * @param {string} keyword custom keyword, should be a valid identifier, should be different from all standard, custom and macro keywords.
106 * @param {object} definition keyword definition object with properties `type` (type(s) which the keyword applies to), `validate` or `compile`.
107 * @return {Ajv} this for method chaining
109 addKeyword(keyword: string, definition: KeywordDefinition): Ajv;
111 * Get keyword definition
113 * @param {string} keyword pre-defined or custom keyword.
114 * @return {object|Boolean} custom keyword definition, `true` if it is a predefined keyword, `false` otherwise.
116 getKeyword(keyword: string): object | boolean;
120 * @param {string} keyword pre-defined or custom keyword.
121 * @return {Ajv} this for method chaining
123 removeKeyword(keyword: string): Ajv;
127 * @param {object} definition keyword definition object
128 * @param {boolean} throwError true to throw exception if definition is invalid
129 * @return {boolean} validation result
131 validateKeyword(definition: KeywordDefinition, throwError: boolean): boolean;
133 * Convert array of error message objects to string
134 * @param {Array<object>} errors optional array of validation errors, if not passed errors from the instance are used.
135 * @param {object} options optional options with properties `separator` and `dataVar`.
136 * @return {string} human readable string with all errors descriptions
138 errorsText(errors?: Array<ErrorObject> | null, options?: ErrorsTextOptions): string;
139 errors?: Array<ErrorObject> | null;
143 interface CustomLogger {
144 log(...args: any[]): any;
145 warn(...args: any[]): any;
146 error(...args: any[]): any;
149 interface ValidateFunction {
153 parentData?: object | Array<any>,
154 parentDataProperty?: string | number,
155 rootData?: object | Array<any>
156 ): boolean | PromiseLike<any>;
157 schema?: object | boolean;
158 errors?: null | Array<ErrorObject>;
161 root?: ValidateFunction | object;
170 jsonPointers?: boolean;
171 uniqueItems?: boolean;
173 format?: false | string;
176 unknownFormats?: true | string[] | 'ignore';
177 schemas?: Array<object> | object;
178 schemaId?: '$id' | 'id' | 'auto';
179 missingRefs?: true | 'ignore' | 'fail';
180 extendRefs?: true | 'ignore' | 'fail';
181 loadSchema?: (uri: string, cb?: (err: Error, schema: object) => void) => PromiseLike<object | boolean>;
182 removeAdditional?: boolean | 'all' | 'failing';
183 useDefaults?: boolean | 'empty' | 'shared';
184 coerceTypes?: boolean | 'array';
185 strictDefaults?: boolean | 'log';
186 strictKeywords?: boolean | 'log';
187 strictNumbers?: boolean;
188 async?: boolean | string;
189 transpile?: string | ((code: string) => string);
190 meta?: boolean | object;
191 validateSchema?: boolean | 'log';
192 addUsedSchema?: boolean;
193 inlineRefs?: boolean | number;
194 passContext?: boolean;
195 loopRequired?: number;
196 ownProperties?: boolean;
197 multipleOfPrecision?: boolean | number;
198 errorDataPath?: string,
200 sourceCode?: boolean;
201 processCode?: (code: string, schema: object) => string;
203 logger?: CustomLogger | false;
205 serialize?: ((schema: object | boolean) => any) | false;
208 type FormatValidator = string | RegExp | ((data: string) => boolean | PromiseLike<any>);
209 type NumberFormatValidator = ((data: number) => boolean | PromiseLike<any>);
211 interface NumberFormatDefinition {
213 validate: NumberFormatValidator;
214 compare?: (data1: number, data2: number) => number;
218 interface StringFormatDefinition {
220 validate: FormatValidator;
221 compare?: (data1: string, data2: string) => number;
225 type FormatDefinition = NumberFormatDefinition | StringFormatDefinition;
227 interface KeywordDefinition {
228 type?: string | Array<string>;
231 errors?: boolean | string;
233 // schema: false makes validate not to expect schema (ValidateFunction)
235 statements?: boolean;
236 dependencies?: Array<string>;
239 // one and only one of the following properties should be present
240 validate?: SchemaValidateFunction | ValidateFunction;
241 compile?: (schema: any, parentSchema: object, it: CompilationContext) => ValidateFunction;
242 macro?: (schema: any, parentSchema: object, it: CompilationContext) => object | boolean;
243 inline?: (it: CompilationContext, keyword: string, schema: any, parentSchema: object) => string;
246 interface CompilationContext {
249 dataPathArr: string[];
256 [index: string]: FormatDefinition | undefined;
259 [index: string]: KeywordDefinition | undefined;
261 compositeRule: boolean;
262 validate: (schema: object) => boolean;
264 copy(obj: any, target?: any): any;
265 toHash(source: string[]): { [index: string]: true | undefined };
266 equal(obj: any, target: any): boolean;
267 getProperty(str: string): string;
268 schemaHasRules(schema: object, rules: any): string;
269 escapeQuotes(str: string): string;
270 toQuotedString(str: string): string;
271 getData(jsonPointer: string, dataLevel: number, paths: string[]): string;
272 escapeJsonPointer(str: string): string;
273 unescapeJsonPointer(str: string): string;
274 escapeFragment(str: string): string;
275 unescapeFragment(str: string): string;
280 interface SchemaValidateFunction {
284 parentSchema?: object,
286 parentData?: object | Array<any>,
287 parentDataProperty?: string | number,
288 rootData?: object | Array<any>
289 ): boolean | PromiseLike<any>;
290 errors?: Array<ErrorObject>;
293 interface ErrorsTextOptions {
298 interface ErrorObject {
302 params: ErrorParameters;
303 // Added to validation errors of propertyNames keyword schema
304 propertyName?: string;
305 // Excluded if messages set to false.
307 // These are added with the `verbose` option.
309 parentSchema?: object;
313 type ErrorParameters = RefParams | LimitParams | AdditionalPropertiesParams |
314 DependenciesParams | FormatParams | ComparisonParams |
315 MultipleOfParams | PatternParams | RequiredParams |
316 TypeParams | UniqueItemsParams | CustomParams |
317 PatternRequiredParams | PropertyNamesParams |
318 IfParams | SwitchParams | NoParams | EnumParams;
320 interface RefParams {
324 interface LimitParams {
328 interface AdditionalPropertiesParams {
329 additionalProperty: string;
332 interface DependenciesParams {
334 missingProperty: string;
339 interface FormatParams {
343 interface ComparisonParams {
345 limit: number | string;
349 interface MultipleOfParams {
353 interface PatternParams {
357 interface RequiredParams {
358 missingProperty: string;
361 interface TypeParams {
365 interface UniqueItemsParams {
370 interface CustomParams {
374 interface PatternRequiredParams {
375 missingPattern: string;
378 interface PropertyNamesParams {
379 propertyName: string;
383 failingKeyword: string;
386 interface SwitchParams {
390 interface NoParams { }
392 interface EnumParams {
393 allowedValues: Array<any>;