-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
[#13998][Bug][PHP] Move isNullable section to the top of the setter function in templates #14005
[#13998][Bug][PHP] Move isNullable section to the top of the setter function in templates #14005
Conversation
@jebentier @dkarlovi @mandrean @jfastnacht @ybelenko @renepardon @wing328 This PR is ready for review |
{{#isEnum}} | ||
$allowedValues = $this->{{getter}}AllowableValues(); | ||
{{^isContainer}} | ||
if ({{^required}}!is_null(${{name}}) && {{/required}}!in_array(${{{name}}}, $allowedValues, true)) { | ||
if ({{#isNullable}}!is_null(${{name}}) && {{/isNullable}}!in_array(${{{name}}}, $allowedValues, true)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MustansirS thanks for the PR. I notice that the check for optional field has been replaced by isNullable
check instead.
Shall we keep the check for optional field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that a null
value will never be passed to the setter
function if it is not a nullable
field:
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache#L516
And if we keep the check as the check for just the optional field, then the original problem of the issue will persist and an operation such as a preg_match
on a null
value will be attempted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the explanation.
thanks for the fix. lgtm but i've not tested it locally let's give it a try to see if anyone has further feedback on this fix. |
Thank you! |
Resolves #13998
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.For Windows users, please run the script in Git BASH.
master
(6.3.0) (minor release - breaking changes with fallbacks),7.0.x
(breaking changes without fallbacks)@jebentier @dkarlovi @mandrean @jfastnacht @ybelenko @renepardon @wing328