Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions Generator/Normalizer/NormalizerGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,20 @@ protected function createNormalizeMethod(string $modelFqdn, Context $context, Cl
}

if (!$property->isRequired()) {
$statements[] = new Stmt\If_(
new Expr\BinaryOp\BooleanAnd(
if ($property->isNullable()) {
$statements[] = new Stmt\If_(
new Expr\MethodCall($objectVariable, 'isInitialized', [new Arg(new Scalar\String_($property->getPhpName()))]),
new Expr\BinaryOp\NotIdentical(new Expr\ConstFetch(new Name('null')), $propertyVar)
),
['stmts' => $normalizationStatements]
);
['stmts' => $normalizationStatements]
);
} else {
$statements[] = new Stmt\If_(
new Expr\BinaryOp\BooleanAnd(
new Expr\MethodCall($objectVariable, 'isInitialized', [new Arg(new Scalar\String_($property->getPhpName()))]),
new Expr\BinaryOp\NotIdentical(new Expr\ConstFetch(new Name('null')), $propertyVar)
),
['stmts' => $normalizationStatements]
);
}
} else {
$statements[] = new Stmt\If_(
new Expr\BinaryOp\NotIdentical(new Expr\ConstFetch(new Name('null')), $propertyVar),
Expand Down
2 changes: 1 addition & 1 deletion Guesser/Guess/CheckNullableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function isNullable($schema): bool
return $schema->offsetExists('x-nullable') && \is_bool($schema->offsetGet('x-nullable')) && $schema->offsetGet('x-nullable');
}
if (\get_class($schema) === 'Jane\\Component\\OpenApi3\\JsonSchema\\Model\\Schema') {
return method_exists($schema, 'getNullable') && !($schema->getNullable() ?? false);
return method_exists($schema, 'getNullable') && $schema->getNullable() === true;
}

return false;
Expand Down
Loading