@pdtf/schemas 3.6.0-23 → 3.6.0-24

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
@@ -254,28 +254,44 @@ const getCachedSchemaData = (path, schemaId, overlays) => {
254
254
  }
255
255
  }
256
256
 
257
- // Check oneOf discriminators
257
+ // Check oneOf discriminators (recursively for nested oneOf)
258
258
  if (oneOf) {
259
- let matchingProperty;
260
- oneOf.forEach((aOneOf) => {
261
- if (aOneOf.type === "array" && !Number.isNaN(pathElement)) {
262
- matchingProperty = aOneOf.items;
263
- } else if (aOneOf.properties?.[pathElement]) {
264
- matchingProperty = aOneOf.properties?.[pathElement];
265
- } else if (aOneOf.patternProperties) {
266
- for (const pattern in aOneOf.patternProperties) {
267
- try {
268
- const regex = new RegExp(pattern);
269
- if (regex.test(pathElement)) {
270
- matchingProperty = aOneOf.patternProperties[pattern];
271
- break;
259
+ const findInOneOf = (branches) => {
260
+ let arrayFallback;
261
+ for (const branch of branches) {
262
+ if (!branch) continue;
263
+ // Track array matches as fallback (prefer property matches)
264
+ if (
265
+ branch.type === "array" &&
266
+ !Number.isNaN(pathElement) &&
267
+ !arrayFallback
268
+ ) {
269
+ arrayFallback = branch.items;
270
+ }
271
+ if (branch.properties?.[pathElement]) {
272
+ return branch.properties[pathElement];
273
+ }
274
+ if (branch.patternProperties) {
275
+ for (const pattern in branch.patternProperties) {
276
+ try {
277
+ const regex = new RegExp(pattern);
278
+ if (regex.test(pathElement)) {
279
+ return branch.patternProperties[pattern];
280
+ }
281
+ } catch (e) {
282
+ // Invalid regex pattern - skip
272
283
  }
273
- } catch (e) {
274
- // Invalid regex pattern - skip
275
284
  }
276
285
  }
286
+ // Recurse into nested oneOf branches
287
+ if (branch.oneOf) {
288
+ const nested = findInOneOf(branch.oneOf);
289
+ if (nested) return nested;
290
+ }
277
291
  }
278
- });
292
+ return arrayFallback;
293
+ };
294
+ const matchingProperty = findInOneOf(oneOf);
279
295
  if (matchingProperty) return matchingProperty;
280
296
  }
281
297
 
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@pdtf/schemas",
3
- "version": "3.6.0-23",
3
+
4
+ "version": "3.6.0-24",
4
5
  "description": "Property Data Trust Framework Schemas and Utilities",
5
6
  "main": "index.js",
6
7
  "directories": {
@@ -233,6 +233,37 @@ test("correctly gets yes another subschema but through a non-baspi oneOf structu
233
233
  expect(subschema).toEqual({ type: "string" });
234
234
  });
235
235
 
236
+ test("correctly resolves properties inside nested oneOf branches", () => {
237
+ // attachments is at japaneseKnotweed.oneOf[1].oneOf[1].properties.attachments
238
+ const subschema = getSubschema(
239
+ "/propertyPack/specialistIssues/japaneseKnotweed/attachments"
240
+ );
241
+ expect(subschema).toBeDefined();
242
+ expect(subschema.type).toBe("string");
243
+ expect(subschema.enum).toContain("To follow");
244
+ expect(subschema.enum).toContain("Attached");
245
+ });
246
+
247
+ test("isPathValid returns true for nested oneOf properties", () => {
248
+ expect(
249
+ isPathValid("/propertyPack/specialistIssues/japaneseKnotweed/attachments")
250
+ ).toBe(true);
251
+ // knotweedSurveyCarriedOut.attachments is also nested in a oneOf
252
+ expect(
253
+ isPathValid(
254
+ "/propertyPack/specialistIssues/japaneseKnotweed/knotweedSurveyCarriedOut/attachments"
255
+ )
256
+ ).toBe(true);
257
+ });
258
+
259
+ test("isPathValid returns false for non-existent paths in nested oneOf", () => {
260
+ expect(
261
+ isPathValid(
262
+ "/propertyPack/specialistIssues/japaneseKnotweed/nonExistentField"
263
+ )
264
+ ).toBe(false);
265
+ });
266
+
236
267
  test("correctly gets an overlaid enum in a subschema", () => {
237
268
  const subschema = getSubschema(
238
269
  "/propertyPack/electricity/mainsElectricity/yesNo",