Skip to content

Commit

Permalink
Add keywords to ajv options
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscomorais committed Feb 13, 2020
1 parent 8d3320d commit 46171d2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/ajv.d.ts
Expand Up @@ -171,6 +171,7 @@ declare namespace ajv {
unicode?: boolean;
format?: false | string;
formats?: object;
keywords?: object;
unknownFormats?: true | string[] | 'ignore';
schemas?: Array<object> | object;
schemaId?: '$id' | 'id' | 'auto';
Expand Down Expand Up @@ -252,6 +253,9 @@ declare namespace ajv {
formats: {
[index: string]: FormatDefinition | undefined;
};
keywords: {
[index: string]: KeywordDefinition | undefined;
};
compositeRule: boolean;
validate: (schema: object) => boolean;
util: {
Expand Down
9 changes: 9 additions & 0 deletions lib/ajv.js
Expand Up @@ -69,6 +69,7 @@ function Ajv(opts) {
this._metaOpts = getMetaSchemaOptions(this);

if (opts.formats) addInitialFormats(this);
if (opts.keywords) addInitialKeywords(this);
addDefaultMetaSchema(this);
if (typeof opts.meta == 'object') this.addMetaSchema(opts.meta);
if (opts.nullable) this.addKeyword('nullable', {metaSchema: {type: 'boolean'}});
Expand Down Expand Up @@ -467,6 +468,14 @@ function addInitialFormats(self) {
}


function addInitialKeywords(self) {
for (var name in self._opts.keywords) {
var keyword = self._opts.keywords[name];
self.addKeyword(name, keyword);
}
}


function checkUnique(self, id) {
if (self._schemas[id] || self._refs[id])
throw new Error('schema with key or id "' + id + '" already exists');
Expand Down

0 comments on commit 46171d2

Please sign in to comment.