Skip to content

[R] Issues with R Codegen Clients  #6520

Open
@cannin

Description

@cannin

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions