diff --git a/package-lock.json b/package-lock.json index 1ba6852c7..1b56f8521 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "passbolt-styleguide", - "version": "4.8.0-alpha.10", + "version": "4.8.0-alpha.11", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "passbolt-styleguide", - "version": "4.8.0-alpha.10", + "version": "4.8.0-alpha.11", "license": "AGPL-3.0", "dependencies": { "@testing-library/dom": "^8.11.3", diff --git a/package.json b/package.json index 55d7c29b7..5d6fb7060 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "passbolt-styleguide", - "version": "4.8.0-alpha.10", + "version": "4.8.0-alpha.11", "license": "AGPL-3.0", "copyright": "Copyright 2023 Passbolt SA", "description": "Passbolt styleguide contains common styling assets used by the different sites, plugin, etc.", diff --git a/src/shared/models/entity/abstract/entitySchema.js b/src/shared/models/entity/abstract/entitySchema.js index eb98ea4c7..d83eebe71 100644 --- a/src/shared/models/entity/abstract/entitySchema.js +++ b/src/shared/models/entity/abstract/entitySchema.js @@ -119,11 +119,21 @@ class EntitySchema { continue; } + // check if propery is null + if (dto?.[propName] === null) { + // the prop is explicitly null, is it explicitly nullable? + if ((schemaProps[propName]?.nullable) === true) { + result[propName] = null; + continue; + } + // @todo: else => props is not nullable and null we could set an error and then continue but it requires all schema to migrate to explicit "nullable": true + } + // Check if property is required if (requiredProps.includes(propName)) { if (!Object.prototype.hasOwnProperty.call(dto, propName)) { validationError = EntitySchema.getOrInitEntityValidationError(name, validationError); - validationError.addError(propName, 'required', `The ${propName} is required.`, validationError); + validationError.addError(propName, 'required', `The ${propName} is required.`); continue; } } else { diff --git a/src/shared/models/entity/healthcheck/associations/applicationEntity.js b/src/shared/models/entity/healthcheck/associations/applicationEntity.js index 1da92d536..f8605e0d7 100644 --- a/src/shared/models/entity/healthcheck/associations/applicationEntity.js +++ b/src/shared/models/entity/healthcheck/associations/applicationEntity.js @@ -41,21 +41,19 @@ class ApplicationEntity extends Entity { "type": "object", "required": ["remoteVersion", "currentVersion"], "properties": { - "remoteVersion": {"anyOf": [{ - "type": "string" - }, { - "type": "null" - }]}, + "remoteVersion": { + "type": "string", + "nullable": true, + }, "currentVersion": { "type": "string" } } }, - "latestVersion": {"anyOf": [{ + "latestVersion": { "type": "boolean", - }, { - "type": "null" - }]}, + "nullable": true, + }, "schema": { "type": "boolean" }, @@ -81,11 +79,10 @@ class ApplicationEntity extends Entity { "isSelfRegistrationPluginEnabled": { "type": "boolean" }, - "selfRegistrationProvider": {"anyOf": [{ - "type": "string" - }, { - "type": "null" - }]}, + "selfRegistrationProvider": { + "type": "string", + "nullable": true, + }, "isRegistrationPublicRemovedFromPassbolt": { "type": "boolean" } diff --git a/src/shared/models/entity/passwordExpiryPro/passwordExpiryProSettingsEntity.js b/src/shared/models/entity/passwordExpiryPro/passwordExpiryProSettingsEntity.js index fcd236e09..c6a68542e 100644 --- a/src/shared/models/entity/passwordExpiryPro/passwordExpiryProSettingsEntity.js +++ b/src/shared/models/entity/passwordExpiryPro/passwordExpiryProSettingsEntity.js @@ -47,13 +47,10 @@ class PasswordExpiryProSettingsEntity extends Entity { "format": "uuid", }, "default_expiry_period": { - "anyOf": [{ - "type": "integer", - "gte": 1, - "lte": 999 - }, { - "type": "null" - }] + "type": "integer", + "gte": 1, + "lte": 999, + "nullable": true, }, "policy_override": { "type": "boolean", diff --git a/src/shared/models/entity/ssoSettings/SsoSettingsEntity.js b/src/shared/models/entity/ssoSettings/SsoSettingsEntity.js index 31b6e9fca..fc2dca7e3 100644 --- a/src/shared/models/entity/ssoSettings/SsoSettingsEntity.js +++ b/src/shared/models/entity/ssoSettings/SsoSettingsEntity.js @@ -61,12 +61,9 @@ class SsoSettingsEntity extends Entity { }, }, "provider": { - "anyOf": [{ - "type": "string", - "enum": SsoSettingsEntity.AVAILABLE_PROVIDERS, - }, { - "type": "null" - }], + "type": "string", + "enum": SsoSettingsEntity.AVAILABLE_PROVIDERS, + "nullable": true, }, "data": { "type": "object", diff --git a/src/shared/models/entity/ssoSettings/SsoSettingsEntity.test.js b/src/shared/models/entity/ssoSettings/SsoSettingsEntity.test.js index 6e37339d7..dc1ec03cb 100644 --- a/src/shared/models/entity/ssoSettings/SsoSettingsEntity.test.js +++ b/src/shared/models/entity/ssoSettings/SsoSettingsEntity.test.js @@ -71,7 +71,7 @@ describe("SsoSettingsEntity", () => { const successScenarios = successValues.map(value => ({scenario: `with value "${value}}"`, value: value})); const failingScenarios = failingValues.map(value => ({scenario: `with value "${value}}"`, value: value})); - assertEntityProperty.assert(SsoSettingsEntity, "provider", successScenarios, failingScenarios, "type"); + assertEntityProperty.assert(SsoSettingsEntity, "provider", successScenarios, failingScenarios, "enum"); assertEntityProperty.nullable(SsoSettingsEntity, "provider"); assertEntityProperty.notRequired(SsoSettingsEntity, "provider"); }); diff --git a/src/shared/models/passwordExpirySettings/PasswordExpirySettingsViewModel.test.js b/src/shared/models/passwordExpirySettings/PasswordExpirySettingsViewModel.test.js index 003cb7010..01dcfde81 100644 --- a/src/shared/models/passwordExpirySettings/PasswordExpirySettingsViewModel.test.js +++ b/src/shared/models/passwordExpirySettings/PasswordExpirySettingsViewModel.test.js @@ -203,7 +203,7 @@ describe("PasswordExpirySettingsViewModel", () => { }, { dto: {default_expiry_period: -1}, - expectedErrors: {default_expiry_period: {type: "The default_expiry_period does not match any of the supported types."}}, + expectedErrors: {default_expiry_period: {type: "The default_expiry_period is not a valid integer."}}, }, ]).describe("should validate the current data set with PasswordExpiryProSettingsEntity", scenario => { it(`for: ${JSON.stringify(scenario.dto)}`, () => { diff --git a/test/assert/assertEntityProperty.js b/test/assert/assertEntityProperty.js index 8ef2750ee..7010f7470 100644 --- a/test/assert/assertEntityProperty.js +++ b/test/assert/assertEntityProperty.js @@ -190,7 +190,7 @@ export const FAIL_LOCALE_SCENARIO = [ {scenario: "Incomplete", value: "fr"}, ]; export const locale = (EntityClass, propertyName) => { - assert(EntityClass, propertyName, SUCCESS_LOCALE_SCENARIO, FAIL_LOCALE_SCENARIO, "type"); + assert(EntityClass, propertyName, SUCCESS_LOCALE_SCENARIO, FAIL_LOCALE_SCENARIO, "pattern"); }; export const enumeration = (EntityClass, propertyName, successValues, failValues = []) => {