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

[R] Fix some bugs for the R client #6535

Merged
merged 4 commits into from
Sep 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,6 @@ samples/client/petstore/kotlin/src/main/kotlin/test/
.stack-work
.cabal-sandbox
cabal.project.local

# R
.Rproj.user
16 changes: 15 additions & 1 deletion modules/swagger-codegen/src/main/resources/r/README.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,22 @@ For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
{{/infoUrl}}

## Installation
You'll need the `devtools` package in order to build the API.
Make sure you have a proper CRAN repository from which you can download packages.

TODO
### Prerequisites
Install the `devtools` package with the following command.
```R
if(!require(devtools)) { install.packages("devtools") }
```

### Installation of the API package
Make sure you set the working directory to where the API code is located.
Then execute
```R
library(devtools)
install(".")
```

## Author

Expand Down
1 change: 1 addition & 0 deletions modules/swagger-codegen/src/main/resources/r/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
{{#queryParams}}
"{{baseName}}" = {{paramName}}{{#hasMore}},{{/hasMore}}
{{/queryParams}}
)
{{/hasQueryParams}}
)

Expand Down
6 changes: 3 additions & 3 deletions modules/swagger-codegen/src/main/resources/r/model.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@
{{classname}}Object <- jsonlite::fromJSON({{classname}}Json)
{{#vars}}
{{#isPrimitiveType}}
self$`{{baseName}}` <- {{classname}}Object`${{baseName}}`
self$`{{baseName}}` <- {{classname}}Object$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#isListContainer}}
self$`{{baseName}}` <- lapply({{classname}}Object$`{{baseName}}`, function(x) {{datatype}}$new()$fromJSON(jsonlite::toJSON(x))
self$`{{baseName}}` <- lapply({{classname}}Object$`{{baseName}}`, function(x) {{datatype}}$new()$fromJSON(jsonlite::toJSON(x)))
{{/isListContainer}}
{{^isListContainer}}
self$`{{baseName}}` <- {{datatype}}$new()$fromJSON(jsonlite::toJSON({{classname}}Object${{baseName}))
self$`{{baseName}}` <- {{datatype}}$new()$fromJSON(jsonlite::toJSON({{classname}}Object${{baseName}}))
{{/isListContainer}}
{{/isPrimitiveType}}
{{/vars}}
Expand Down
34 changes: 33 additions & 1 deletion samples/client/petstore/R/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
.Rproj.user
# ref: https://github.com/github/gitignore/blob/master/R.gitignore

# History files
.Rhistory
.Rapp.history

# Session Data files
.RData

# Example code in package build process
*-Ex.R

# Output files from R CMD build
/*.tar.gz

# Output files from R CMD check
/*.Rcheck/

# RStudio files
.Rproj.user/

# produced vignettes
vignettes/*.html
vignettes/*.pdf

# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth

# knitr and R markdown default cache directories
/*_cache/
/cache/

# Temporary files created by R markdown
*.utf8.md
*.knit.md
23 changes: 23 additions & 0 deletions samples/client/petstore/R/.swagger-codegen-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Swagger Codegen Ignore
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
1 change: 1 addition & 0 deletions samples/client/petstore/R/.swagger-codegen/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.3.0-SNAPSHOT
3 changes: 3 additions & 0 deletions samples/client/petstore/R/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ref: https://docs.travis-ci.com/user/languages/r/
language: r
cache: packages
11 changes: 5 additions & 6 deletions samples/client/petstore/R/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
Package: petstore
Title: R Package Client for <http://swagger.io> Petstore APIs
Version: 0.0.0.9000
Authors@R: person("Ramkumar", "Chandrasekaran", email = "ramkumar.november@gmail.com", role = c("aut", "cre"))
Description: R Package Client for <http://swagger.io> Petstore APIs.
Title: R Package Client for Swagger Petstore
Version: 1.0.0
Authors@R: person("Swagger Codegen community", email = "apiteam@swagger.io", role = c("aut", "cre"))
Description: This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
Depends: R (>= 3.3.3)
Encoding: UTF-8
License: MIT
License: Unlicense
LazyData: true
Suggests: testthat
Imports: jsonlite, httr, R6
RoxygenNote: 6.0.1.9000

5 changes: 5 additions & 0 deletions samples/client/petstore/R/NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Generated by roxygen2: do not edit by hand

export(ApiResponse)
export(Category)
export(Element)
export(Order)
export(Pet)
export(PetStoreClient)
export(Response)
export(Tag)
export(User)
93 changes: 93 additions & 0 deletions samples/client/petstore/R/R/ApiResponse.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Swagger Petstore
#
# This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
#
# OpenAPI spec version: 1.0.0
# Contact: apiteam@swagger.io
# Generated by: https://github.com/swagger-api/swagger-codegen.git



#' ApiResponse Class
#' @export
ApiResponse <- R6::R6Class(
'ApiResponse',
public = list(
`code` = NULL,
`type` = NULL,
`message` = NULL,
initialize = function(`code`, `type`, `message`){
if (!missing(`code`)) {
stopifnot(is.numeric(`code`), length(`code`) == 1)
self$`code` <- `code`
}
if (!missing(`type`)) {
stopifnot(is.character(`type`), length(`type`) == 1)
self$`type` <- `type`
}
if (!missing(`message`)) {
stopifnot(is.character(`message`), length(`message`) == 1)
self$`message` <- `message`
}
},
toJSON = function() {
sprintf(
'{
"code": "%s",
"type": "%s",
"message": "%s"
}',
self$`code`,
self$`type`,
self$`message`
)
},
fromJSON = function(ApiResponseJson) {
ApiResponseObject <- jsonlite::fromJSON(ApiResponseJson)
self$`code` <- ApiResponseObject$`code`
self$`type` <- ApiResponseObject$`type`
self$`message` <- ApiResponseObject$`message`
}
)
)

#' Element Class
#'
#' Element Class
#' @export
Element <- R6::R6Class(
'Element',
public = list(
id = NULL,
name = NULL,
initialize = function(id,name){
if (!missing(id)) {
stopifnot(is.numeric(id), length(id) == 1)
self$id <- id
}
if (!missing(name)) {
stopifnot(is.character(name), length(name) == 1)
self$name <- name
}
},
toJSON = function() {
sprintf('{"id":%d,"name":"%s"}', self$id, self$name)
}
)
)

#' Response Class
#'
#' Response Class
#' @export
Response <- R6::R6Class(
'Response',
public = list(
content = NULL,
response = NULL,
initialize = function(content, response){
self$content <- content
self$response <- response
}
)
)
85 changes: 85 additions & 0 deletions samples/client/petstore/R/R/Category.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Swagger Petstore
#
# This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
#
# OpenAPI spec version: 1.0.0
# Contact: apiteam@swagger.io
# Generated by: https://github.com/swagger-api/swagger-codegen.git



#' Category Class
#' @export
Category <- R6::R6Class(
'Category',
public = list(
`id` = NULL,
`name` = NULL,
initialize = function(`id`, `name`){
if (!missing(`id`)) {
stopifnot(is.numeric(`id`), length(`id`) == 1)
self$`id` <- `id`
}
if (!missing(`name`)) {
stopifnot(is.character(`name`), length(`name`) == 1)
self$`name` <- `name`
}
},
toJSON = function() {
sprintf(
'{
"id": %d,
"name": "%s"
}',
self$`id`,
self$`name`
)
},
fromJSON = function(CategoryJson) {
CategoryObject <- jsonlite::fromJSON(CategoryJson)
self$`id` <- CategoryObject$`id`
self$`name` <- CategoryObject$`name`
}
)
)

#' Element Class
#'
#' Element Class
#' @export
Element <- R6::R6Class(
'Element',
public = list(
id = NULL,
name = NULL,
initialize = function(id,name){
if (!missing(id)) {
stopifnot(is.numeric(id), length(id) == 1)
self$id <- id
}
if (!missing(name)) {
stopifnot(is.character(name), length(name) == 1)
self$name <- name
}
},
toJSON = function() {
sprintf('{"id":%d,"name":"%s"}', self$id, self$name)
}
)
)

#' Response Class
#'
#' Response Class
#' @export
Response <- R6::R6Class(
'Response',
public = list(
content = NULL,
response = NULL,
initialize = function(content, response){
self$content <- content
self$response <- response
}
)
)
Loading