Skip to content

Conversation

@mattpollock
Copy link
Contributor

@mattpollock mattpollock commented Jul 24, 2025

@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 NULL return FALSE (!is.null(param)) in the if() 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 be NULL. This prevents users from intentionally setting a required parameter to NULL and 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.null checks than before.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@Mattias-Sehlstedt
Copy link
Contributor

Hello,

For the change described with:

The code still checks for missing() but also requires that "required" parameters not be NULL

Is it intentional that the client will not follow OAS with this change? 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.

This change would mean that you could not send a null value for a property that is both required and nullable?

@mattpollock
Copy link
Contributor Author

Sorry for the mixup. I've reverted the commits pertaining to the null check. The R api.mustache file does not appear to handle {{#isNullable}} at all. I can put that in a separate PR tomorrow though.

@wing328
Copy link
Member

wing328 commented Jul 25, 2025

The R api.mustache file does not appear to handle {{#isNullable}}

hmm... that should work in each item in the parameters mustache tags (eg.. allParams)

@mattpollock
Copy link
Contributor Author

@wing328 I'm not sure I follow. I just meant that in master there is no {{#isNullable}} or {{^isNullable}} blocks in the modules/openapi-generator/src/main/resources/r/api.mustache file.

I went ahead and added 2 commits to this PR. The first adds a {{^isNullable}} block and will throw and error if a parameter not marked nullable is NULL. The second updates the code in samples/client/{echo_api,petstore}/. This way we throw for null values appropriately but handle nullable values gracefully when checking other things (e.g., like min/max value).

Let me know if you would rather I remove the commits pertaining to the {{^isNullable}} block or cherry-pick them onto a separate PR.

reason = "Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}, `{{paramName}}` is not nullable"))
{{/useRlangExceptionHandling}}
}
{{/isNullable}}
Copy link
Member

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:

  1. looks like required parameters are processed again for null check. shall we update the block in line 195 instead?

  2. since this is in the allParams loop/list, that means optional parameters (if defined) will be processed as well. would optional parameters work in this new code block (null check)?

Copy link
Contributor Author

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:

  1. Required parameters are only processed for missing in 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.
  2. Yes, optional parameters are first checked for missing() and then checked for is.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.

@wing328
Copy link
Member

wing328 commented Jul 28, 2025

I just meant that in master there is no {{#isNullable}} or {{^isNullable}} blocks in the modules/openapi-generator/src/main/resources/r/api.mustache file.

ok. please ignore my feedback. I thought you mean isNullable is not working.

@wing328
Copy link
Member

wing328 commented Jul 29, 2025

tested locally and the result is good

All user-level objects in a package should have documentation entries.
See chapter ‘Writing R documentation files’ in the ‘Writing R
Extensions’ manual.
* checking examples ... NONE
* checking for unstated dependencies in ‘tests’ ... OK
* checking tests ...
  Running ‘testthat.R’
 OK
* DONE

Status: 1 WARNING
See
  ‘/mnt/c/Users/wing3/Code/openapi-generator/samples/client/petstore/R/petstore.Rcheck/00check.log’
for details.


* installing to library ‘/home/wing328/R’
* installing *source* package ‘petstore’ ...
** using staged installation
** R
** byte-compile and prepare package for lazy loading
** help
No man pages found in package  ‘petstore’
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (petstore)
* 

@wing328
Copy link
Member

wing328 commented Jul 29, 2025

let's give it a try. thanks for the contribution

@wing328 wing328 merged commit 815a732 into OpenAPITools:master Jul 29, 2025
15 checks passed
Goopher pushed a commit to Goopher/openapi-generator that referenced this pull request Sep 9, 2025
* [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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants