source: trip-planner-front/node_modules/ajv/dist/vocabularies/applicator/oneOf.js@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.2 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const codegen_1 = require("../../compile/codegen");
4const util_1 = require("../../compile/util");
5const error = {
6 message: "must match exactly one schema in oneOf",
7 params: ({ params }) => codegen_1._ `{passingSchemas: ${params.passing}}`,
8};
9const def = {
10 keyword: "oneOf",
11 schemaType: "array",
12 trackErrors: true,
13 error,
14 code(cxt) {
15 const { gen, schema, parentSchema, it } = cxt;
16 /* istanbul ignore if */
17 if (!Array.isArray(schema))
18 throw new Error("ajv implementation error");
19 if (it.opts.discriminator && parentSchema.discriminator)
20 return;
21 const schArr = schema;
22 const valid = gen.let("valid", false);
23 const passing = gen.let("passing", null);
24 const schValid = gen.name("_valid");
25 cxt.setParams({ passing });
26 // TODO possibly fail straight away (with warning or exception) if there are two empty always valid schemas
27 gen.block(validateOneOf);
28 cxt.result(valid, () => cxt.reset(), () => cxt.error(true));
29 function validateOneOf() {
30 schArr.forEach((sch, i) => {
31 let schCxt;
32 if (util_1.alwaysValidSchema(it, sch)) {
33 gen.var(schValid, true);
34 }
35 else {
36 schCxt = cxt.subschema({
37 keyword: "oneOf",
38 schemaProp: i,
39 compositeRule: true,
40 }, schValid);
41 }
42 if (i > 0) {
43 gen
44 .if(codegen_1._ `${schValid} && ${valid}`)
45 .assign(valid, false)
46 .assign(passing, codegen_1._ `[${passing}, ${i}]`)
47 .else();
48 }
49 gen.if(schValid, () => {
50 gen.assign(valid, true);
51 gen.assign(passing, i);
52 if (schCxt)
53 cxt.mergeEvaluated(schCxt, codegen_1.Name);
54 });
55 });
56 }
57 },
58};
59exports.default = def;
60//# sourceMappingURL=oneOf.js.map
Note: See TracBrowser for help on using the repository browser.