From 85c09663e2cc7f7606e6fdc13ed8553f378804c0 Mon Sep 17 00:00:00 2001 From: Asad Ali Date: Thu, 27 Jun 2024 17:20:13 +0500 Subject: [PATCH] remove xml handling --- packages/schema/src/types/object.ts | 4 ++-- packages/schema/test/types/object.test.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/schema/src/types/object.ts b/packages/schema/src/types/object.ts index c329556..e662e26 100644 --- a/packages/schema/src/types/object.ts +++ b/packages/schema/src/types/object.ts @@ -468,11 +468,11 @@ function mapObject( unknownKeys.delete(propName); if (isOptionalNullable(element[1].type(), propValue)) { - if (typeof value === 'undefined') { + if (typeof propValue === 'undefined') { // Skip mapping to avoid creating properties with value 'undefined' continue; } - output[key] = propValue; + output[key] = null; continue; } diff --git a/packages/schema/test/types/object.test.ts b/packages/schema/test/types/object.test.ts index d6e345e..a15417d 100644 --- a/packages/schema/test/types/object.test.ts +++ b/packages/schema/test/types/object.test.ts @@ -20,15 +20,22 @@ describe('Object', () => { }); const workSchema = object({ - id: ['work_id', optional(nullable(string()))], + id: ['work_id', optional(nullable(number()))], + name: ['work_name', optional(nullable(string()))], + address: ['work_address', optional(nullable(string()))], }); + // null => null + // undefined => missing + // missing => missing + it('should map valid object with lazy loaded sub object', () => { const input = { user_id: 'John Smith', user_age: 50, user_work: { work_id: null, + work_name: undefined, }, }; const output = validateAndMap(input, userSchema);