From c6847aeaf747c13b95b620a6d507b86df449f804 Mon Sep 17 00:00:00 2001 From: Eduardo Shiota Yasuda Date: Fri, 22 Aug 2025 19:25:02 +0200 Subject: [PATCH 1/2] feat(json-logic): apply computed attrs on nested allOf/anyOf/oneOf properties --- src/validation/json-logic.ts | 62 ++++++++++++++---------------- test/validation/json-logic.test.ts | 55 ++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 34 deletions(-) diff --git a/src/validation/json-logic.ts b/src/validation/json-logic.ts index 02a28179..4d5da80f 100644 --- a/src/validation/json-logic.ts +++ b/src/validation/json-logic.ts @@ -162,51 +162,45 @@ function cycleThroughPropertiesAndApplyValues(schemaCopy: JsfSchema, computedVal cycleThroughAttrsAndApplyValues(propertySchema, computedValues, computedAttrs) } - if (propertySchema.type === 'object' && propertySchema.properties) { - cycleThroughPropertiesAndApplyValues(propertySchema, computedValues) + // If the schemas has properties, we need to cycle through each one and apply the computed values + if (typeof propertySchema.properties === 'object') { + for (const propertyName in propertySchema.properties) { + processProperty(propertySchema.properties[propertyName]) + } } - // deleting x-jsf-logic-computedAttrs to keep the schema clean - delete propertySchema['x-jsf-logic-computedAttrs'] - } - - // If the schemas has properties, we need to cycle through each one and apply the computed values - // Otherwise, just process the property - if (schemaCopy.properties) { - for (const propertyName in schemaCopy.properties) { - processProperty(schemaCopy.properties[propertyName]) + // If the schema has an if statement, we need to cycle through the properties and apply the computed values + if (typeof propertySchema.if === 'object') { + cycleThroughPropertiesAndApplyValues(propertySchema.if, computedValues) } - } - else { - processProperty(schemaCopy) - } - // If the schema has an if statement, we need to cycle through the properties and apply the computed values - if (typeof schemaCopy.if === 'object') { - cycleThroughPropertiesAndApplyValues(schemaCopy.if, computedValues) - } - - /* If the schema has an allOf or anyOf property, we need to cycle through each property inside it and - * apply the computed values - */ + /* If the schema has an allOf or anyOf property, we need to cycle through each property inside it and + * apply the computed values + */ - if (schemaCopy.allOf && schemaCopy.allOf.length > 0) { - for (const schema of schemaCopy.allOf) { - cycleThroughPropertiesAndApplyValues(schema, computedValues) + if (propertySchema.allOf && propertySchema.allOf.length > 0) { + for (const schema of propertySchema.allOf) { + cycleThroughPropertiesAndApplyValues(schema, computedValues) + } } - } - if (schemaCopy.anyOf && schemaCopy.anyOf.length > 0) { - for (const schema of schemaCopy.anyOf) { - cycleThroughPropertiesAndApplyValues(schema, computedValues) + if (propertySchema.anyOf && propertySchema.anyOf.length > 0) { + for (const schema of propertySchema.anyOf) { + cycleThroughPropertiesAndApplyValues(schema, computedValues) + } } - } - if (schemaCopy.oneOf && schemaCopy.oneOf.length > 0) { - for (const schema of schemaCopy.oneOf) { - cycleThroughPropertiesAndApplyValues(schema, computedValues) + if (propertySchema.oneOf && propertySchema.oneOf.length > 0) { + for (const schema of propertySchema.oneOf) { + cycleThroughPropertiesAndApplyValues(schema, computedValues) + } } + + // deleting x-jsf-logic-computedAttrs to keep the schema clean + delete propertySchema['x-jsf-logic-computedAttrs'] } + + processProperty(schemaCopy) } /** diff --git a/test/validation/json-logic.test.ts b/test/validation/json-logic.test.ts index ce08dc62..d4e34e75 100644 --- a/test/validation/json-logic.test.ts +++ b/test/validation/json-logic.test.ts @@ -537,4 +537,59 @@ describe('applyComputedAttrsToSchema', () => { expect(conditionValue['x-jsf-logic-computedAttrs']).toBeUndefined() expect(conditionValue.minimum).toBe(10) }) + + it('allows to use computed values inside oneOf statements nested in a property', () => { + const schema: JsfObjectSchema = { + 'type': 'object', + 'properties': { + maximum_temperature: { + title: 'Maximum room temperature', + type: 'number', + description: 'What is the maximum room temperature in Celsius?', + }, + temperature_setting: { + title: 'Select a preset temperature', + type: 'string', + oneOf: [ + { + title: 'Low', + const: 18, + }, + { + title: 'Medium', + const: 20, + }, + { + 'title': 'Maximum', + 'x-jsf-logic-computedAttrs': { + const: 'maximum_temperature', + }, + }, + ], + }, + }, + 'required': [ + 'maximum_temperature', + 'temperature_setting', + ], + 'x-jsf-logic': { + computedValues: { + maximum_temperature: { + rule: { + var: 'maximum_temperature', + }, + }, + }, + }, + }; + + // Mock the jsonLogic.apply to return 24 + (jsonLogic.apply as jest.Mock).mockReturnValue(24) + + const result = JsonLogicValidation.applyComputedAttrsToSchema(schema, schema['x-jsf-logic']?.computedValues, { maximum_temperature: 24 }) + + const temperatureSetting = result.properties?.temperature_setting as NonBooleanJsfSchema + expect(temperatureSetting['x-jsf-logic-computedAttrs']).toBeUndefined() + expect((temperatureSetting.oneOf?.[2] as NonBooleanJsfSchema)?.const).toBe(24) + }) }) From 4008b9e7ddbb1b3fea3674202fb7e0ea79e22e2c Mon Sep 17 00:00:00 2001 From: Eduardo Shiota Yasuda Date: Thu, 28 Aug 2025 14:44:50 +0200 Subject: [PATCH 2/2] fix(release): fix dev version git tag --- scripts/release.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/release.js b/scripts/release.js index 448bd755..f413163a 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -142,7 +142,7 @@ async function gitCommit({ newVersion, releaseType }) { cmd = `git add package.json CHANGELOG.md && git commit -m "Release ${newVersion}" && git tag ${newVersion} && git push && git push origin --tags`; } else { // For dev, we only create a tag - cmd = `git tag ${prefix}-${newVersion} && git push origin --tags`; + cmd = `git tag ${newVersion} && git push origin --tags`; } await runExec(cmd);