source: imaps-frontend/node_modules/ajv-keywords/dist/definitions/deepProperties.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.7 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const _util_1 = require("./_util");
4function getDef(opts) {
5 return {
6 keyword: "deepProperties",
7 type: "object",
8 schemaType: "object",
9 macro: function (schema) {
10 const allOf = [];
11 for (const pointer in schema)
12 allOf.push(getSchema(pointer, schema[pointer]));
13 return { allOf };
14 },
15 metaSchema: {
16 type: "object",
17 propertyNames: { type: "string", format: "json-pointer" },
18 additionalProperties: (0, _util_1.metaSchemaRef)(opts),
19 },
20 };
21}
22exports.default = getDef;
23function getSchema(jsonPointer, schema) {
24 const segments = jsonPointer.split("/");
25 const rootSchema = {};
26 let pointerSchema = rootSchema;
27 for (let i = 1; i < segments.length; i++) {
28 let segment = segments[i];
29 const isLast = i === segments.length - 1;
30 segment = unescapeJsonPointer(segment);
31 const properties = (pointerSchema.properties = {});
32 let items;
33 if (/[0-9]+/.test(segment)) {
34 let count = +segment;
35 items = pointerSchema.items = [];
36 pointerSchema.type = ["object", "array"];
37 while (count--)
38 items.push({});
39 }
40 else {
41 pointerSchema.type = "object";
42 }
43 pointerSchema = isLast ? schema : {};
44 properties[segment] = pointerSchema;
45 if (items)
46 items.push(pointerSchema);
47 }
48 return rootSchema;
49}
50function unescapeJsonPointer(str) {
51 return str.replace(/~1/g, "/").replace(/~0/g, "~");
52}
53module.exports = getDef;
54//# sourceMappingURL=deepProperties.js.map
Note: See TracBrowser for help on using the repository browser.