@pdtf/schemas 0.5.13 → 0.5.14
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
CHANGED
|
@@ -18,7 +18,7 @@ const subSchemas = {
|
|
|
18
18
|
"https://homebuyingandsellinggroup.co.uk/schemas/energy-performance-certificate.json":
|
|
19
19
|
energyPerformanceCertificate,
|
|
20
20
|
"https://geojson.org/schema/GeoJSON.json": geoJson,
|
|
21
|
-
"https://homebuyingandsellinggroup.co.uk/schemas/title-deed.json": titleDeed
|
|
21
|
+
"https://homebuyingandsellinggroup.co.uk/schemas/title-deed.json": titleDeed,
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
const propertyPackSchema = dereference(propertyPack, (id) => subSchemas[id]);
|
|
@@ -26,7 +26,7 @@ const propertyPackSchema = dereference(propertyPack, (id) => subSchemas[id]);
|
|
|
26
26
|
const ajv = new Ajv({
|
|
27
27
|
allErrors: true,
|
|
28
28
|
// schema contains additional baspiRef and RDSRef metadata which is not strictly valid
|
|
29
|
-
strictSchema: false
|
|
29
|
+
strictSchema: false,
|
|
30
30
|
});
|
|
31
31
|
// Adds date formats among other types to the validator.
|
|
32
32
|
addFormats(ajv);
|
|
@@ -36,7 +36,7 @@ const validator = ajv.compile(propertyPackSchema);
|
|
|
36
36
|
const getSubschema = (path) => {
|
|
37
37
|
const pathArray = path.split("/").slice(1);
|
|
38
38
|
if (pathArray.length < 1) {
|
|
39
|
-
return
|
|
39
|
+
return propertyPackSchema;
|
|
40
40
|
}
|
|
41
41
|
return pathArray.reduce((propertyPackSchema, pathElement) => {
|
|
42
42
|
return propertyPackSchema.properties[pathElement];
|
|
@@ -44,7 +44,14 @@ const getSubschema = (path) => {
|
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
const getSubschemaValidator = (path) => {
|
|
47
|
-
|
|
47
|
+
const subSchema = getSubschema(path);
|
|
48
|
+
let validator = ajv.getSchema(path);
|
|
49
|
+
if (!validator && subSchema.$id) validator = ajv.getSchema(subSchema.$id);
|
|
50
|
+
if (!validator) {
|
|
51
|
+
ajv.addSchema(subSchema, path);
|
|
52
|
+
validator = ajv.getSchema(path);
|
|
53
|
+
}
|
|
54
|
+
return validator;
|
|
48
55
|
};
|
|
49
56
|
|
|
50
57
|
const getTitleAtPath = (schema, path, rootPath = path) => {
|
|
@@ -97,5 +104,5 @@ module.exports = {
|
|
|
97
104
|
getSubschema,
|
|
98
105
|
getSubschemaValidator,
|
|
99
106
|
getTitleAtPath,
|
|
100
|
-
verifiedClaimsSchema
|
|
107
|
+
verifiedClaimsSchema,
|
|
101
108
|
};
|
package/package.json
CHANGED
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
"source": {
|
|
10
10
|
"name": "Royal Mail Postcode Address File record via ideal-postcodes.co.uk"
|
|
11
11
|
},
|
|
12
|
-
"type": "
|
|
12
|
+
"type": "postcode_address_file"
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
]
|
|
16
16
|
},
|
|
17
17
|
"claims": {
|
|
18
|
-
"/propertyPack/materialFacts/
|
|
18
|
+
"/propertyPack/materialFacts/address": {
|
|
19
19
|
"address1": "3 The Hollys",
|
|
20
20
|
"address2": "Birtley",
|
|
21
21
|
"town": "CHESTER LE STREET",
|
|
@@ -25,9 +25,7 @@
|
|
|
25
25
|
"energyEfficiencyRating": "A"
|
|
26
26
|
},
|
|
27
27
|
"delayFactors": {
|
|
28
|
-
"hasDelayFactors": {
|
|
29
|
-
"yesNo": "No"
|
|
30
|
-
}
|
|
28
|
+
"hasDelayFactors": { "yesNo": "No" }
|
|
31
29
|
},
|
|
32
30
|
"ownership": {
|
|
33
31
|
"ownershipType": "Freehold"
|
|
@@ -371,6 +369,9 @@
|
|
|
371
369
|
"consumerProtectionRegulationsDeclaration": {
|
|
372
370
|
"consumerProtectionRegulationsResponse": true
|
|
373
371
|
}
|
|
372
|
+
},
|
|
373
|
+
"energyPerformanceCertificate": {
|
|
374
|
+
"certificate": { "currentEnergyRating": "B" }
|
|
374
375
|
}
|
|
375
376
|
}
|
|
376
377
|
}
|
|
@@ -4,10 +4,13 @@
|
|
|
4
4
|
"type": "object",
|
|
5
5
|
"title": "Energy Performance Certificate and Recommendations Schema, supporting data retrieved from https://epc.opendatacommunities.org ",
|
|
6
6
|
"description": "Mirrors the Domestic EPC Glossary at https://epc.opendatacommunities.org/docs/guidance#glossary",
|
|
7
|
+
"required": ["certificate"],
|
|
7
8
|
"properties": {
|
|
8
9
|
"certificate": {
|
|
9
10
|
"type": "object",
|
|
11
|
+
"required": ["currentEnergyRating"],
|
|
10
12
|
"properties": {
|
|
13
|
+
"certificateNumber": { "type": "string" },
|
|
11
14
|
"address": { "type": "string" },
|
|
12
15
|
"address1": { "type": "string" },
|
|
13
16
|
"address2": { "type": "string" },
|
|
@@ -5,7 +5,7 @@ const {
|
|
|
5
5
|
validator,
|
|
6
6
|
getSubschema,
|
|
7
7
|
getSubschemaValidator,
|
|
8
|
-
getTitleAtPath
|
|
8
|
+
getTitleAtPath,
|
|
9
9
|
} = require("../../index.js");
|
|
10
10
|
const examplePropertyPack = require("../examples/examplePropertyPack.json");
|
|
11
11
|
|
|
@@ -37,11 +37,27 @@ test("sample with missing dependent required fields is invalid", () => {
|
|
|
37
37
|
expect(isValid).toBe(false);
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
+
test("correctly gets a top level subschema", () => {
|
|
41
|
+
const subschema = getSubschema("/propertyPack");
|
|
42
|
+
expect(subschema.title).toBe("Property Pack");
|
|
43
|
+
});
|
|
44
|
+
|
|
40
45
|
test("correctly gets a subschema", () => {
|
|
41
46
|
const subschema = getSubschema("/propertyPack/materialFacts/notices");
|
|
42
47
|
expect(subschema.title).toBe("Notices which Affect the Property");
|
|
43
48
|
});
|
|
44
49
|
|
|
50
|
+
test("correctly gets a subschema validator which is already cached", () => {
|
|
51
|
+
const validator = getSubschemaValidator(
|
|
52
|
+
"/propertyPack/energyPerformanceCertificate"
|
|
53
|
+
);
|
|
54
|
+
expect(validator).not.toBeNull();
|
|
55
|
+
const anotherValidator = getSubschemaValidator(
|
|
56
|
+
"/propertyPack/energyPerformanceCertificate"
|
|
57
|
+
);
|
|
58
|
+
expect(anotherValidator).not.toBeNull();
|
|
59
|
+
});
|
|
60
|
+
|
|
45
61
|
test("correctly gets a working subschema validator", () => {
|
|
46
62
|
const path = "/propertyPack/materialFacts/notices";
|
|
47
63
|
const validator = getSubschemaValidator(path);
|