forked from loafle/openapi-generator-original
Fix some bugs for the R client (#6535)
* * Fix bugs in api.mustache, model.mustache, mostly bracket errors or small typos * Added section about installation in README.mustace TODO: fix tests in testthat TODO: fix bug in description.mustace regarding package name * Updates to sample for R client caused by running ./bin/r-petstore.sh (or .\bin\windows\r-petstore.bat) * Add R specific files to .gitignore * [R] add additional files generated by the petstore sample. (see #6520)
This commit is contained in:
parent
5e9d977a03
commit
e3ba06cabb
3
.gitignore
vendored
3
.gitignore
vendored
@ -174,3 +174,6 @@ samples/client/petstore/kotlin/src/main/kotlin/test/
|
||||
.stack-work
|
||||
.cabal-sandbox
|
||||
cabal.project.local
|
||||
|
||||
# R
|
||||
.Rproj.user
|
||||
|
@ -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
|
||||
|
||||
|
@ -36,6 +36,7 @@
|
||||
{{#queryParams}}
|
||||
"{{baseName}}" = {{paramName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/queryParams}}
|
||||
)
|
||||
{{/hasQueryParams}}
|
||||
)
|
||||
|
||||
|
@ -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}}
|
||||
|
34
samples/client/petstore/R/.gitignore
vendored
34
samples/client/petstore/R/.gitignore
vendored
@ -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
samples/client/petstore/R/.swagger-codegen-ignore
Normal file
23
samples/client/petstore/R/.swagger-codegen-ignore
Normal file
@ -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
samples/client/petstore/R/.swagger-codegen/VERSION
Normal file
1
samples/client/petstore/R/.swagger-codegen/VERSION
Normal file
@ -0,0 +1 @@
|
||||
2.3.0-SNAPSHOT
|
3
samples/client/petstore/R/.travis.yml
Normal file
3
samples/client/petstore/R/.travis.yml
Normal file
@ -0,0 +1,3 @@
|
||||
# ref: https://docs.travis-ci.com/user/languages/r/
|
||||
language: r
|
||||
cache: packages
|
@ -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
|
||||
|
||||
|
@ -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
samples/client/petstore/R/R/ApiResponse.r
Normal file
93
samples/client/petstore/R/R/ApiResponse.r
Normal file
@ -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
samples/client/petstore/R/R/Category.r
Normal file
85
samples/client/petstore/R/R/Category.r
Normal file
@ -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
|
||||
}
|
||||
)
|
||||
)
|
116
samples/client/petstore/R/R/Order.r
Normal file
116
samples/client/petstore/R/R/Order.r
Normal file
@ -0,0 +1,116 @@
|
||||
# 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
|
||||
|
||||
|
||||
|
||||
#' Order Class
|
||||
#' @export
|
||||
Order <- R6::R6Class(
|
||||
'Order',
|
||||
public = list(
|
||||
`id` = NULL,
|
||||
`petId` = NULL,
|
||||
`quantity` = NULL,
|
||||
`shipDate` = NULL,
|
||||
`status` = NULL,
|
||||
`complete` = NULL,
|
||||
initialize = function(`id`, `petId`, `quantity`, `shipDate`, `status`, `complete`){
|
||||
if (!missing(`id`)) {
|
||||
stopifnot(is.numeric(`id`), length(`id`) == 1)
|
||||
self$`id` <- `id`
|
||||
}
|
||||
if (!missing(`petId`)) {
|
||||
stopifnot(is.numeric(`petId`), length(`petId`) == 1)
|
||||
self$`petId` <- `petId`
|
||||
}
|
||||
if (!missing(`quantity`)) {
|
||||
stopifnot(is.numeric(`quantity`), length(`quantity`) == 1)
|
||||
self$`quantity` <- `quantity`
|
||||
}
|
||||
if (!missing(`shipDate`)) {
|
||||
stopifnot(is.character(`shipDate`), length(`shipDate`) == 1)
|
||||
self$`shipDate` <- `shipDate`
|
||||
}
|
||||
if (!missing(`status`)) {
|
||||
stopifnot(is.character(`status`), length(`status`) == 1)
|
||||
self$`status` <- `status`
|
||||
}
|
||||
if (!missing(`complete`)) {
|
||||
self$`complete` <- `complete`
|
||||
}
|
||||
},
|
||||
toJSON = function() {
|
||||
sprintf(
|
||||
'{
|
||||
"id": %d,
|
||||
"petId": %d,
|
||||
"quantity": "%s",
|
||||
"shipDate": "%s",
|
||||
"status": "%s",
|
||||
"complete": "%s"
|
||||
}',
|
||||
self$`id`,
|
||||
self$`petId`,
|
||||
self$`quantity`,
|
||||
self$`shipDate`,
|
||||
self$`status`,
|
||||
self$`complete`
|
||||
)
|
||||
},
|
||||
fromJSON = function(OrderJson) {
|
||||
OrderObject <- jsonlite::fromJSON(OrderJson)
|
||||
self$`id` <- OrderObject$`id`
|
||||
self$`petId` <- OrderObject$`petId`
|
||||
self$`quantity` <- OrderObject$`quantity`
|
||||
self$`shipDate` <- OrderObject$`shipDate`
|
||||
self$`status` <- OrderObject$`status`
|
||||
self$`complete` <- OrderObject$`complete`
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
#' 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
|
||||
}
|
||||
)
|
||||
)
|
154
samples/client/petstore/R/R/PetApi.r
Normal file
154
samples/client/petstore/R/R/PetApi.r
Normal file
@ -0,0 +1,154 @@
|
||||
# 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
|
||||
|
||||
PetApi <- R6::R6Class(
|
||||
'PetApi',
|
||||
public = list(
|
||||
userAgent = "Swagger-Codegen/1.0.0/r",
|
||||
basePath = "http://petstore.swagger.io/v2",
|
||||
initialize = function(basePath){
|
||||
if (!missing(basePath)) {
|
||||
stopifnot(is.character(basePath), length(basePath) == 1)
|
||||
self$basePath <- basePath
|
||||
}
|
||||
},
|
||||
|
||||
add_pet = function(body){
|
||||
resp <- httr::POST(paste0(self$basePath),
|
||||
httr::add_headers("User-Agent" = self$userAgent, "accept" = "application/json", "content-type" = "application/xml")
|
||||
,body = body$toJSON()
|
||||
)
|
||||
|
||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
||||
# void response, no need to return anything
|
||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
||||
Response$new("API client error", resp)
|
||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
||||
Response$new("API server error", resp)
|
||||
}
|
||||
|
||||
},
|
||||
delete_pet = function(pet_id, api_key){
|
||||
resp <- httr::DELETE(paste0(self$basePath, pet_id),
|
||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml", "api_key" = api_key)
|
||||
)
|
||||
|
||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
||||
# void response, no need to return anything
|
||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
||||
Response$new("API client error", resp)
|
||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
||||
Response$new("API server error", resp)
|
||||
}
|
||||
|
||||
},
|
||||
find_pets_by_status = function(status){
|
||||
resp <- httr::GET(paste0(self$basePath),
|
||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
||||
,query = list(
|
||||
"status" = status
|
||||
)
|
||||
)
|
||||
|
||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
||||
result <- Pet$new()$fromJSON(httr::content(resp, "text", encoding = "UTF-8"), simplifyVector = FALSE)
|
||||
Response$new(result, resp)
|
||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
||||
Response$new("API client error", resp)
|
||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
||||
Response$new("API server error", resp)
|
||||
}
|
||||
|
||||
},
|
||||
find_pets_by_tags = function(tags){
|
||||
resp <- httr::GET(paste0(self$basePath),
|
||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
||||
,query = list(
|
||||
"tags" = tags
|
||||
)
|
||||
)
|
||||
|
||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
||||
result <- Pet$new()$fromJSON(httr::content(resp, "text", encoding = "UTF-8"), simplifyVector = FALSE)
|
||||
Response$new(result, resp)
|
||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
||||
Response$new("API client error", resp)
|
||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
||||
Response$new("API server error", resp)
|
||||
}
|
||||
|
||||
},
|
||||
get_pet_by_id = function(pet_id){
|
||||
resp <- httr::GET(paste0(self$basePath, pet_id),
|
||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
||||
)
|
||||
|
||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
||||
result <- Pet$new()$fromJSON(httr::content(resp, "text", encoding = "UTF-8"), simplifyVector = FALSE)
|
||||
Response$new(result, resp)
|
||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
||||
Response$new("API client error", resp)
|
||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
||||
Response$new("API server error", resp)
|
||||
}
|
||||
|
||||
},
|
||||
update_pet = function(body){
|
||||
resp <- httr::PUT(paste0(self$basePath),
|
||||
httr::add_headers("User-Agent" = self$userAgent, "accept" = "application/json", "content-type" = "application/xml")
|
||||
,body = body$toJSON()
|
||||
)
|
||||
|
||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
||||
# void response, no need to return anything
|
||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
||||
Response$new("API client error", resp)
|
||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
||||
Response$new("API server error", resp)
|
||||
}
|
||||
|
||||
},
|
||||
update_pet_with_form = function(pet_id, name, status){
|
||||
resp <- httr::POST(paste0(self$basePath, pet_id),
|
||||
httr::add_headers("User-Agent" = self$userAgent, "accept" = "application/x-www-form-urlencoded", "content-type" = "application/xml")
|
||||
,body = list(
|
||||
"name" = name,
|
||||
"status" = status
|
||||
)
|
||||
)
|
||||
|
||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
||||
# void response, no need to return anything
|
||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
||||
Response$new("API client error", resp)
|
||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
||||
Response$new("API server error", resp)
|
||||
}
|
||||
|
||||
},
|
||||
upload_file = function(pet_id, additional_metadata, file){
|
||||
resp <- httr::POST(paste0(self$basePath, pet_id),
|
||||
httr::add_headers("User-Agent" = self$userAgent, "accept" = "multipart/form-data", "content-type" = "application/json")
|
||||
,body = list(
|
||||
"additionalMetadata" = additional_metadata,
|
||||
"file" = httr::upload_file(file)
|
||||
)
|
||||
)
|
||||
|
||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
||||
result <- ApiResponse$new()$fromJSON(httr::content(resp, "text", encoding = "UTF-8"), simplifyVector = FALSE)
|
||||
Response$new(result, resp)
|
||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
||||
Response$new("API client error", resp)
|
||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
||||
Response$new("API server error", resp)
|
||||
}
|
||||
|
||||
}
|
||||
)
|
||||
)
|
82
samples/client/petstore/R/R/StoreApi.r
Normal file
82
samples/client/petstore/R/R/StoreApi.r
Normal file
@ -0,0 +1,82 @@
|
||||
# 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
|
||||
|
||||
StoreApi <- R6::R6Class(
|
||||
'StoreApi',
|
||||
public = list(
|
||||
userAgent = "Swagger-Codegen/1.0.0/r",
|
||||
basePath = "http://petstore.swagger.io/v2",
|
||||
initialize = function(basePath){
|
||||
if (!missing(basePath)) {
|
||||
stopifnot(is.character(basePath), length(basePath) == 1)
|
||||
self$basePath <- basePath
|
||||
}
|
||||
},
|
||||
|
||||
delete_order = function(order_id){
|
||||
resp <- httr::DELETE(paste0(self$basePath, order_id),
|
||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
||||
)
|
||||
|
||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
||||
# void response, no need to return anything
|
||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
||||
Response$new("API client error", resp)
|
||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
||||
Response$new("API server error", resp)
|
||||
}
|
||||
|
||||
},
|
||||
get_inventory = function(){
|
||||
resp <- httr::GET(paste0(self$basePath),
|
||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/json")
|
||||
)
|
||||
|
||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
||||
result <- Integer$new()$fromJSON(httr::content(resp, "text", encoding = "UTF-8"), simplifyVector = FALSE)
|
||||
Response$new(result, resp)
|
||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
||||
Response$new("API client error", resp)
|
||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
||||
Response$new("API server error", resp)
|
||||
}
|
||||
|
||||
},
|
||||
get_order_by_id = function(order_id){
|
||||
resp <- httr::GET(paste0(self$basePath, order_id),
|
||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
||||
)
|
||||
|
||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
||||
result <- Order$new()$fromJSON(httr::content(resp, "text", encoding = "UTF-8"), simplifyVector = FALSE)
|
||||
Response$new(result, resp)
|
||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
||||
Response$new("API client error", resp)
|
||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
||||
Response$new("API server error", resp)
|
||||
}
|
||||
|
||||
},
|
||||
place_order = function(body){
|
||||
resp <- httr::POST(paste0(self$basePath),
|
||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
||||
,body = body$toJSON()
|
||||
)
|
||||
|
||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
||||
result <- Order$new()$fromJSON(httr::content(resp, "text", encoding = "UTF-8"), simplifyVector = FALSE)
|
||||
Response$new(result, resp)
|
||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
||||
Response$new("API client error", resp)
|
||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
||||
Response$new("API server error", resp)
|
||||
}
|
||||
|
||||
}
|
||||
)
|
||||
)
|
85
samples/client/petstore/R/R/Tag.r
Normal file
85
samples/client/petstore/R/R/Tag.r
Normal file
@ -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
|
||||
|
||||
|
||||
|
||||
#' Tag Class
|
||||
#' @export
|
||||
Tag <- R6::R6Class(
|
||||
'Tag',
|
||||
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(TagJson) {
|
||||
TagObject <- jsonlite::fromJSON(TagJson)
|
||||
self$`id` <- TagObject$`id`
|
||||
self$`name` <- TagObject$`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
|
||||
}
|
||||
)
|
||||
)
|
133
samples/client/petstore/R/R/User.r
Normal file
133
samples/client/petstore/R/R/User.r
Normal file
@ -0,0 +1,133 @@
|
||||
# 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
|
||||
|
||||
|
||||
|
||||
#' User Class
|
||||
#' @export
|
||||
User <- R6::R6Class(
|
||||
'User',
|
||||
public = list(
|
||||
`id` = NULL,
|
||||
`username` = NULL,
|
||||
`firstName` = NULL,
|
||||
`lastName` = NULL,
|
||||
`email` = NULL,
|
||||
`password` = NULL,
|
||||
`phone` = NULL,
|
||||
`userStatus` = NULL,
|
||||
initialize = function(`id`, `username`, `firstName`, `lastName`, `email`, `password`, `phone`, `userStatus`){
|
||||
if (!missing(`id`)) {
|
||||
stopifnot(is.numeric(`id`), length(`id`) == 1)
|
||||
self$`id` <- `id`
|
||||
}
|
||||
if (!missing(`username`)) {
|
||||
stopifnot(is.character(`username`), length(`username`) == 1)
|
||||
self$`username` <- `username`
|
||||
}
|
||||
if (!missing(`firstName`)) {
|
||||
stopifnot(is.character(`firstName`), length(`firstName`) == 1)
|
||||
self$`firstName` <- `firstName`
|
||||
}
|
||||
if (!missing(`lastName`)) {
|
||||
stopifnot(is.character(`lastName`), length(`lastName`) == 1)
|
||||
self$`lastName` <- `lastName`
|
||||
}
|
||||
if (!missing(`email`)) {
|
||||
stopifnot(is.character(`email`), length(`email`) == 1)
|
||||
self$`email` <- `email`
|
||||
}
|
||||
if (!missing(`password`)) {
|
||||
stopifnot(is.character(`password`), length(`password`) == 1)
|
||||
self$`password` <- `password`
|
||||
}
|
||||
if (!missing(`phone`)) {
|
||||
stopifnot(is.character(`phone`), length(`phone`) == 1)
|
||||
self$`phone` <- `phone`
|
||||
}
|
||||
if (!missing(`userStatus`)) {
|
||||
stopifnot(is.numeric(`userStatus`), length(`userStatus`) == 1)
|
||||
self$`userStatus` <- `userStatus`
|
||||
}
|
||||
},
|
||||
toJSON = function() {
|
||||
sprintf(
|
||||
'{
|
||||
"id": %d,
|
||||
"username": "%s",
|
||||
"firstName": "%s",
|
||||
"lastName": "%s",
|
||||
"email": "%s",
|
||||
"password": "%s",
|
||||
"phone": "%s",
|
||||
"userStatus": "%s"
|
||||
}',
|
||||
self$`id`,
|
||||
self$`username`,
|
||||
self$`firstName`,
|
||||
self$`lastName`,
|
||||
self$`email`,
|
||||
self$`password`,
|
||||
self$`phone`,
|
||||
self$`userStatus`
|
||||
)
|
||||
},
|
||||
fromJSON = function(UserJson) {
|
||||
UserObject <- jsonlite::fromJSON(UserJson)
|
||||
self$`id` <- UserObject$`id`
|
||||
self$`username` <- UserObject$`username`
|
||||
self$`firstName` <- UserObject$`firstName`
|
||||
self$`lastName` <- UserObject$`lastName`
|
||||
self$`email` <- UserObject$`email`
|
||||
self$`password` <- UserObject$`password`
|
||||
self$`phone` <- UserObject$`phone`
|
||||
self$`userStatus` <- UserObject$`userStatus`
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
#' 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
|
||||
}
|
||||
)
|
||||
)
|
144
samples/client/petstore/R/R/UserApi.r
Normal file
144
samples/client/petstore/R/R/UserApi.r
Normal file
@ -0,0 +1,144 @@
|
||||
# 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
|
||||
|
||||
UserApi <- R6::R6Class(
|
||||
'UserApi',
|
||||
public = list(
|
||||
userAgent = "Swagger-Codegen/1.0.0/r",
|
||||
basePath = "http://petstore.swagger.io/v2",
|
||||
initialize = function(basePath){
|
||||
if (!missing(basePath)) {
|
||||
stopifnot(is.character(basePath), length(basePath) == 1)
|
||||
self$basePath <- basePath
|
||||
}
|
||||
},
|
||||
|
||||
create_user = function(body){
|
||||
resp <- httr::POST(paste0(self$basePath),
|
||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
||||
,body = body$toJSON()
|
||||
)
|
||||
|
||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
||||
# void response, no need to return anything
|
||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
||||
Response$new("API client error", resp)
|
||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
||||
Response$new("API server error", resp)
|
||||
}
|
||||
|
||||
},
|
||||
create_users_with_array_input = function(body){
|
||||
resp <- httr::POST(paste0(self$basePath),
|
||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
||||
,body = body$toJSON()
|
||||
)
|
||||
|
||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
||||
# void response, no need to return anything
|
||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
||||
Response$new("API client error", resp)
|
||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
||||
Response$new("API server error", resp)
|
||||
}
|
||||
|
||||
},
|
||||
create_users_with_list_input = function(body){
|
||||
resp <- httr::POST(paste0(self$basePath),
|
||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
||||
,body = body$toJSON()
|
||||
)
|
||||
|
||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
||||
# void response, no need to return anything
|
||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
||||
Response$new("API client error", resp)
|
||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
||||
Response$new("API server error", resp)
|
||||
}
|
||||
|
||||
},
|
||||
delete_user = function(username){
|
||||
resp <- httr::DELETE(paste0(self$basePath, username),
|
||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
||||
)
|
||||
|
||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
||||
# void response, no need to return anything
|
||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
||||
Response$new("API client error", resp)
|
||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
||||
Response$new("API server error", resp)
|
||||
}
|
||||
|
||||
},
|
||||
get_user_by_name = function(username){
|
||||
resp <- httr::GET(paste0(self$basePath, username),
|
||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
||||
)
|
||||
|
||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
||||
result <- User$new()$fromJSON(httr::content(resp, "text", encoding = "UTF-8"), simplifyVector = FALSE)
|
||||
Response$new(result, resp)
|
||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
||||
Response$new("API client error", resp)
|
||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
||||
Response$new("API server error", resp)
|
||||
}
|
||||
|
||||
},
|
||||
login_user = function(username, password){
|
||||
resp <- httr::GET(paste0(self$basePath),
|
||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
||||
,query = list(
|
||||
"username" = username,
|
||||
"password" = password
|
||||
)
|
||||
)
|
||||
|
||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
||||
result <- Character$new()$fromJSON(httr::content(resp, "text", encoding = "UTF-8"), simplifyVector = FALSE)
|
||||
Response$new(result, resp)
|
||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
||||
Response$new("API client error", resp)
|
||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
||||
Response$new("API server error", resp)
|
||||
}
|
||||
|
||||
},
|
||||
logout_user = function(){
|
||||
resp <- httr::GET(paste0(self$basePath),
|
||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
||||
)
|
||||
|
||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
||||
# void response, no need to return anything
|
||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
||||
Response$new("API client error", resp)
|
||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
||||
Response$new("API server error", resp)
|
||||
}
|
||||
|
||||
},
|
||||
update_user = function(username, body){
|
||||
resp <- httr::PUT(paste0(self$basePath, username),
|
||||
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
|
||||
,body = body$toJSON()
|
||||
)
|
||||
|
||||
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
|
||||
# void response, no need to return anything
|
||||
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499){
|
||||
Response$new("API client error", resp)
|
||||
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599){
|
||||
Response$new("API server error", resp)
|
||||
}
|
||||
|
||||
}
|
||||
)
|
||||
)
|
@ -1,64 +1,79 @@
|
||||
#' Pet Class
|
||||
#'
|
||||
# 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
|
||||
|
||||
|
||||
|
||||
#' Pet Class
|
||||
#' @export
|
||||
Pet <- R6::R6Class(
|
||||
Pet <- R6::R6Class(
|
||||
'Pet',
|
||||
public = list(
|
||||
id = NULL,
|
||||
category = NULL,
|
||||
name = NULL,
|
||||
photoUrls = NULL,
|
||||
tags = NULL,
|
||||
status = NULL,
|
||||
initialize = function(id,category,name,photoUrls,tags,status){
|
||||
if (!missing(id)) {
|
||||
stopifnot(is.numeric(id), length(id) == 1)
|
||||
self$id <- id
|
||||
`id` = NULL,
|
||||
`category` = NULL,
|
||||
`name` = NULL,
|
||||
`photoUrls` = NULL,
|
||||
`tags` = NULL,
|
||||
`status` = NULL,
|
||||
initialize = function(`id`, `category`, `name`, `photoUrls`, `tags`, `status`){
|
||||
if (!missing(`id`)) {
|
||||
stopifnot(is.numeric(`id`), length(`id`) == 1)
|
||||
self$`id` <- `id`
|
||||
}
|
||||
if (!missing(category)) {
|
||||
stopifnot("Element" %in% class(category), !is.list(category))
|
||||
self$category <- category
|
||||
}
|
||||
if (!missing(name)) {
|
||||
stopifnot(is.character(name), length(name) == 1)
|
||||
self$name <- name
|
||||
}
|
||||
if (!missing(photoUrls)) {
|
||||
stopifnot(is.list(photoUrls), length(photoUrls) != 0)
|
||||
lapply(photoUrls, function(x) stopifnot(is.character(x)))
|
||||
self$photoUrls <- photoUrls
|
||||
}
|
||||
if (!missing(tags)) {
|
||||
if (!missing(`category`)) {
|
||||
stopifnot(is.list(tags), length(tags) != 0)
|
||||
lapply(tags, function(x) stopifnot("Element" %in% class(x), !is.list(x)))
|
||||
self$tags <- tags
|
||||
lapply(`category`, function(x) stopifnot("Element" %in% class(x), !is.list(x)))
|
||||
self$`category` <- `category`
|
||||
}
|
||||
if (!missing(status)) {
|
||||
stopifnot(is.character(status), length(status) == 1)
|
||||
self$status <- status
|
||||
if (!missing(`name`)) {
|
||||
stopifnot(is.character(`name`), length(`name`) == 1)
|
||||
self$`name` <- `name`
|
||||
}
|
||||
if (!missing(`photoUrls`)) {
|
||||
stopifnot(is.list(`photoUrls`), length(`photoUrls`) != 0)
|
||||
lapply(`photoUrls`, function(x) stopifnot(is.character(x)))
|
||||
self$`photoUrls` <- `photoUrls`
|
||||
}
|
||||
if (!missing(`tags`)) {
|
||||
stopifnot(is.list(tags), length(tags) != 0)
|
||||
lapply(`tags`, function(x) stopifnot("Element" %in% class(x), !is.list(x)))
|
||||
self$`tags` <- `tags`
|
||||
}
|
||||
if (!missing(`status`)) {
|
||||
stopifnot(is.character(`status`), length(`status`) == 1)
|
||||
self$`status` <- `status`
|
||||
}
|
||||
},
|
||||
toJson = function() {
|
||||
toJSON = function() {
|
||||
sprintf(
|
||||
'{
|
||||
"id": %d,
|
||||
"category": {
|
||||
"id": %d,
|
||||
"name": "%s"
|
||||
},
|
||||
"category": %s,
|
||||
"name": "%s",
|
||||
"photoUrls": [%s],
|
||||
"tags": [%s],
|
||||
"status": "%s"
|
||||
"photoUrls": ["%s"],
|
||||
"tags": [%s],
|
||||
"status": "%s"
|
||||
}',
|
||||
self$id,
|
||||
self$category$id,
|
||||
self$category$name,
|
||||
self$name,
|
||||
lapply(self$photoUrls, function(x) paste(paste0('"', x, '"'), sep=",")),
|
||||
lapply(self$tags, function(x) paste(x$toJson(), sep=",")),
|
||||
self$status)
|
||||
self$`id`,
|
||||
self$`category`$toJSON(),
|
||||
self$`name`,
|
||||
lapply(self$`photoUrls`, function(x) paste(paste0('"', x, '"'), sep=",")),
|
||||
lapply(self$`tags`, function(x) paste(x$toJSON(), sep=",")),
|
||||
self$`status`
|
||||
)
|
||||
},
|
||||
fromJSON = function(PetJson) {
|
||||
PetObject <- jsonlite::fromJSON(PetJson)
|
||||
self$`id` <- PetObject$`id`
|
||||
self$`category` <- Category$new()$fromJSON(jsonlite::toJSON(PetObject$category))
|
||||
self$`name` <- PetObject$`name`
|
||||
self$`photoUrls` <- PetObject$`photoUrls`
|
||||
self$`tags` <- lapply(PetObject$`tags`, function(x) Tag$new()$fromJSON(jsonlite::toJSON(x)))
|
||||
self$`status` <- PetObject$`status`
|
||||
}
|
||||
)
|
||||
)
|
||||
@ -82,7 +97,7 @@ Element <- R6::R6Class(
|
||||
self$name <- name
|
||||
}
|
||||
},
|
||||
toJson = function() {
|
||||
toJSON = function() {
|
||||
sprintf('{"id":%d,"name":"%s"}', self$id, self$name)
|
||||
}
|
||||
)
|
||||
@ -102,4 +117,4 @@ Response <- R6::R6Class(
|
||||
self$response <- response
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -1 +1,33 @@
|
||||
https://github.com/swagger-api/swagger-codegen/issues/2231
|
||||
# R API client for swagger
|
||||
|
||||
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.
|
||||
|
||||
## Overview
|
||||
This API client was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the [OpenAPI/Swagger spec](https://github.com/swagger-api/swagger-spec) from a remote server, you can easily generate an API client.
|
||||
|
||||
- API version: 1.0.0
|
||||
- Package version: 1.0.0
|
||||
- Build package: io.swagger.codegen.languages.RClientCodegen
|
||||
|
||||
## 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.
|
||||
|
||||
### 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
|
||||
|
||||
apiteam@swagger.io
|
||||
|
||||
|
52
samples/client/petstore/R/git_push.sh
Normal file
52
samples/client/petstore/R/git_push.sh
Normal file
@ -0,0 +1,52 @@
|
||||
#!/bin/sh
|
||||
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
|
||||
#
|
||||
# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update"
|
||||
|
||||
git_user_id=$1
|
||||
git_repo_id=$2
|
||||
release_note=$3
|
||||
|
||||
if [ "$git_user_id" = "" ]; then
|
||||
git_user_id="GIT_USER_ID"
|
||||
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
|
||||
fi
|
||||
|
||||
if [ "$git_repo_id" = "" ]; then
|
||||
git_repo_id="GIT_REPO_ID"
|
||||
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
|
||||
fi
|
||||
|
||||
if [ "$release_note" = "" ]; then
|
||||
release_note="Minor update"
|
||||
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
|
||||
fi
|
||||
|
||||
# Initialize the local directory as a Git repository
|
||||
git init
|
||||
|
||||
# Adds the files in the local repository and stages them for commit.
|
||||
git add .
|
||||
|
||||
# Commits the tracked changes and prepares them to be pushed to a remote repository.
|
||||
git commit -m "$release_note"
|
||||
|
||||
# Sets the new remote
|
||||
git_remote=`git remote`
|
||||
if [ "$git_remote" = "" ]; then # git remote not defined
|
||||
|
||||
if [ "$GIT_TOKEN" = "" ]; then
|
||||
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment."
|
||||
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
|
||||
else
|
||||
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
git pull origin master
|
||||
|
||||
# Pushes (Forces) the changes in the local repository up to the remote repository
|
||||
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
|
||||
git push origin master 2>&1 | grep -v 'To https'
|
||||
|
@ -1,14 +1,40 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/pet.R
|
||||
% Please edit documentation in R/ApiResponse.r, R/Category.r, R/Order.r,
|
||||
% R/Tag.r, R/User.r, R/pet.R
|
||||
\docType{data}
|
||||
\name{Element}
|
||||
\alias{Element}
|
||||
\alias{Element}
|
||||
\alias{Element}
|
||||
\alias{Element}
|
||||
\alias{Element}
|
||||
\alias{Element}
|
||||
\title{Element Class}
|
||||
\format{An object of class \code{R6ClassGenerator} of length 24.}
|
||||
\usage{
|
||||
Element
|
||||
|
||||
Element
|
||||
|
||||
Element
|
||||
|
||||
Element
|
||||
|
||||
Element
|
||||
|
||||
Element
|
||||
}
|
||||
\description{
|
||||
Element Class
|
||||
|
||||
Element Class
|
||||
|
||||
Element Class
|
||||
|
||||
Element Class
|
||||
|
||||
Element Class
|
||||
|
||||
Element Class
|
||||
}
|
||||
\keyword{datasets}
|
||||
|
@ -1,14 +1,40 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/pet.R
|
||||
% Please edit documentation in R/ApiResponse.r, R/Category.r, R/Order.r,
|
||||
% R/Tag.r, R/User.r, R/pet.R
|
||||
\docType{data}
|
||||
\name{Response}
|
||||
\alias{Response}
|
||||
\alias{Response}
|
||||
\alias{Response}
|
||||
\alias{Response}
|
||||
\alias{Response}
|
||||
\alias{Response}
|
||||
\title{Response Class}
|
||||
\format{An object of class \code{R6ClassGenerator} of length 24.}
|
||||
\usage{
|
||||
Response
|
||||
|
||||
Response
|
||||
|
||||
Response
|
||||
|
||||
Response
|
||||
|
||||
Response
|
||||
|
||||
Response
|
||||
}
|
||||
\description{
|
||||
Response Class
|
||||
|
||||
Response Class
|
||||
|
||||
Response Class
|
||||
|
||||
Response Class
|
||||
|
||||
Response Class
|
||||
|
||||
Response Class
|
||||
}
|
||||
\keyword{datasets}
|
||||
|
@ -5,8 +5,13 @@ SaveWorkspace: No
|
||||
AlwaysSaveHistory: Default
|
||||
|
||||
EnableCodeIndexing: Yes
|
||||
UseSpacesForTab: Yes
|
||||
NumSpacesForTab: 4
|
||||
Encoding: UTF-8
|
||||
|
||||
RnwWeave: Sweave
|
||||
LaTeX: pdfLaTeX
|
||||
|
||||
AutoAppendNewline: Yes
|
||||
StripTrailingWhitespace: Yes
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user