From 360bb0fd9efc33b9f93aaab117cf930dd544e2ab Mon Sep 17 00:00:00 2001 From: Jakob Schelbert Date: Thu, 21 Sep 2017 16:31:15 +0200 Subject: [PATCH 1/4] * 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 --- .../src/main/resources/r/README.mustache | 16 +++++++++++++++- .../src/main/resources/r/api.mustache | 1 + .../src/main/resources/r/model.mustache | 6 +++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/r/README.mustache b/modules/swagger-codegen/src/main/resources/r/README.mustache index 0bf65d4f3ab..a79bef44805 100644 --- a/modules/swagger-codegen/src/main/resources/r/README.mustache +++ b/modules/swagger-codegen/src/main/resources/r/README.mustache @@ -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 diff --git a/modules/swagger-codegen/src/main/resources/r/api.mustache b/modules/swagger-codegen/src/main/resources/r/api.mustache index b863deee4d0..74d07116c1f 100644 --- a/modules/swagger-codegen/src/main/resources/r/api.mustache +++ b/modules/swagger-codegen/src/main/resources/r/api.mustache @@ -36,6 +36,7 @@ {{#queryParams}} "{{baseName}}" = {{paramName}}{{#hasMore}},{{/hasMore}} {{/queryParams}} + ) {{/hasQueryParams}} ) diff --git a/modules/swagger-codegen/src/main/resources/r/model.mustache b/modules/swagger-codegen/src/main/resources/r/model.mustache index dcd3fa4febf..bcdbf152b5e 100644 --- a/modules/swagger-codegen/src/main/resources/r/model.mustache +++ b/modules/swagger-codegen/src/main/resources/r/model.mustache @@ -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}} From 62ef70d9fd5455be10450f324ac5085768107811 Mon Sep 17 00:00:00 2001 From: Jakob Schelbert Date: Thu, 21 Sep 2017 17:15:16 +0200 Subject: [PATCH 2/4] Updates to sample for R client caused by running ./bin/r-petstore.sh (or .\bin\windows\r-petstore.bat) --- samples/client/petstore/R/.gitignore | 34 ++++++- samples/client/petstore/R/DESCRIPTION | 11 +-- samples/client/petstore/R/NAMESPACE | 5 + samples/client/petstore/R/R/pet.R | 107 ++++++++++++---------- samples/client/petstore/R/README.md | 34 ++++++- samples/client/petstore/R/man/Element.Rd | 28 +++++- samples/client/petstore/R/man/Response.Rd | 28 +++++- samples/client/petstore/R/petstore.Rproj | 5 + 8 files changed, 196 insertions(+), 56 deletions(-) diff --git a/samples/client/petstore/R/.gitignore b/samples/client/petstore/R/.gitignore index 807ea251739..5d21150e0ca 100644 --- a/samples/client/petstore/R/.gitignore +++ b/samples/client/petstore/R/.gitignore @@ -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 diff --git a/samples/client/petstore/R/DESCRIPTION b/samples/client/petstore/R/DESCRIPTION index 85732b23fd9..a4aa2089c8b 100644 --- a/samples/client/petstore/R/DESCRIPTION +++ b/samples/client/petstore/R/DESCRIPTION @@ -1,13 +1,12 @@ Package: petstore -Title: R Package Client for 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 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 - diff --git a/samples/client/petstore/R/NAMESPACE b/samples/client/petstore/R/NAMESPACE index 5c892f91298..dfeda0ceae8 100644 --- a/samples/client/petstore/R/NAMESPACE +++ b/samples/client/petstore/R/NAMESPACE @@ -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) diff --git a/samples/client/petstore/R/R/pet.R b/samples/client/petstore/R/R/pet.R index e51d8a7eb23..849a0d5c642 100644 --- a/samples/client/petstore/R/R/pet.R +++ b/samples/client/petstore/R/R/pet.R @@ -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(`category`)) { + stopifnot(is.list(tags), length(tags) != 0) + lapply(`category`, function(x) stopifnot("Element" %in% class(x), !is.list(x))) + self$`category` <- `category` } - if (!missing(name)) { - stopifnot(is.character(name), length(name) == 1) - self$name <- name + 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(`photoUrls`)) { + stopifnot(is.list(`photoUrls`), length(`photoUrls`) != 0) + lapply(`photoUrls`, function(x) stopifnot(is.character(x))) + self$`photoUrls` <- `photoUrls` } - if (!missing(tags)) { + 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 + 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 + 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 } ) -) \ No newline at end of file +) diff --git a/samples/client/petstore/R/README.md b/samples/client/petstore/R/README.md index 17e1b0fed67..a1659d974a7 100644 --- a/samples/client/petstore/R/README.md +++ b/samples/client/petstore/R/README.md @@ -1 +1,33 @@ -https://github.com/swagger-api/swagger-codegen/issues/2231 \ No newline at end of file +# 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 + diff --git a/samples/client/petstore/R/man/Element.Rd b/samples/client/petstore/R/man/Element.Rd index 38dcd7b4070..636ac170d50 100644 --- a/samples/client/petstore/R/man/Element.Rd +++ b/samples/client/petstore/R/man/Element.Rd @@ -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} diff --git a/samples/client/petstore/R/man/Response.Rd b/samples/client/petstore/R/man/Response.Rd index c9fb6beddef..334e5cadd6b 100644 --- a/samples/client/petstore/R/man/Response.Rd +++ b/samples/client/petstore/R/man/Response.Rd @@ -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} diff --git a/samples/client/petstore/R/petstore.Rproj b/samples/client/petstore/R/petstore.Rproj index d848a9ff573..bfa3107e042 100644 --- a/samples/client/petstore/R/petstore.Rproj +++ b/samples/client/petstore/R/petstore.Rproj @@ -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 From a8bc0b10a969999777ad40389fe237cba0d4a804 Mon Sep 17 00:00:00 2001 From: Jakob Schelbert Date: Thu, 21 Sep 2017 17:16:06 +0200 Subject: [PATCH 3/4] Add R specific files to .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 7f6a9b4e5f0..3eb0f095343 100644 --- a/.gitignore +++ b/.gitignore @@ -174,3 +174,6 @@ samples/client/petstore/kotlin/src/main/kotlin/test/ .stack-work .cabal-sandbox cabal.project.local + +# R +.Rproj.user From d2af6420e334532ef06471e01e47b44b59bd54f7 Mon Sep 17 00:00:00 2001 From: Jakob Schelbert Date: Thu, 21 Sep 2017 17:34:19 +0200 Subject: [PATCH 4/4] [R] add additional files generated by the petstore sample. (see #6520) --- .../client/petstore/R/.swagger-codegen-ignore | 23 +++ .../petstore/R/.swagger-codegen/VERSION | 1 + samples/client/petstore/R/.travis.yml | 3 + samples/client/petstore/R/R/ApiResponse.r | 93 +++++++++++ samples/client/petstore/R/R/Category.r | 85 ++++++++++ samples/client/petstore/R/R/Order.r | 116 +++++++++++++ samples/client/petstore/R/R/PetApi.r | 154 ++++++++++++++++++ samples/client/petstore/R/R/StoreApi.r | 82 ++++++++++ samples/client/petstore/R/R/Tag.r | 85 ++++++++++ samples/client/petstore/R/R/User.r | 133 +++++++++++++++ samples/client/petstore/R/R/UserApi.r | 144 ++++++++++++++++ samples/client/petstore/R/git_push.sh | 52 ++++++ 12 files changed, 971 insertions(+) create mode 100644 samples/client/petstore/R/.swagger-codegen-ignore create mode 100644 samples/client/petstore/R/.swagger-codegen/VERSION create mode 100644 samples/client/petstore/R/.travis.yml create mode 100644 samples/client/petstore/R/R/ApiResponse.r create mode 100644 samples/client/petstore/R/R/Category.r create mode 100644 samples/client/petstore/R/R/Order.r create mode 100644 samples/client/petstore/R/R/PetApi.r create mode 100644 samples/client/petstore/R/R/StoreApi.r create mode 100644 samples/client/petstore/R/R/Tag.r create mode 100644 samples/client/petstore/R/R/User.r create mode 100644 samples/client/petstore/R/R/UserApi.r create mode 100644 samples/client/petstore/R/git_push.sh diff --git a/samples/client/petstore/R/.swagger-codegen-ignore b/samples/client/petstore/R/.swagger-codegen-ignore new file mode 100644 index 00000000000..c5fa491b4c5 --- /dev/null +++ b/samples/client/petstore/R/.swagger-codegen-ignore @@ -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 diff --git a/samples/client/petstore/R/.swagger-codegen/VERSION b/samples/client/petstore/R/.swagger-codegen/VERSION new file mode 100644 index 00000000000..f9f7450d135 --- /dev/null +++ b/samples/client/petstore/R/.swagger-codegen/VERSION @@ -0,0 +1 @@ +2.3.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/R/.travis.yml b/samples/client/petstore/R/.travis.yml new file mode 100644 index 00000000000..3f05544a724 --- /dev/null +++ b/samples/client/petstore/R/.travis.yml @@ -0,0 +1,3 @@ +# ref: https://docs.travis-ci.com/user/languages/r/ +language: r +cache: packages diff --git a/samples/client/petstore/R/R/ApiResponse.r b/samples/client/petstore/R/R/ApiResponse.r new file mode 100644 index 00000000000..79789288baf --- /dev/null +++ b/samples/client/petstore/R/R/ApiResponse.r @@ -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 + } + ) +) diff --git a/samples/client/petstore/R/R/Category.r b/samples/client/petstore/R/R/Category.r new file mode 100644 index 00000000000..5ae5581ef23 --- /dev/null +++ b/samples/client/petstore/R/R/Category.r @@ -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 + } + ) +) diff --git a/samples/client/petstore/R/R/Order.r b/samples/client/petstore/R/R/Order.r new file mode 100644 index 00000000000..b622b3d96ea --- /dev/null +++ b/samples/client/petstore/R/R/Order.r @@ -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 + } + ) +) diff --git a/samples/client/petstore/R/R/PetApi.r b/samples/client/petstore/R/R/PetApi.r new file mode 100644 index 00000000000..7e7aa3ef6bc --- /dev/null +++ b/samples/client/petstore/R/R/PetApi.r @@ -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) + } + + } + ) +) diff --git a/samples/client/petstore/R/R/StoreApi.r b/samples/client/petstore/R/R/StoreApi.r new file mode 100644 index 00000000000..944efdf6602 --- /dev/null +++ b/samples/client/petstore/R/R/StoreApi.r @@ -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) + } + + } + ) +) diff --git a/samples/client/petstore/R/R/Tag.r b/samples/client/petstore/R/R/Tag.r new file mode 100644 index 00000000000..77ccd88e0f2 --- /dev/null +++ b/samples/client/petstore/R/R/Tag.r @@ -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 + } + ) +) diff --git a/samples/client/petstore/R/R/User.r b/samples/client/petstore/R/R/User.r new file mode 100644 index 00000000000..2137dcc7d81 --- /dev/null +++ b/samples/client/petstore/R/R/User.r @@ -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 + } + ) +) diff --git a/samples/client/petstore/R/R/UserApi.r b/samples/client/petstore/R/R/UserApi.r new file mode 100644 index 00000000000..dd2686434ca --- /dev/null +++ b/samples/client/petstore/R/R/UserApi.r @@ -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) + } + + } + ) +) diff --git a/samples/client/petstore/R/git_push.sh b/samples/client/petstore/R/git_push.sh new file mode 100644 index 00000000000..ed374619b13 --- /dev/null +++ b/samples/client/petstore/R/git_push.sh @@ -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' +