swagger-api / swagger-api/swagger-codegen
[R] Issues with R Codegen Clients
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
I tried to make a new API package using the following with code pulled on September 18. :
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar -i http://petstore.swagger.io/v2/swagger.json -l r -o /tmp/test
Below are a number of suggestions and bugs:
Minor Issue 1: Include Installation Instructions
This would be useful in the README.md.
Set up to use CRAN package repository
setRepositories(ind=1:6)
options(repos="http://cran.rstudio.com/")
if(!require(devtools)) { install.packages("devtools") }
Install package
library(devtools)
install(".")
First Bug: The above doesn't work.
The code needs a NAMESPACE file in the top directory. Any function that had an @export in the template will need to be represented in the NAMESPACE file as below:
export(func1)
export(func2)
Second Bug: Syntax issue
The NAMESPACE can be generated in R, so I tried to do that, but came across this issue when building the NAMESPACE file using roxygen (http://r-pkgs.had.co.nz/namespace.html):
Error in parse(text = lines, n = -1, srcfile = srcfile) :
/tmp/test/R/ApiResponse.r:47:39: unexpected symbol
46: ApiResponseObject <- jsonlite::fromJSON(ApiResponseJson)
47: self$code <- ApiResponseObject$code
The backtick is in the wrong place, it should be after the dollar sign. Also, the backtick is probably not needed at all unless spaces can appear in the strings.
Third Bug: Use API name in DESCRIPTION
This line:
Package: swagger
will end up conflicting if multiple Swagger packages are installed. Libraries in R are loaded as library(swagger) using the package string. Can "title":"Swagger Petstore" be grabbed instead? The space won't work. Some options: CamelCase or just turn it into all lowercase replacing spaces with underscores or dashes?
Background:
- http://r-pkgs.had.co.nz/package.html (names should be unique)
- https://cran.r-project.org/doc/manuals/r-release/R-exts.html#The-DESCRIPTION-file ([Package] should contain only (ASCII) letters, numbers and dot, have at least two characters and start with a letter and not end in a dot.)
Minor Issue 2:
What is git_push.sh for? Is it necessary? Can it be removed from the code generation?
Fourth Bug: Duplicated code
Response and Element classes are duplicated in several files.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the R client with the documented swagger-codegen-cli command. Inspect the generated README.md, NAMESPACE, R/ApiResponse.r, DESCRIPTION, and git_push.sh, then trace the templates responsible for duplicated Response and Element classes. Done means the generated package installs, parses valid R syntax, uses a suitable package name, and no longer emits unnecessary or duplicated files.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, r
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100