Skip to content

Commit dfa640a

Browse files
committed
readme, fixed addMetaSchema
1 parent 22d4c6e commit dfa640a

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ if (!valid) console.log(ajv.errorsText());
7070

7171
ajv compiles schemas to functions and caches them in all cases (using stringified schema as a key - using [json-stable-stringify](https://github.com/substack/json-stable-stringify)), so that the next time the same schema is used (not necessarily the same object instance) it won't be compiled again.
7272

73-
The best performance is achieved when using compiled functions (there is no additional function call).
73+
The best performance is achieved when using compiled functions returned by `compile` or `getSchema` methods (there is no additional function call).
7474

7575

7676
## Using in browser
@@ -104,7 +104,7 @@ The following formats are supported for string validation with "format" keyword:
104104
- _ipv6_: IP address v6.
105105
- _regex_: tests whether a string is a valid regular expression by passing it to RegExp constructor.
106106

107-
There are two modes of fomat validation: `fast` and `full` that affect all formats but `ipv4` and `ipv6`. See [Options](#options) for details.
107+
There are two modes of format validation: `fast` and `full` that affect all formats but `ipv4` and `ipv6`. See [Options](#options) for details.
108108

109109
You can add additional formats and replace any of the formats above using [addFormat](#api-addformat) method.
110110

@@ -224,12 +224,12 @@ Options can have properties `separator` (string used to separate errors, ", " by
224224
- _formats_: an object with custom formats. Keys and values will be passed to `addFormat` method.
225225
- _schemas_: an array or object of schemas that will be added to the instance. If the order is important, pass array. In this case schemas must have IDs in them. Otherwise the object can be passed - `addSchema(value, key)` will be called for each schema in this object.
226226
- _meta_: add [meta-schema](http://json-schema.org/documentation.html) so it can be used by other schemas (true by default).
227-
- _validateSchema_: validate added/compiled schemas against meta-schema (true by default). `$schema` property in the schema can either be absent (draft-4 meta-schema will be used) or can be a reference to any previously added schema. If the validation fails, the exception is thrown. Pass "log" in this option to log error instead of throwing exception. Pass `false` to skip schema validation.
227+
- _validateSchema_: validate added/compiled schemas against meta-schema (true by default). `$schema` property in the schema can either be http://json-schema.org/draft-04/schema or absent (draft-4 meta-schema will be used) or can be a reference to the schema previously added with `addMetaSchema` method. If the validation fails, the exception is thrown. Pass "log" in this option to log error instead of throwing exception. Pass `false` to skip schema validation.
228228
- _missingRefs_: by default if the reference cannot be resolved during compilation the exception is thrown. Pass 'ignore' to log error during compilation and pass validation. Pass 'fail' to log error and successfully compile schema but fail validation if this rule is checked.
229229
- _uniqueItems_: validate `uniqueItems` keyword (true by default).
230230
- _unicode_: calculate correct length of strings with unicode pairs (true by default). Pass `false` to use `.length` of strings that is faster, but gives "incorrect" lengths of strings with unicode pairs - each unicode pair is counted as two characters.
231231
- _beautify_: format the generated function with [js-beautify](https://github.com/beautify-web/js-beautify) (the validating function is generated without line-breaks). `npm install js-beautify` to use this option. `true` or js-beautify options can be passed.
232-
- _cache_: an optional instance of cache to store compiled schemas using stable-stringified schema as a key. For example, set-associative cache [sacjs](https://github.com/epoberezkin/sacjs) can be used. If not passed then a simple hash is used which is good enough for the common use case (a limited number of statically defined schemas). Cache should have methods `put(key, value)` and `get(key)`.
232+
- _cache_: an optional instance of cache to store compiled schemas using stable-stringified schema as a key. For example, set-associative cache [sacjs](https://github.com/epoberezkin/sacjs) can be used. If not passed then a simple hash is used which is good enough for the common use case (a limited number of statically defined schemas). Cache should have methods `put(key, value)`, `get(key)` and `del(key)`.
233233

234234

235235
## Tests
@@ -263,9 +263,11 @@ All validation functions are generated using doT templates in [dot](https://gith
263263

264264
##### 0.7.0
265265

266-
`addShema` no longer returns compiled schema(s)
266+
`addShema` no longer returns compiled schema(s).
267267

268-
Improved / fixed compiling of recursive schemas
268+
Improved / fixed compilation of recursive schemas.
269+
270+
If cache instance is supplied it must have `put`, `get` and `del` methods.
269271

270272

271273
##### 0.6.11

lib/ajv.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function Ajv(opts) {
3636
this.validate = validate;
3737
this.compile = compile;
3838
this.addSchema = addSchema;
39+
this.addMetaSchema = addMetaSchema;
3940
this.validateSchema = validateSchema;
4041
this.getSchema = getSchema;
4142
this.removeSchema = removeSchema;

0 commit comments

Comments
 (0)