@pdtf/schemas 0.6.7 → 0.6.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 CHANGED
@@ -41,7 +41,18 @@ const getSubschema = (path) => {
41
41
  }
42
42
  return pathArray.reduce((schema, pathElement) => {
43
43
  if (schema.type === "array") return schema.items;
44
- return schema.properties[pathElement];
44
+ if (schema.properties[pathElement]) return schema.properties[pathElement];
45
+ const dependencies = schema.dependencies;
46
+ if (dependencies) {
47
+ // only single dependency discriminator, oneOf keyword is supported
48
+ const dependencyDiscriminator = Object.keys(dependencies)[0];
49
+ const oneOfs = dependencies[dependencyDiscriminator].oneOf;
50
+ const matchingOneOf = oneOfs.find(
51
+ (oneOf) => oneOf["properties"][pathElement]
52
+ );
53
+ if (matchingOneOf) return matchingOneOf["properties"][pathElement];
54
+ }
55
+ return undefined;
45
56
  }, transactionSchema);
46
57
  };
47
58
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdtf/schemas",
3
- "version": "0.6.7",
3
+ "version": "0.6.10",
4
4
  "description": "Property Data Trust Framework Schemas and Utilities",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -81,6 +81,35 @@ test("correctly gets another subschema through an arrays element", () => {
81
81
  expect(subschema.title).toBe("First name");
82
82
  });
83
83
 
84
+ test("correctly gets a subschema through a dependency", () => {
85
+ const subschema = getSubschema(
86
+ "/propertyPack/materialFacts/delayFactors/hasDelayFactors/details"
87
+ );
88
+ expect(subschema.title).toBe("Details");
89
+ });
90
+
91
+ test("correctly gets another subschema through a dependency", () => {
92
+ const subschema = getSubschema(
93
+ "/propertyPack/materialFacts/ownership/leaseholdDetails/lengthOfLeaseInYears"
94
+ );
95
+ expect(subschema.title).toBe("Length of lease (years)");
96
+ });
97
+
98
+ test("correctly gets yet another subschema through a dependency", () => {
99
+ const subschema = getSubschema(
100
+ "/propertyPack/materialFacts/ownership/leaseholdDetails/rentIncrease/details"
101
+ );
102
+ expect(subschema.title).toBe("Details");
103
+ });
104
+
105
+ test("correctly gets yet, yet another subschema through a dependency", () => {
106
+ const subschema = getSubschema(
107
+ "/propertyPack/materialFacts/listingAndConservation/isConservationArea/yesNo"
108
+ );
109
+ expect(subschema.type).toBe("string");
110
+ expect(subschema.enum).toStrictEqual(["Yes", "No"]);
111
+ });
112
+
84
113
  test("correctly gets a subschema validator which is already cached", () => {
85
114
  const validator = getSubschemaValidator(
86
115
  "/propertyPack/energyPerformanceCertificate"