···345345 plugin,
346346 schema: property,
347347 });
348348- if (propertyNodes.length) {
349349- if (required.includes(name)) {
350350- nodes = nodes.concat(propertyNodes);
351351- } else {
352352- nodes.push(
353353- compiler.ifStatement({
354354- expression: propertyAccessExpression,
355355- thenStatement: compiler.block({
356356- statements: ensureStatements(propertyNodes),
357357- }),
348348+ if (!propertyNodes.length) {
349349+ continue;
350350+ }
351351+ const noNullableTypesInSchema = !property.items?.find(
352352+ (x) => x.type === 'null',
353353+ );
354354+ const requiredField = required.includes(name);
355355+ // Cannot fully rely on required fields
356356+ // Such value has to be present, but it doesn't guarantee that this value is not nullish
357357+ if (requiredField && noNullableTypesInSchema) {
358358+ nodes = nodes.concat(propertyNodes);
359359+ } else {
360360+ nodes.push(
361361+ // todo: Probably, it would make more sense to go with if(x !== undefined && x !== null) instead of if(x)
362362+ // this place influences all underlying transformers, while it's not exactly transformer itself
363363+ // Keep in mind that !!0 === false, so it already makes output for Bigint undesirable
364364+ compiler.ifStatement({
365365+ expression: propertyAccessExpression,
366366+ thenStatement: compiler.block({
367367+ statements: ensureStatements(propertyNodes),
358368 }),
359359- );
360360- }
369369+ }),
370370+ );
361371 }
362372 }
363373