-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
[R] add null checks to nullable api parameters #21629
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
Conversation
|
Hello, For the change described with:
Is it intentional that the client will not follow OAS with this change? Parameters have two settings, This change would mean that you could not send a null value for a property that is both required and nullable? |
1fa8d73 to
1d7111f
Compare
|
Sorry for the mixup. I've reverted the commits pertaining to the null check. The R |
hmm... that should work in each item in the parameters mustache tags (eg.. allParams) |
|
@wing328 I'm not sure I follow. I just meant that in I went ahead and added 2 commits to this PR. The first adds a Let me know if you would rather I remove the commits pertaining to the |
| reason = "Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}, `{{paramName}}` is not nullable")) | ||
| {{/useRlangExceptionHandling}} | ||
| } | ||
| {{/isNullable}} |
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 pr
2 questions:
-
looks like required parameters are processed again for null check. shall we update the block in line 195 instead?
-
since this is in the
allParamsloop/list, that means optional parameters (if defined) will be processed as well. would optional parameters work in this new code block (null check)?
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.
This update was in response to @Mattias-Sehlstedt above
Parameters have two settings, required and nullable, see for example Data Types. required means that the property must be present, while nullable means whether the property can take the value null.
I was matching "required" to the R missing() check and "nullable" the R is.null() check. I added the !missing({{paramName}}) to the null checks to avoid an error in the event that an a parameter that is "not required" but "is not nullable" and is set to NULL. I cannot think of any cases where an optional parameter should not be nullable though.
To your questions:
- Required parameters are only processed for
missingin the line 195 block. If I add a null check there then optional and nullable will by handled the same way in R clients. I'm fine with this if you prefer it. - Yes, optional parameters are first checked for
missing()and then checked foris.null()if the parameter is not nullable.
I think this is ready to go, but what I actually care about is the fix in a4aac2a. If we need further discussion on the nullable checks I'm happy to move those commits to a fresh PR.
ok. please ignore my feedback. I thought you mean isNullable is not working. |
|
tested locally and the result is good |
|
let's give it a try. thanks for the contribution |
* [R] check optional parametrs for null before evaluating param conditions * update petstore * handle isNullable when checking api parameters * update samples * allow not-nullable parameters to be missing * update samples * samples
@Ramanth, @saigiridhar21, @wing328
This PR fixes an issue where exceptions are thrown when trying to check nullable parameters against patters or ranges, etc. The change is simple: if the parameter is
NULLreturnFALSE(!is.null(param)) in theif()conditional statement to avoid throwing an error.I also made a small change to the check for required parameters. The code still checks for
missing()but also requires that "required" parameters not beNULL. This prevents users from intentionally setting a required parameter toNULLand ensures that the!is.null()checks I added in the{{#allParams}}section are independent of required parameter checks.You can see that it works by looking at the regenerated petstore R client. It has more
is.nullchecks than before.PR checklist
Commit all changed files.
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*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)