MCPcopy
hub / github.com/ajv-validator/ajv / addKeyword

Method addKeyword

lib/core.ts:589–628  ·  view source on GitHub ↗
(
    kwdOrDef: string | KeywordDefinition,
    def?: KeywordDefinition // deprecated
  )

Source from the content-addressed store, hash-verified

587 }
588
589 addKeyword(
590 kwdOrDef: string | KeywordDefinition,
591 def?: KeywordDefinition // deprecated
592 ): Ajv {
593 let keyword: string | string[]
594 if (typeof kwdOrDef == "string") {
595 keyword = kwdOrDef
596 if (typeof def == "object") {
597 this.logger.warn("these parameters are deprecated, see docs for addKeyword")
598 def.keyword = keyword
599 }
600 } else if (typeof kwdOrDef == "object" && def === undefined) {
601 def = kwdOrDef
602 keyword = def.keyword
603 if (Array.isArray(keyword) && !keyword.length) {
604 throw new Error("addKeywords: keyword must be string or non-empty array")
605 }
606 } else {
607 throw new Error("invalid addKeywords parameters")
608 }
609
610 checkKeyword.call(this, keyword, def)
611 if (!def) {
612 eachItem(keyword, (kwd) => addRule.call(this, kwd))
613 return this
614 }
615 keywordMetaschema.call(this, def)
616 const definition: AddedKeywordDefinition = {
617 ...def,
618 type: getJSONTypes(def.type),
619 schemaType: getJSONTypes(def.schemaType),
620 }
621 eachItem(
622 keyword,
623 definition.type.length === 0
624 ? (k) => addRule.call(this, k, definition)
625 : (k) => definition.type.forEach((t) => addRule.call(this, k, definition, t))
626 )
627 return this
628 }
629
630 getKeyword(keyword: string): AddedKeywordDefinition | boolean {
631 const rule = this.RULES.all[keyword]

Callers 15

_addVocabulariesMethod · 0.95
_addVocabulariesMethod · 0.95
addVocabularyMethod · 0.95
_addVocabulariesMethod · 0.45
_addVocabulariesMethod · 0.45
addInitialKeywordsFunction · 0.45
addRuleFunction · 0.45
ajv.spec.tsFile · 0.45
testFunction · 0.45
async.spec.tsFile · 0.45
keyword.spec.tsFile · 0.45

Calls 3

eachItemFunction · 0.90
getJSONTypesFunction · 0.90
warnMethod · 0.80

Tested by 14

testFunction · 0.36
testEvenKeywordFunction · 0.36
testEvenKeyword$dataFunction · 0.36
testConstantKeywordFunction · 0.36
testRangeKeywordFunction · 0.36
testMultipleRangeKeywordFunction · 0.36
_addKeywordFunction · 0.36
testModifyingFunction · 0.36
getValidateFunction · 0.36
getValidateFunction · 0.36