@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
- if (schema.type === "array") return schema.items;
52
- if (schema.properties[pathElement]) return schema.properties[pathElement];
53
- const discriminator = schema.discriminator?.propertyName;
54
- if (discriminator) {
55
- // only single dependency discriminator, oneOf keyword is supported
56
- const oneOfs = schema.oneOf;
57
- const matchingOneOf = oneOfs.find(
58
- (oneOf) => oneOf["properties"][pathElement]
59
- );
60
- if (matchingOneOf) return matchingOneOf["properties"][pathElement];
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdtf/schemas",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Property Data Trust Framework Schemas and Utilities",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -19,6 +19,9 @@
19
19
  "title": "UUID for the transaction",
20
20
  "type": "string"
21
21
  },
22
+ "externalIds": {
23
+ "type": "object"
24
+ },
22
25
  "status": {
23
26
  "type": "string",
24
27
  "enum": ["active", "cancelled", "completed"]
@@ -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"