diff --git a/packages/schema/src/schema.ts b/packages/schema/src/schema.ts index 4cf7bd8..a7604f4 100644 --- a/packages/schema/src/schema.ts +++ b/packages/schema/src/schema.ts @@ -142,7 +142,7 @@ export function validateAndUnmap>( * @param schema Schema for type */ export function validateAndMapXml>( - value: SchemaMappedType, + value: unknown, schema: T ): ValidationResult> { const contextCreator = createSchemaContextCreator( @@ -150,9 +150,6 @@ export function validateAndMapXml>( ); const validationResult = schema.validateBeforeMapXml(value, contextCreator); if (validationResult.length === 0) { - if (isOptionalNullable(schema.type(), value)) { - return { errors: false, result: value }; - } return { errors: false, result: schema.mapXml(value, contextCreator) }; } else { return { errors: validationResult }; diff --git a/packages/schema/src/types/nullable.ts b/packages/schema/src/types/nullable.ts index 7c0ecf4..b4a1e2a 100644 --- a/packages/schema/src/types/nullable.ts +++ b/packages/schema/src/types/nullable.ts @@ -22,7 +22,7 @@ export function nullable( validateBeforeMapXml: (value, ctxt) => value === null ? [] : schema.validateBeforeMapXml(value, ctxt), mapXml: (value, ctxt) => - isNullOrMissing(value) ? null : schema.mapXml(value, ctxt), + value === null ? null : schema.mapXml(value, ctxt), unmapXml: (value, ctxt) => value === null ? null : schema.unmapXml(value, ctxt), }; diff --git a/packages/schema/src/types/optional.ts b/packages/schema/src/types/optional.ts index 7592f2c..ff776ba 100644 --- a/packages/schema/src/types/optional.ts +++ b/packages/schema/src/types/optional.ts @@ -27,7 +27,7 @@ export function optional( ? [] : schema.validateBeforeMapXml(value, ctxt), mapXml: (value, ctxt) => - isNullOrMissing(value) ? undefined : schema.mapXml(value, ctxt), + value === null ? undefined : schema.mapXml(value, ctxt), unmapXml: (value, ctxt) => typeof value === 'undefined' ? undefined : schema.unmapXml(value, ctxt), };