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

Function testModifying

spec/keyword.spec.ts:1286–1329  ·  view source on GitHub ↗
(withOption)

Source from the content-addressed store, hash-verified

1284 })
1285
1286 function testModifying(withOption) {
1287 const collectionFormat = {
1288 csv: function (data, {parentData, parentDataProperty}) {
1289 parentData[parentDataProperty] = data.split(",")
1290 return true
1291 },
1292 }
1293
1294 ajv.addKeyword({
1295 keyword: "collectionFormat",
1296 type: "string",
1297 modifying: withOption,
1298 compile: function (schema) {
1299 return collectionFormat[schema]
1300 },
1301 metaSchema: {
1302 enum: ["csv"],
1303 },
1304 })
1305
1306 const validate = ajv.compile({
1307 type: "object",
1308 properties: {
1309 foo: {
1310 allOf: [
1311 {
1312 type: "string",
1313 collectionFormat: "csv",
1314 },
1315 {
1316 type: "array",
1317 items: {type: "string"},
1318 },
1319 ],
1320 },
1321 },
1322 additionalProperties: false,
1323 })
1324
1325 const obj: any = {foo: "bar,baz,quux"}
1326
1327 validate(obj).should.equal(true)
1328 obj.should.eql({foo: ["bar", "baz", "quux"]})
1329 }
1330 })
1331
1332 describe('"validate" keywords with predefined validation result', () => {

Callers 1

keyword.spec.tsFile · 0.85

Calls 3

validateFunction · 0.85
addKeywordMethod · 0.45
compileMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…