@pdtf/schemas 0.6.8 → 0.6.9

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
@@ -40,6 +40,16 @@ const getSubschema = (path) => {
40
40
  return transactionSchema;
41
41
  }
42
42
  return pathArray.reduce((schema, pathElement) => {
43
+ const dependencies = schema.dependencies;
44
+ if (dependencies) {
45
+ // only single dependency discriminator, oneOf keyword is supported
46
+ const dependencyDiscriminator = Object.keys(dependencies)[0];
47
+ const oneOfs = dependencies[dependencyDiscriminator].oneOf;
48
+ const matchingOneOf = oneOfs.find(
49
+ (oneOf) => oneOf["properties"][pathElement]
50
+ );
51
+ if (matchingOneOf) return matchingOneOf["properties"][pathElement];
52
+ }
43
53
  if (schema.type === "array") return schema.items;
44
54
  return schema.properties[pathElement];
45
55
  }, transactionSchema);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdtf/schemas",
3
- "version": "0.6.8",
3
+ "version": "0.6.9",
4
4
  "description": "Property Data Trust Framework Schemas and Utilities",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -81,6 +81,27 @@ 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
+
84
105
  test("correctly gets a subschema validator which is already cached", () => {
85
106
  const validator = getSubschemaValidator(
86
107
  "/propertyPack/energyPerformanceCertificate"