@pdtf/schemas 0.5.7 → 0.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +45 -1
- package/package.json +1 -1
- package/src/schemas/baspi-a-material-facts.json +491 -435
- package/src/schemas/baspi-b-legal-information.json +734 -599
- package/src/schemas/energy-performance-certificate.json +95 -92
- package/src/schemas/pdtf-claim.json +1 -1
- package/src/schemas/property-pack.json +94 -1
- package/src/schemas/title-deed.json +10 -5
- package/src/tests/examplePropertyPack.json +47 -38
- package/src/tests/propertyPackSchema.test.js +66 -1
package/index.js
CHANGED
|
@@ -39,7 +39,7 @@ const getSubschema = (path) => {
|
|
|
39
39
|
return schema;
|
|
40
40
|
}
|
|
41
41
|
return pathArray.reduce((propertyPackSchema, pathElement) => {
|
|
42
|
-
return propertyPackSchema
|
|
42
|
+
return propertyPackSchema.properties[pathElement];
|
|
43
43
|
}, propertyPackSchema);
|
|
44
44
|
};
|
|
45
45
|
|
|
@@ -47,11 +47,55 @@ const getSubschemaValidator = (path) => {
|
|
|
47
47
|
return ajv.getSchema(path) || ajv.compile(getSubschema(path));
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
+
const getTitleAtPath = (schema, path, rootPath = path) => {
|
|
51
|
+
if (path === "") path = "/";
|
|
52
|
+
let pathArray = path.split("/").slice(1);
|
|
53
|
+
if (pathArray.length === 1 && pathArray[0] === "") {
|
|
54
|
+
if (schema.title) return schema.title;
|
|
55
|
+
// no 'title' property present, so we use the property name to create a readable descriptor
|
|
56
|
+
const propertyName = rootPath
|
|
57
|
+
.split("/")
|
|
58
|
+
.pop()
|
|
59
|
+
.replace(/([A-Z])/g, " $1")
|
|
60
|
+
.toLowerCase()
|
|
61
|
+
.trim();
|
|
62
|
+
return propertyName.charAt(0).toUpperCase() + propertyName.slice(1);
|
|
63
|
+
}
|
|
64
|
+
const propertyName = pathArray.shift();
|
|
65
|
+
const subPath = "/" + pathArray.join("/");
|
|
66
|
+
let subSchema = schema.properties
|
|
67
|
+
? schema.properties[propertyName]
|
|
68
|
+
: undefined;
|
|
69
|
+
if (subSchema) {
|
|
70
|
+
return getTitleAtPath(subSchema, subPath, rootPath);
|
|
71
|
+
}
|
|
72
|
+
if (schema.type === "array") {
|
|
73
|
+
subSchema = schema.items;
|
|
74
|
+
return getTitleAtPath(subSchema, subPath, rootPath);
|
|
75
|
+
}
|
|
76
|
+
const dependencies = schema.dependencies;
|
|
77
|
+
if (dependencies) {
|
|
78
|
+
// only single dependency discriminator, oneOf keyword is supported
|
|
79
|
+
const dependencyDiscriminator = Object.keys(dependencies)[0];
|
|
80
|
+
const oneOfs = dependencies[dependencyDiscriminator].oneOf;
|
|
81
|
+
const matchingOneOf = oneOfs.find(
|
|
82
|
+
(oneOf) => oneOf["properties"][propertyName]
|
|
83
|
+
);
|
|
84
|
+
if (matchingOneOf)
|
|
85
|
+
return getTitleAtPath(
|
|
86
|
+
matchingOneOf["properties"][propertyName],
|
|
87
|
+
subPath,
|
|
88
|
+
rootPath
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
50
93
|
module.exports = {
|
|
51
94
|
propertyPackSchema,
|
|
52
95
|
validator,
|
|
53
96
|
getSubschema,
|
|
54
97
|
getSubschemaValidator,
|
|
98
|
+
getTitleAtPath,
|
|
55
99
|
pdtfClaim,
|
|
56
100
|
verifiedClaim
|
|
57
101
|
};
|