@pdtf/schemas 2.0.0-0 → 2.0.0-2
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 +12 -9
- package/package.json +1 -1
- package/src/examples/v2/exampleTransaction.json +77 -22
- package/src/schemas/v2/combined.json +99 -47
- package/src/schemas/v2/core.json +12 -13
- package/src/schemas/v2/merged.json +28697 -0
- package/src/schemas/v2/overlays/baspi.json +132 -20
- package/src/schemas/v2/overlays/fme1.json +5 -5
- package/src/schemas/v2/overlays/lpe1.json +17 -22
- package/src/schemas/v2/overlays/nts.json +1 -1
- package/src/schemas/v2/overlays/rds.json +3 -2
- package/src/schemas/v2/overlays/ta7.json +4 -3
- package/src/tests/v2/transactionSchema.test.js +15 -24
- package/src/utils/extractOverlay.js +28 -0
|
@@ -59,46 +59,37 @@ test("sample with missing dependent required fields is invalid", () => {
|
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
test("correctly gets a top level subschema", () => {
|
|
62
|
-
const subschema = getSubschema("/propertyPack"
|
|
62
|
+
const subschema = getSubschema("/propertyPack");
|
|
63
63
|
expect(subschema.title).toBe("Property Pack");
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
test("correctly identifies a valid path", () => {
|
|
67
|
-
const isValid = isPathValid(
|
|
68
|
-
"/propertyPack/materialFacts",
|
|
69
|
-
v2TransactionSchema
|
|
70
|
-
);
|
|
67
|
+
const isValid = isPathValid("/propertyPack/materialFacts");
|
|
71
68
|
expect(isValid).toBe(true);
|
|
72
69
|
});
|
|
73
70
|
|
|
74
71
|
test("correctly identifies an undefined invalid path", () => {
|
|
75
|
-
const isValid = isPathValid(
|
|
76
|
-
"/propertyPack/materialItems",
|
|
77
|
-
v2TransactionSchema
|
|
78
|
-
);
|
|
72
|
+
const isValid = isPathValid("/propertyPack/materialItems");
|
|
79
73
|
expect(isValid).toBe(false);
|
|
80
74
|
});
|
|
81
75
|
|
|
82
76
|
test("correctly identifies an error generating invalid path", () => {
|
|
83
77
|
const isValid = isPathValid(
|
|
84
78
|
"/propertyPack/materialItems/someProperty/item",
|
|
85
|
-
|
|
79
|
+
schemaId
|
|
86
80
|
);
|
|
87
81
|
expect(isValid).toBe(false);
|
|
88
82
|
});
|
|
89
83
|
|
|
90
84
|
test("correctly identifies an array invalid path", () => {
|
|
91
|
-
const isValid = isPathValid(
|
|
92
|
-
"/propertyPack/materialFacts/1/item",
|
|
93
|
-
v2TransactionSchema
|
|
94
|
-
);
|
|
85
|
+
const isValid = isPathValid("/propertyPack/materialFacts/1/item");
|
|
95
86
|
expect(isValid).toBe(false);
|
|
96
87
|
});
|
|
97
88
|
|
|
98
89
|
test("correctly gets a subschema", () => {
|
|
99
90
|
const subschema = getSubschema(
|
|
100
91
|
"/propertyPack/materialFacts/notices",
|
|
101
|
-
|
|
92
|
+
schemaId
|
|
102
93
|
);
|
|
103
94
|
expect(subschema.title).toBe("Notices which Affect the Property");
|
|
104
95
|
});
|
|
@@ -106,7 +97,7 @@ test("correctly gets a subschema", () => {
|
|
|
106
97
|
test("correctly gets a subschema through an arrays element", () => {
|
|
107
98
|
const subschema = getSubschema(
|
|
108
99
|
"/propertyPack/titlesToBeSold/0/registerExtract",
|
|
109
|
-
|
|
100
|
+
schemaId
|
|
110
101
|
);
|
|
111
102
|
expect(Object.keys(subschema.properties)).toEqual([
|
|
112
103
|
"OCSummaryData",
|
|
@@ -117,7 +108,7 @@ test("correctly gets a subschema through an arrays element", () => {
|
|
|
117
108
|
test("correctly gets a subschema through a dependency", () => {
|
|
118
109
|
const subschema = getSubschema(
|
|
119
110
|
"/propertyPack/materialFacts/delayFactors/hasDelayFactors/details",
|
|
120
|
-
|
|
111
|
+
schemaId
|
|
121
112
|
);
|
|
122
113
|
expect(subschema.title).toBe("Details");
|
|
123
114
|
});
|
|
@@ -125,16 +116,16 @@ test("correctly gets a subschema through a dependency", () => {
|
|
|
125
116
|
test("correctly gets another subschema through a dependency", () => {
|
|
126
117
|
const subschema = getSubschema(
|
|
127
118
|
"/propertyPack/materialFacts/ownership/ownershipsToBeTransferred/0/leaseholdInformation/general/leaseTerm/lengthOfLeaseInYears",
|
|
128
|
-
|
|
119
|
+
schemaId
|
|
129
120
|
);
|
|
130
121
|
expect(subschema.title).toBe("Length of lease (years)");
|
|
131
122
|
});
|
|
132
123
|
|
|
133
124
|
test("correctly gets yet another subschema through a dependency", () => {
|
|
134
125
|
const subschema = getSubschema(
|
|
135
|
-
"/propertyPack/materialFacts/ownership/ownershipsToBeTransferred/0/
|
|
126
|
+
"/propertyPack/materialFacts/ownership/ownershipsToBeTransferred/0/leaseholdInformation/groundRent/rentSubjectToIncrease/rentIncreaseCalculated"
|
|
136
127
|
);
|
|
137
|
-
expect(subschema.title).toBe("
|
|
128
|
+
expect(subschema.title).toBe("How is the increase calculated?");
|
|
138
129
|
});
|
|
139
130
|
|
|
140
131
|
test("correctly gets yet, yet another subschema through a dependency", () => {
|
|
@@ -147,7 +138,7 @@ test("correctly gets yet, yet another subschema through a dependency", () => {
|
|
|
147
138
|
|
|
148
139
|
test("correctly gets yet, yet, yet another subschema through a dependency", () => {
|
|
149
140
|
const subschema = getSubschema(
|
|
150
|
-
"/propertyPack/materialFacts/
|
|
141
|
+
"/propertyPack/materialFacts/environmentalIssues/flooding/typeOfFlooding/groundWater/yesNo"
|
|
151
142
|
);
|
|
152
143
|
expect(subschema.type).toBe("string");
|
|
153
144
|
expect(subschema.enum).toStrictEqual(["Yes", "No"]);
|
|
@@ -155,7 +146,7 @@ test("correctly gets yet, yet, yet another subschema through a dependency", () =
|
|
|
155
146
|
|
|
156
147
|
test("correctly gets yet, yet, yet another subschema through a second item dependency", () => {
|
|
157
148
|
const subschema = getSubschema(
|
|
158
|
-
"/propertyPack/materialFacts/
|
|
149
|
+
"/propertyPack/materialFacts/environmentalIssues/flooding/typeOfFlooding"
|
|
159
150
|
);
|
|
160
151
|
expect(subschema.type).toBe("object");
|
|
161
152
|
});
|
|
@@ -176,11 +167,11 @@ test("correctly gets yes another subschema but through a non-baspi oneOf structu
|
|
|
176
167
|
|
|
177
168
|
test("correctly gets a subschema validator which is already cached", () => {
|
|
178
169
|
const validator = getSubschemaValidator(
|
|
179
|
-
"/propertyPack/
|
|
170
|
+
"/propertyPack/materialFacts/energyEfficiency/certificate"
|
|
180
171
|
);
|
|
181
172
|
expect(validator).not.toBeNull();
|
|
182
173
|
const anotherValidator = getSubschemaValidator(
|
|
183
|
-
"/propertyPack/
|
|
174
|
+
"/propertyPack/materialFacts/energyEfficiency/certificate"
|
|
184
175
|
);
|
|
185
176
|
expect(anotherValidator).not.toBeNull();
|
|
186
177
|
});
|
|
@@ -26,8 +26,23 @@ const overlayIncludeProperties = [
|
|
|
26
26
|
"description",
|
|
27
27
|
"enum",
|
|
28
28
|
"discriminator",
|
|
29
|
+
"minItems",
|
|
29
30
|
];
|
|
30
31
|
|
|
32
|
+
const combineMerge = (target, source, options) => {
|
|
33
|
+
const destination = target.slice();
|
|
34
|
+
source.forEach((item, index) => {
|
|
35
|
+
if (typeof destination[index] === "undefined") {
|
|
36
|
+
destination[index] = options.cloneUnlessOtherwiseSpecified(item, options);
|
|
37
|
+
} else if (options.isMergeableObject(item)) {
|
|
38
|
+
destination[index] = merge(target[index], item, options);
|
|
39
|
+
} else if (target.indexOf(item) === -1) {
|
|
40
|
+
destination.push(item);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return destination;
|
|
44
|
+
};
|
|
45
|
+
|
|
31
46
|
const extractOverlay = (sourceSchema, ref) => {
|
|
32
47
|
const refName = `${ref}Ref`;
|
|
33
48
|
const refRequired = `${ref}Required`;
|
|
@@ -75,6 +90,8 @@ const deleteProperties = (sourceSchema, propertyNames) => {
|
|
|
75
90
|
return sourceSchema;
|
|
76
91
|
};
|
|
77
92
|
|
|
93
|
+
const overlays = {};
|
|
94
|
+
|
|
78
95
|
extractFields.forEach((key) => {
|
|
79
96
|
let overlay = extractOverlay(combinedSchema, key, [
|
|
80
97
|
"title",
|
|
@@ -82,6 +99,7 @@ extractFields.forEach((key) => {
|
|
|
82
99
|
"enum",
|
|
83
100
|
"discriminator",
|
|
84
101
|
]);
|
|
102
|
+
overlays[key] = overlay;
|
|
85
103
|
const fileName = `../schemas/v2/overlays/${key}.json`;
|
|
86
104
|
fs.writeFileSync(fileName, JSON.stringify(overlay, null, 2));
|
|
87
105
|
console.log(`Overlay ${key} written to ${fileName}`);
|
|
@@ -98,3 +116,13 @@ fs.writeFileSync(
|
|
|
98
116
|
JSON.stringify(coreSchema, null, 2)
|
|
99
117
|
);
|
|
100
118
|
console.log("Core schema written to ../schemas/v2/core.json");
|
|
119
|
+
console.log(overlays.baspi);
|
|
120
|
+
const mergedSchema = merge(overlays.baspi, coreSchema, {
|
|
121
|
+
arrayMerge: combineMerge,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
fs.writeFileSync(
|
|
125
|
+
"../schemas/v2/merged.json",
|
|
126
|
+
JSON.stringify(mergedSchema, null, 2)
|
|
127
|
+
);
|
|
128
|
+
console.log("Merged schema written to ../schemas/v2/merged.json");
|