Skip to content

Commit

Permalink
remove xml handling
Browse files Browse the repository at this point in the history
  • Loading branch information
asadali214 committed Jun 27, 2024
1 parent a706549 commit 85c0966
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/schema/src/types/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,11 @@ function mapObject<T extends AnyObjectSchema>(
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;
}

Expand Down
9 changes: 8 additions & 1 deletion packages/schema/test/types/object.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 85c0966

Please sign in to comment.