1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const validate_1 = require("../../compile/validate");
|
4 | const code_1 = require("../code");
|
5 | const util_1 = require("../../compile/util");
|
6 | const additionalProperties_1 = require("./additionalProperties");
|
7 | const def = {
|
8 | keyword: "properties",
|
9 | type: "object",
|
10 | schemaType: "object",
|
11 | code(cxt) {
|
12 | const { gen, schema, parentSchema, data, it } = cxt;
|
13 | if (it.opts.removeAdditional === "all" && parentSchema.additionalProperties === undefined) {
|
14 | additionalProperties_1.default.code(new validate_1.KeywordCxt(it, additionalProperties_1.default, "additionalProperties"));
|
15 | }
|
16 | const allProps = (0, code_1.allSchemaProperties)(schema);
|
17 | for (const prop of allProps) {
|
18 | it.definedProperties.add(prop);
|
19 | }
|
20 | if (it.opts.unevaluated && allProps.length && it.props !== true) {
|
21 | it.props = util_1.mergeEvaluated.props(gen, (0, util_1.toHash)(allProps), it.props);
|
22 | }
|
23 | const properties = allProps.filter((p) => !(0, util_1.alwaysValidSchema)(it, schema[p]));
|
24 | if (properties.length === 0)
|
25 | return;
|
26 | const valid = gen.name("valid");
|
27 | for (const prop of properties) {
|
28 | if (hasDefault(prop)) {
|
29 | applyPropertySchema(prop);
|
30 | }
|
31 | else {
|
32 | gen.if((0, code_1.propertyInData)(gen, data, prop, it.opts.ownProperties));
|
33 | applyPropertySchema(prop);
|
34 | if (!it.allErrors)
|
35 | gen.else().var(valid, true);
|
36 | gen.endIf();
|
37 | }
|
38 | cxt.it.definedProperties.add(prop);
|
39 | cxt.ok(valid);
|
40 | }
|
41 | function hasDefault(prop) {
|
42 | return it.opts.useDefaults && !it.compositeRule && schema[prop].default !== undefined;
|
43 | }
|
44 | function applyPropertySchema(prop) {
|
45 | cxt.subschema({
|
46 | keyword: "properties",
|
47 | schemaProp: prop,
|
48 | dataProp: prop,
|
49 | }, valid);
|
50 | }
|
51 | },
|
52 | };
|
53 | exports.default = def;
|
54 |
|
\ | No newline at end of file |