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;
142 interface CustomLogger {
143 log(...args: any[]): any;
144 warn(...args: any[]): any;
145 error(...args: any[]): any;
148 interface ValidateFunction {
152 parentData?: object | Array<any>,
153 parentDataProperty?: string | number,
154 rootData?: object | Array<any>
155 ): boolean | PromiseLike<any>;
156 schema?: object | boolean;
157 errors?: null | Array<ErrorObject>;
160 root?: ValidateFunction | object;
169 jsonPointers?: boolean;
170 uniqueItems?: boolean;
172 format?: false | string;
175 unknownFormats?: true | string[] | 'ignore';
176 schemas?: Array<object> | object;
177 schemaId?: '$id' | 'id' | 'auto';
178 missingRefs?: true | 'ignore' | 'fail';
179 extendRefs?: true | 'ignore' | 'fail';
180 loadSchema?: (uri: string, cb?: (err: Error, schema: object) => void) => PromiseLike<object | boolean>;
181 removeAdditional?: boolean | 'all' | 'failing';
182 useDefaults?: boolean | 'empty' | 'shared';
183 coerceTypes?: boolean | 'array';
184 strictDefaults?: boolean | 'log';
185 strictKeywords?: boolean | 'log';
186 strictNumbers?: boolean;
187 async?: boolean | string;
188 transpile?: string | ((code: string) => string);
189 meta?: boolean | object;
190 validateSchema?: boolean | 'log';
191 addUsedSchema?: boolean;
192 inlineRefs?: boolean | number;
193 passContext?: boolean;
194 loopRequired?: number;
195 ownProperties?: boolean;
196 multipleOfPrecision?: boolean | number;
197 errorDataPath?: string,
199 sourceCode?: boolean;
200 processCode?: (code: string, schema: object) => string;
202 logger?: CustomLogger | false;
204 serialize?: ((schema: object | boolean) => any) | false;
207 type FormatValidator = string | RegExp | ((data: string) => boolean | PromiseLike<any>);
208 type NumberFormatValidator = ((data: number) => boolean | PromiseLike<any>);
210 interface NumberFormatDefinition {
212 validate: NumberFormatValidator;
213 compare?: (data1: number, data2: number) => number;
217 interface StringFormatDefinition {
219 validate: FormatValidator;
220 compare?: (data1: string, data2: string) => number;
224 type FormatDefinition = NumberFormatDefinition | StringFormatDefinition;
226 interface KeywordDefinition {
227 type?: string | Array<string>;
230 errors?: boolean | string;
232 // schema: false makes validate not to expect schema (ValidateFunction)
234 statements?: boolean;
235 dependencies?: Array<string>;
238 // one and only one of the following properties should be present
239 validate?: SchemaValidateFunction | ValidateFunction;
240 compile?: (schema: any, parentSchema: object, it: CompilationContext) => ValidateFunction;
241 macro?: (schema: any, parentSchema: object, it: CompilationContext) => object | boolean;
242 inline?: (it: CompilationContext, keyword: string, schema: any, parentSchema: object) => string;
245 interface CompilationContext {
248 dataPathArr: string[];
255 [index: string]: FormatDefinition | undefined;
258 [index: string]: KeywordDefinition | undefined;
260 compositeRule: boolean;
261 validate: (schema: object) => boolean;
263 copy(obj: any, target?: any): any;
264 toHash(source: string[]): { [index: string]: true | undefined };
265 equal(obj: any, target: any): boolean;
266 getProperty(str: string): string;
267 schemaHasRules(schema: object, rules: any): string;
268 escapeQuotes(str: string): string;
269 toQuotedString(str: string): string;
270 getData(jsonPointer: string, dataLevel: number, paths: string[]): string;
271 escapeJsonPointer(str: string): string;
272 unescapeJsonPointer(str: string): string;
273 escapeFragment(str: string): string;
274 unescapeFragment(str: string): string;
279 interface SchemaValidateFunction {
283 parentSchema?: object,
285 parentData?: object | Array<any>,
286 parentDataProperty?: string | number,
287 rootData?: object | Array<any>
288 ): boolean | PromiseLike<any>;
289 errors?: Array<ErrorObject>;
292 interface ErrorsTextOptions {
297 interface ErrorObject {
301 params: ErrorParameters;
302 // Added to validation errors of propertyNames keyword schema
303 propertyName?: string;
304 // Excluded if messages set to false.
306 // These are added with the `verbose` option.
308 parentSchema?: object;
312 type ErrorParameters = RefParams | LimitParams | AdditionalPropertiesParams |
313 DependenciesParams | FormatParams | ComparisonParams |
314 MultipleOfParams | PatternParams | RequiredParams |
315 TypeParams | UniqueItemsParams | CustomParams |
316 PatternRequiredParams | PropertyNamesParams |
317 IfParams | SwitchParams | NoParams | EnumParams;
319 interface RefParams {
323 interface LimitParams {
327 interface AdditionalPropertiesParams {
328 additionalProperty: string;
331 interface DependenciesParams {
333 missingProperty: string;
338 interface FormatParams {
342 interface ComparisonParams {
344 limit: number | string;
348 interface MultipleOfParams {
352 interface PatternParams {
356 interface RequiredParams {
357 missingProperty: string;
360 interface TypeParams {
364 interface UniqueItemsParams {
369 interface CustomParams {
373 interface PatternRequiredParams {
374 missingPattern: string;
377 interface PropertyNamesParams {
378 propertyName: string;
382 failingKeyword: string;
385 interface SwitchParams {
389 interface NoParams { }
391 interface EnumParams {
392 allowedValues: Array<any>;