Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonSchema DenormalizerGenerator does not unset data in else branch #801

Open
discordier opened this issue Apr 12, 2024 · 0 comments
Open
Labels

Comments

@discordier
Copy link
Contributor

Jane version(s) affected: 7.6.1 (probably all before also)

Description

JsonSchema DenormalizerGenerator does not unset the read key in input data when going into the else branch which handles reading of null values.

How to reproduce

Generate any object with nullable properties.

Possible Solution

I came up with the following solution:

--- src/Component/JsonSchema/Generator/Normalizer/DenormalizerGenerator.php	2024-04-12 08:25:00.617827483 +0000
+++ src/Component/JsonSchema/Generator/Normalizer/DenormalizerGenerator.php	2024-04-12 08:26:07.800853676 +0000
@@ -156,6 +156,7 @@
 
                 $statements[] = new Stmt\ElseIf_($invertCondition, [
                     new Stmt\Expression(new Expr\MethodCall($objectVariable, $this->getNaming()->getPrefixedMethodName('set', $property->getAccessorName()), [new Expr\ConstFetch(new Name('null'))])),
+                    ...($unset ? [new Stmt\Unset_([$propertyVar])] : [])
                 ]);
             }
         }

The unsetting, which is done here:

$mutatorStmt = array_merge($denormalizationStatements, [
new Stmt\Expression(new Expr\MethodCall($objectVariable, $this->getNaming()->getPrefixedMethodName('set', $property->getAccessorName()), [$outputVar])),
], $unset ? [new Stmt\Unset_([$propertyVar])] : []);

seems to have been forgotten here:

$statements[] = new Stmt\ElseIf_($invertCondition, [
new Stmt\Expression(new Expr\MethodCall($objectVariable, $this->getNaming()->getPrefixedMethodName('set', $property->getAccessorName()), [new Expr\ConstFetch(new Name('null'))])),
]);

@discordier discordier added the bug label Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant