@pdtf/schemas 1.1.1 → 1.1.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
CHANGED
|
@@ -48,16 +48,19 @@ const getSubschema = (path) => {
|
|
|
48
48
|
const pathArray = path.split("/").slice(1);
|
|
49
49
|
if (pathArray.length < 1) return transactionSchema;
|
|
50
50
|
return pathArray.reduce((schema, pathElement) => {
|
|
51
|
-
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
51
|
+
const { type, items, properties, oneOf } = schema;
|
|
52
|
+
if (type === "array") return items;
|
|
53
|
+
if (properties?.[pathElement]) return properties[pathElement];
|
|
54
|
+
if (oneOf) {
|
|
55
|
+
let matchingProperty;
|
|
56
|
+
oneOf.forEach((aOneOf) => {
|
|
57
|
+
if (aOneOf.type === "array" && !Number.isNaN(pathElement)) {
|
|
58
|
+
matchingProperty = aOneOf.items;
|
|
59
|
+
} else if (aOneOf.properties?.[pathElement]) {
|
|
60
|
+
matchingProperty = aOneOf.properties?.[pathElement];
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
if (matchingProperty) return matchingProperty;
|
|
61
64
|
}
|
|
62
65
|
return undefined;
|
|
63
66
|
}, transactionSchema);
|
package/package.json
CHANGED
|
@@ -118,6 +118,27 @@ test("correctly gets yet, yet, yet another subschema through a dependency", () =
|
|
|
118
118
|
expect(subschema.enum).toStrictEqual(["Yes", "No"]);
|
|
119
119
|
});
|
|
120
120
|
|
|
121
|
+
test("correctly gets yet, yet, yet another subschema through a second item dependency", () => {
|
|
122
|
+
const subschema = getSubschema(
|
|
123
|
+
"/propertyPack/materialFacts/otherIssues/flooding/typeOfFlooding"
|
|
124
|
+
);
|
|
125
|
+
expect(subschema.type).toBe("object");
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("correctly gets yes another subschema but through a non-baspi oneOf structure", () => {
|
|
129
|
+
const subschema = getSubschema(
|
|
130
|
+
"/propertyPack/titlesToBeSold/0/registerExtract/OCSummaryData/RestrictionDetails/RestrictionEntry/ChargeRestriction/EntryDetails/EntryText"
|
|
131
|
+
);
|
|
132
|
+
expect(subschema).toEqual({ type: "string" });
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("correctly gets yes another subschema but through a non-baspi oneOf structure with array option", () => {
|
|
136
|
+
const subschema = getSubschema(
|
|
137
|
+
"/propertyPack/titlesToBeSold/0/registerExtract/OCSummaryData/RestrictionDetails/RestrictionEntry/0/ChargeRestriction/EntryDetails/EntryText"
|
|
138
|
+
);
|
|
139
|
+
expect(subschema).toEqual({ type: "string" });
|
|
140
|
+
});
|
|
141
|
+
|
|
121
142
|
test("correctly gets a subschema validator which is already cached", () => {
|
|
122
143
|
const validator = getSubschemaValidator(
|
|
123
144
|
"/propertyPack/energyPerformanceCertificate"
|