@pdtf/schemas 0.11.0-3 → 0.11.0-5

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
@@ -37,6 +37,7 @@ const ajv = new Ajv({
37
37
  allErrors: true,
38
38
  // schema contains additional baspiRef and RDSRef metadata which is not strictly valid
39
39
  strictSchema: false,
40
+ discriminator: true,
40
41
  });
41
42
  // Adds date formats among other types to the validator.
42
43
  addFormats(ajv);
@@ -45,18 +46,14 @@ const validator = ajv.compile(transactionSchema);
45
46
 
46
47
  const getSubschema = (path) => {
47
48
  const pathArray = path.split("/").slice(1);
48
- if (pathArray.length < 1) {
49
- return transactionSchema;
50
- }
51
-
49
+ if (pathArray.length < 1) return transactionSchema;
52
50
  return pathArray.reduce((schema, pathElement) => {
53
51
  if (schema.type === "array") return schema.items;
54
52
  if (schema.properties[pathElement]) return schema.properties[pathElement];
55
- const dependencies = schema.dependencies;
56
- if (dependencies) {
53
+ const discriminator = schema.discriminator?.propertyName;
54
+ if (discriminator) {
57
55
  // only single dependency discriminator, oneOf keyword is supported
58
- const dependencyDiscriminator = Object.keys(dependencies)[0];
59
- const oneOfs = dependencies[dependencyDiscriminator].oneOf;
56
+ const oneOfs = schema.oneOf;
60
57
  const matchingOneOf = oneOfs.find(
61
58
  (oneOf) => oneOf["properties"][pathElement]
62
59
  );
@@ -112,11 +109,10 @@ const getTitleAtPath = (schema, path, rootPath = path) => {
112
109
  subSchema = schema.items;
113
110
  return getTitleAtPath(subSchema, subPath, rootPath);
114
111
  }
115
- const dependencies = schema.dependencies;
116
- if (dependencies) {
112
+ const discriminator = schema.discriminator?.propertyName;
113
+ if (discriminator) {
117
114
  // only single dependency discriminator, oneOf keyword is supported
118
- const dependencyDiscriminator = Object.keys(dependencies)[0];
119
- const oneOfs = dependencies[dependencyDiscriminator].oneOf;
115
+ const oneOfs = schema.oneOf;
120
116
  const matchingOneOf = oneOfs.find(
121
117
  (oneOf) => oneOf["properties"][propertyName]
122
118
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdtf/schemas",
3
- "version": "0.11.0-3",
3
+ "version": "0.11.0-5",
4
4
  "description": "Property Data Trust Framework Schemas and Utilities",
5
5
  "main": "index.js",
6
6
  "directories": {