@pdtf/schemas 1.0.0 → 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.0.0",
3
+ "version": "1.1.2",
4
4
  "description": "Property Data Trust Framework Schemas and Utilities",
5
5
  "main": "index.js",
6
6
  "directories": {