update R default value, clean up old R files, add window batch for (#415)

openapi3
This commit is contained in:
William Cheng 2018-05-11 11:25:50 +08:00 committed by GitHub
parent 7716d7e9b3
commit a4f76b889e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
59 changed files with 1944 additions and 2005 deletions

View File

@ -27,6 +27,6 @@ fi
# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -t modules/openapi-generator/src/main/resources/r -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -l r -o samples/client/petstore/r_test -DpackageName=petstore $@"
ags="generate -t modules/openapi-generator/src/main/resources/r -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -l r -o samples/client/petstore/R -DpackageName=petstore $@"
java $JAVA_OPTS -jar $executable $ags

View File

@ -27,6 +27,6 @@ fi
# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -t modules/openapi-generator/src/main/resources/r -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -l r -o samples/client/petstore/r_test -DpackageName=petstore $@"
ags="generate -t modules/openapi-generator/src/main/resources/r -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -l r -o samples/client/petstore/R -DpackageName=petstore $@"
java $JAVA_OPTS -jar $executable $ags

View File

@ -0,0 +1,10 @@
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
If Not Exist %executable% (
mvn clean package
)
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
set ags=generate -i modules\openapi-generator\src\test\resources\3_0\petstore.yaml -l r -o samples\client\petstore\R
java %JAVA_OPTS% -jar %executable% %ags%

View File

@ -5,6 +5,6 @@ If Not Exist %executable% (
)
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -l r -o samples\client\petstore\r
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -l r -o samples\client\petstore\R
java %JAVA_OPTS% -jar %executable% %ags%

View File

@ -17,25 +17,21 @@
package org.openapitools.codegen.languages;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.Schema;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.*;
import org.openapitools.codegen.utils.ModelUtils;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.media.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
static Logger LOGGER = LoggerFactory.getLogger(RClientCodegen.class);
protected String packageName = "openapitools";
protected String packageName = "openapi";
protected String packageVersion = "1.0.0";
protected String apiDocPath = "docs/";
protected String modelDocPath = "docs/";
@ -102,16 +98,14 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
typeMapping.put("date", "Character");
typeMapping.put("DateTime", "Character");
typeMapping.put("password", "Character");
typeMapping.put("file", "TODO_FILE_MAPPING");
// map binary to string as a workaround
// the correct solution is to use []byte
typeMapping.put("binary", "Character");
typeMapping.put("file", "data.frame");
typeMapping.put("binary", "data.frame");
typeMapping.put("ByteArray", "Character");
typeMapping.put("object", "TODO_OBJECT_MAPPING");
typeMapping.put("object", "object");
cliOptions.clear();
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "R package name (convention: lowercase).")
.defaultValue("openapitools"));
.defaultValue("openapi"));
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "R package version.")
.defaultValue("1.0.0"));
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC)
@ -126,7 +120,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
} else {
setPackageName("openapitools");
setPackageName("openapi");
}
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_VERSION)) {
@ -163,8 +157,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
}
@Override
public String escapeReservedWord(String name)
{
public String escapeReservedWord(String name) {
// Can't start with an underscore, as our fields need to start with an
// UppercaseLetter so that R treats them as public/visible.
@ -176,7 +169,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
// - X_Name
// ... or maybe a suffix?
// - Name_ ... think this will work.
if(this.reservedWordsMappings().containsKey(name)) {
if (this.reservedWordsMappings().containsKey(name)) {
return this.reservedWordsMappings().get(name);
}
return camelize(name) + '_';
@ -288,7 +281,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
@Override
public String getTypeDeclaration(Schema p) {
if(ModelUtils.isArraySchema(p)) {
if (ModelUtils.isArraySchema(p)) {
ArraySchema ap = (ArraySchema) p;
Schema inner = ap.getItems();
return getTypeDeclaration(inner);
@ -397,7 +390,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
return input.replace("]]", "] ]");
}
public Map<String, String> createMapping(String key, String value){
public Map<String, String> createMapping(String key, String value) {
Map<String, String> customImport = new HashMap<String, String>();
customImport.put(key, value);

View File

@ -1 +1 @@
2.3.0-SNAPSHOT
3.0.0-SNAPSHOT

View File

@ -1,8 +1,8 @@
Package: petstore
Title: R Package Client for Swagger Petstore
Title: R Package Client for OpenAPI 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.
Authors@R: person("OpenAPI Generator community", email = "team@openapitools.org", role = c("aut", "cre"))
Description: This is a sample server Petstore server. 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: Unlicense

View File

@ -1,11 +1,9 @@
# Generated by roxygen2: do not edit by hand
# Generated by openapi-generator: https://openapi-generator.tech
# Do not edit by hand
export(ApiResponse)
export(Category)
export(Element)
export(Order)
export(Pet)
export(PetStoreClient)
export(Response)
export(Tag)
export(User)

View File

@ -1,14 +1,20 @@
# Swagger Petstore
# OpenAPI 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.
# This is a sample server Petstore server. 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
#
# Generated by: https://openapi-generator.tech
#' ApiResponse Class
#'
#' @field code
#' @field type
#' @field message
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
ApiResponse <- R6::R6Class(
'ApiResponse',
@ -31,18 +37,44 @@ ApiResponse <- R6::R6Class(
}
},
toJSON = function() {
ApiResponseObject <- list()
if (!is.null(self$`code`)) {
ApiResponseObject[['code']] <- self$`code`
}
if (!is.null(self$`type`)) {
ApiResponseObject[['type']] <- self$`type`
}
if (!is.null(self$`message`)) {
ApiResponseObject[['message']] <- self$`message`
}
ApiResponseObject
},
fromJSON = function(ApiResponseJson) {
ApiResponseObject <- jsonlite::fromJSON(ApiResponseJson)
if (!is.null(ApiResponseObject$`code`)) {
self$`code` <- ApiResponseObject$`code`
}
if (!is.null(ApiResponseObject$`type`)) {
self$`type` <- ApiResponseObject$`type`
}
if (!is.null(ApiResponseObject$`message`)) {
self$`message` <- ApiResponseObject$`message`
}
},
toJSONString = function() {
sprintf(
'{
"code": "%s",
"type": "%s",
"message": "%s"
"code": %d,
"type": %s,
"message": %s
}',
self$`code`,
self$`type`,
self$`message`
)
},
fromJSON = function(ApiResponseJson) {
fromJSONString = function(ApiResponseJson) {
ApiResponseObject <- jsonlite::fromJSON(ApiResponseJson)
self$`code` <- ApiResponseObject$`code`
self$`type` <- ApiResponseObject$`type`
@ -50,44 +82,3 @@ ApiResponse <- R6::R6Class(
}
)
)
#' 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
}
)
)

View File

@ -1,14 +1,19 @@
# Swagger Petstore
# OpenAPI 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.
# This is a sample server Petstore server. 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
#
# Generated by: https://openapi-generator.tech
#' Category Class
#'
#' @field id
#' @field name
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
Category <- R6::R6Class(
'Category',
@ -26,60 +31,39 @@ Category <- R6::R6Class(
}
},
toJSON = function() {
CategoryObject <- list()
if (!is.null(self$`id`)) {
CategoryObject[['id']] <- self$`id`
}
if (!is.null(self$`name`)) {
CategoryObject[['name']] <- self$`name`
}
CategoryObject
},
fromJSON = function(CategoryJson) {
CategoryObject <- jsonlite::fromJSON(CategoryJson)
if (!is.null(CategoryObject$`id`)) {
self$`id` <- CategoryObject$`id`
}
if (!is.null(CategoryObject$`name`)) {
self$`name` <- CategoryObject$`name`
}
},
toJSONString = function() {
sprintf(
'{
"id": %d,
"name": "%s"
"name": %s
}',
self$`id`,
self$`name`
)
},
fromJSON = function(CategoryJson) {
fromJSONString = 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
}
)
)

View File

@ -1,14 +1,23 @@
# Swagger Petstore
# OpenAPI 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.
# This is a sample server Petstore server. 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
#
# Generated by: https://openapi-generator.tech
#' Order Class
#'
#' @field id
#' @field petId
#' @field quantity
#' @field shipDate
#' @field status
#' @field complete
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
Order <- R6::R6Class(
'Order',
@ -45,14 +54,58 @@ Order <- R6::R6Class(
}
},
toJSON = function() {
OrderObject <- list()
if (!is.null(self$`id`)) {
OrderObject[['id']] <- self$`id`
}
if (!is.null(self$`petId`)) {
OrderObject[['petId']] <- self$`petId`
}
if (!is.null(self$`quantity`)) {
OrderObject[['quantity']] <- self$`quantity`
}
if (!is.null(self$`shipDate`)) {
OrderObject[['shipDate']] <- self$`shipDate`
}
if (!is.null(self$`status`)) {
OrderObject[['status']] <- self$`status`
}
if (!is.null(self$`complete`)) {
OrderObject[['complete']] <- self$`complete`
}
OrderObject
},
fromJSON = function(OrderJson) {
OrderObject <- jsonlite::fromJSON(OrderJson)
if (!is.null(OrderObject$`id`)) {
self$`id` <- OrderObject$`id`
}
if (!is.null(OrderObject$`petId`)) {
self$`petId` <- OrderObject$`petId`
}
if (!is.null(OrderObject$`quantity`)) {
self$`quantity` <- OrderObject$`quantity`
}
if (!is.null(OrderObject$`shipDate`)) {
self$`shipDate` <- OrderObject$`shipDate`
}
if (!is.null(OrderObject$`status`)) {
self$`status` <- OrderObject$`status`
}
if (!is.null(OrderObject$`complete`)) {
self$`complete` <- OrderObject$`complete`
}
},
toJSONString = function() {
sprintf(
'{
"id": %d,
"petId": %d,
"quantity": "%s",
"shipDate": "%s",
"status": "%s",
"complete": "%s"
"quantity": %d,
"shipDate": %s,
"status": %s,
"complete": %s
}',
self$`id`,
self$`petId`,
@ -62,7 +115,7 @@ Order <- R6::R6Class(
self$`complete`
)
},
fromJSON = function(OrderJson) {
fromJSONString = function(OrderJson) {
OrderObject <- jsonlite::fromJSON(OrderJson)
self$`id` <- OrderObject$`id`
self$`petId` <- OrderObject$`petId`
@ -73,44 +126,3 @@ Order <- R6::R6Class(
}
)
)
#' 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
}
)
)

View File

@ -1,151 +1,292 @@
# Swagger Petstore
# OpenAPI 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.
# This is a sample server Petstore server. 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
#
# Generated by: https://openapi-generator.tech
#' @title Pet operations
#' @description petstore.Pet
#'
#' @field path Stores url path of the request.
#' @field apiClient Handles the client-server communication.
#' @field userAgent Set the user agent of the request.
#'
#' @importFrom R6 R6Class
#'
#' @section Methods:
#' \describe{
#'
#' add_pet Add a new pet to the store
#'
#'
#' delete_pet Deletes a pet
#'
#'
#' find_pets_by_status Finds Pets by status
#'
#'
#' find_pets_by_tags Finds Pets by tags
#'
#'
#' get_pet_by_id Find pet by ID
#'
#'
#' update_pet Update an existing pet
#'
#'
#' update_pet_with_form Updates a pet in the store with form data
#'
#'
#' upload_file uploads an image
#'
#' }
#'
#' @export
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
userAgent = "OpenAPI-Generator/1.0.0/r",
apiClient = NULL,
initialize = function(apiClient){
if (!missing(apiClient)) {
self$apiClient <- apiClient
}
else {
self$apiClient <- ApiClient$new()
}
},
add_pet = function(pet, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
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 (!missing(`pet`)) {
body <- `pet`$toJSONString()
} else {
body <- NULL
}
urlPath <- "/pet"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "POST",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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){
} 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){
} 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)
)
delete_pet = function(pet_id, api_key, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`api_key`)) {
headerParams['api_key'] <- `api_key`
}
urlPath <- "/pet/{petId}"
if (!missing(`pet_id`)) {
urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet_id`, urlPath)
}
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "DELETE",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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){
} 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){
} 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
)
)
find_pets_by_status = function(status, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`status`)) {
queryParams['status'] <- status
}
urlPath <- "/pet/findByStatus"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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){
returnObject <- Pet$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, 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){
} 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
)
)
find_pets_by_tags = function(tags, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`tags`)) {
queryParams['tags'] <- tags
}
urlPath <- "/pet/findByTags"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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){
returnObject <- Pet$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, 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){
} 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")
)
get_pet_by_id = function(pet_id, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
urlPath <- "/pet/{petId}"
if (!missing(`pet_id`)) {
urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet_id`, urlPath)
}
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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){
returnObject <- Pet$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, 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){
} 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()
)
update_pet = function(pet, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`pet`)) {
body <- `pet`$toJSONString()
} else {
body <- NULL
}
urlPath <- "/pet"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "PUT",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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){
} 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){
} 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(
update_pet_with_form = function(pet_id, name, status, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
body <- list(
"name" = name,
"status" = status
)
)
urlPath <- "/pet/{petId}"
if (!missing(`pet_id`)) {
urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet_id`, urlPath)
}
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "POST",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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){
} 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){
} 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(
upload_file = function(pet_id, additional_metadata, file, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
body <- list(
"additionalMetadata" = additional_metadata,
"file" = httr::upload_file(file)
)
)
urlPath <- "/pet/{petId}/uploadImage"
if (!missing(`pet_id`)) {
urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet_id`, urlPath)
}
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "POST",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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){
returnObject <- ApiResponse$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, 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){
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp)
}

View File

@ -1,79 +1,154 @@
# Swagger Petstore
# OpenAPI 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.
# This is a sample server Petstore server. 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
#
# Generated by: https://openapi-generator.tech
#' @title Store operations
#' @description petstore.Store
#'
#' @field path Stores url path of the request.
#' @field apiClient Handles the client-server communication.
#' @field userAgent Set the user agent of the request.
#'
#' @importFrom R6 R6Class
#'
#' @section Methods:
#' \describe{
#'
#' delete_order Delete purchase order by ID
#'
#'
#' get_inventory Returns pet inventories by status
#'
#'
#' get_order_by_id Find purchase order by ID
#'
#'
#' place_order Place an order for a pet
#'
#' }
#'
#' @export
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
userAgent = "OpenAPI-Generator/1.0.0/r",
apiClient = NULL,
initialize = function(apiClient){
if (!missing(apiClient)) {
self$apiClient <- apiClient
}
else {
self$apiClient <- ApiClient$new()
}
},
delete_order = function(order_id, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
delete_order = function(order_id){
resp <- httr::DELETE(paste0(self$basePath, order_id),
httr::add_headers("User-Agent" = self$userAgent, "content-type" = "application/xml")
)
urlPath <- "/store/order/{orderId}"
if (!missing(`order_id`)) {
urlPath <- gsub(paste0("\\{", "orderId", "\\}"), `order_id`, urlPath)
}
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "DELETE",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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){
} 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){
} 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")
)
get_inventory = function(...){
args <- list(...)
queryParams <- list()
headerParams <- character()
urlPath <- "/store/inventory"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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){
returnObject <- Integer$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, 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){
} 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")
)
get_order_by_id = function(order_id, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
urlPath <- "/store/order/{orderId}"
if (!missing(`order_id`)) {
urlPath <- gsub(paste0("\\{", "orderId", "\\}"), `order_id`, urlPath)
}
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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){
returnObject <- Order$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, 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){
} 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()
)
place_order = function(order, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`order`)) {
body <- `order`$toJSONString()
} else {
body <- NULL
}
urlPath <- "/store/order"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "POST",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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){
returnObject <- Order$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, 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){
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp)
}

View File

@ -1,14 +1,19 @@
# Swagger Petstore
# OpenAPI 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.
# This is a sample server Petstore server. 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
#
# Generated by: https://openapi-generator.tech
#' Tag Class
#'
#' @field id
#' @field name
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
Tag <- R6::R6Class(
'Tag',
@ -26,60 +31,39 @@ Tag <- R6::R6Class(
}
},
toJSON = function() {
TagObject <- list()
if (!is.null(self$`id`)) {
TagObject[['id']] <- self$`id`
}
if (!is.null(self$`name`)) {
TagObject[['name']] <- self$`name`
}
TagObject
},
fromJSON = function(TagJson) {
TagObject <- jsonlite::fromJSON(TagJson)
if (!is.null(TagObject$`id`)) {
self$`id` <- TagObject$`id`
}
if (!is.null(TagObject$`name`)) {
self$`name` <- TagObject$`name`
}
},
toJSONString = function() {
sprintf(
'{
"id": %d,
"name": "%s"
"name": %s
}',
self$`id`,
self$`name`
)
},
fromJSON = function(TagJson) {
fromJSONString = 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
}
)
)

View File

@ -1,14 +1,25 @@
# Swagger Petstore
# OpenAPI 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.
# This is a sample server Petstore server. 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
#
# Generated by: https://openapi-generator.tech
#' User Class
#'
#' @field id
#' @field username
#' @field firstName
#' @field lastName
#' @field email
#' @field password
#' @field phone
#' @field userStatus
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
User <- R6::R6Class(
'User',
@ -56,16 +67,72 @@ User <- R6::R6Class(
}
},
toJSON = function() {
UserObject <- list()
if (!is.null(self$`id`)) {
UserObject[['id']] <- self$`id`
}
if (!is.null(self$`username`)) {
UserObject[['username']] <- self$`username`
}
if (!is.null(self$`firstName`)) {
UserObject[['firstName']] <- self$`firstName`
}
if (!is.null(self$`lastName`)) {
UserObject[['lastName']] <- self$`lastName`
}
if (!is.null(self$`email`)) {
UserObject[['email']] <- self$`email`
}
if (!is.null(self$`password`)) {
UserObject[['password']] <- self$`password`
}
if (!is.null(self$`phone`)) {
UserObject[['phone']] <- self$`phone`
}
if (!is.null(self$`userStatus`)) {
UserObject[['userStatus']] <- self$`userStatus`
}
UserObject
},
fromJSON = function(UserJson) {
UserObject <- jsonlite::fromJSON(UserJson)
if (!is.null(UserObject$`id`)) {
self$`id` <- UserObject$`id`
}
if (!is.null(UserObject$`username`)) {
self$`username` <- UserObject$`username`
}
if (!is.null(UserObject$`firstName`)) {
self$`firstName` <- UserObject$`firstName`
}
if (!is.null(UserObject$`lastName`)) {
self$`lastName` <- UserObject$`lastName`
}
if (!is.null(UserObject$`email`)) {
self$`email` <- UserObject$`email`
}
if (!is.null(UserObject$`password`)) {
self$`password` <- UserObject$`password`
}
if (!is.null(UserObject$`phone`)) {
self$`phone` <- UserObject$`phone`
}
if (!is.null(UserObject$`userStatus`)) {
self$`userStatus` <- UserObject$`userStatus`
}
},
toJSONString = function() {
sprintf(
'{
"id": %d,
"username": "%s",
"firstName": "%s",
"lastName": "%s",
"email": "%s",
"password": "%s",
"phone": "%s",
"userStatus": "%s"
"username": %s,
"firstName": %s,
"lastName": %s,
"email": %s,
"password": %s,
"phone": %s,
"userStatus": %d
}',
self$`id`,
self$`username`,
@ -77,7 +144,7 @@ User <- R6::R6Class(
self$`userStatus`
)
},
fromJSON = function(UserJson) {
fromJSONString = function(UserJson) {
UserObject <- jsonlite::fromJSON(UserJson)
self$`id` <- UserObject$`id`
self$`username` <- UserObject$`username`
@ -90,44 +157,3 @@ User <- R6::R6Class(
}
)
)
#' 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
}
)
)

View File

@ -1,141 +1,282 @@
# Swagger Petstore
# OpenAPI 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.
# This is a sample server Petstore server. 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
#
# Generated by: https://openapi-generator.tech
#' @title User operations
#' @description petstore.User
#'
#' @field path Stores url path of the request.
#' @field apiClient Handles the client-server communication.
#' @field userAgent Set the user agent of the request.
#'
#' @importFrom R6 R6Class
#'
#' @section Methods:
#' \describe{
#'
#' create_user Create user
#'
#'
#' create_users_with_array_input Creates list of users with given input array
#'
#'
#' create_users_with_list_input Creates list of users with given input array
#'
#'
#' delete_user Delete user
#'
#'
#' get_user_by_name Get user by user name
#'
#'
#' login_user Logs user into the system
#'
#'
#' logout_user Logs out current logged in user session
#'
#'
#' update_user Updated user
#'
#' }
#'
#' @export
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
userAgent = "OpenAPI-Generator/1.0.0/r",
apiClient = NULL,
initialize = function(apiClient){
if (!missing(apiClient)) {
self$apiClient <- apiClient
}
else {
self$apiClient <- ApiClient$new()
}
},
create_user = function(user, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
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 (!missing(`user`)) {
body <- `user`$toJSONString()
} else {
body <- NULL
}
urlPath <- "/user"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "POST",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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){
} 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){
} 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()
)
create_users_with_array_input = function(user, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`user`)) {
body <- `user`$toJSONString()
} else {
body <- NULL
}
urlPath <- "/user/createWithArray"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "POST",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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){
} 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){
} 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()
)
create_users_with_list_input = function(user, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`user`)) {
body <- `user`$toJSONString()
} else {
body <- NULL
}
urlPath <- "/user/createWithList"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "POST",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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){
} 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){
} 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")
)
delete_user = function(username, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
urlPath <- "/user/{username}"
if (!missing(`username`)) {
urlPath <- gsub(paste0("\\{", "username", "\\}"), `username`, urlPath)
}
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "DELETE",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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){
} 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){
} 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")
)
get_user_by_name = function(username, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
urlPath <- "/user/{username}"
if (!missing(`username`)) {
urlPath <- gsub(paste0("\\{", "username", "\\}"), `username`, urlPath)
}
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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){
returnObject <- User$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, 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){
} 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
)
)
login_user = function(username, password, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`username`)) {
queryParams['username'] <- username
}
if (!missing(`password`)) {
queryParams['password'] <- password
}
urlPath <- "/user/login"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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){
returnObject <- Character$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, 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){
} 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")
)
logout_user = function(...){
args <- list(...)
queryParams <- list()
headerParams <- character()
urlPath <- "/user/logout"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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){
} 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){
} 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()
)
update_user = function(username, user, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`user`)) {
body <- `user`$toJSONString()
} else {
body <- NULL
}
urlPath <- "/user/{username}"
if (!missing(`username`)) {
urlPath <- gsub(paste0("\\{", "username", "\\}"), `username`, urlPath)
}
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "PUT",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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){
} 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){
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp)
}

View File

@ -1,14 +1,23 @@
# Swagger Petstore
# OpenAPI 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.
# This is a sample server Petstore server. 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
#
# Generated by: https://openapi-generator.tech
#' Pet Class
#'
#' @field id
#' @field category
#' @field name
#' @field photoUrls
#' @field tags
#' @field status
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
Pet <- R6::R6Class(
'Pet',
@ -25,8 +34,7 @@ Pet <- R6::R6Class(
self$`id` <- `id`
}
if (!missing(`category`)) {
stopifnot(is.list(tags), length(tags) != 0)
lapply(`category`, function(x) stopifnot("Element" %in% class(x), !is.list(x)))
stopifnot(R6::is.R6(`category`))
self$`category` <- `category`
}
if (!missing(`name`)) {
@ -39,8 +47,8 @@ Pet <- R6::R6Class(
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)))
stopifnot(is.list(`tags`), length(`tags`) != 0)
lapply(`tags`, function(x) stopifnot(R6::is.R6(x)))
self$`tags` <- `tags`
}
if (!missing(`status`)) {
@ -49,14 +57,64 @@ Pet <- R6::R6Class(
}
},
toJSON = function() {
PetObject <- list()
if (!is.null(self$`id`)) {
PetObject[['id']] <- self$`id`
}
if (!is.null(self$`category`)) {
PetObject[['category']] <- self$`category`$toJSON()
}
if (!is.null(self$`name`)) {
PetObject[['name']] <- self$`name`
}
if (!is.null(self$`photoUrls`)) {
PetObject[['photoUrls']] <- self$`photoUrls`
}
if (!is.null(self$`tags`)) {
PetObject[['tags']] <- lapply(self$`tags`, function(x) x$toJSON())
}
if (!is.null(self$`status`)) {
PetObject[['status']] <- self$`status`
}
PetObject
},
fromJSON = function(PetJson) {
PetObject <- jsonlite::fromJSON(PetJson)
if (!is.null(PetObject$`id`)) {
self$`id` <- PetObject$`id`
}
if (!is.null(PetObject$`category`)) {
categoryObject <- Category$new()
categoryObject$fromJSON(jsonlite::toJSON(PetObject$category, auto_unbox = TRUE))
self$`category` <- categoryObject
}
if (!is.null(PetObject$`name`)) {
self$`name` <- PetObject$`name`
}
if (!is.null(PetObject$`photoUrls`)) {
self$`photoUrls` <- PetObject$`photoUrls`
}
if (!is.null(PetObject$`tags`)) {
self$`tags` <- lapply(PetObject$`tags`, function(x) {
tagsObject <- Tag$new()
tagsObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))
tagsObject
})
}
if (!is.null(PetObject$`status`)) {
self$`status` <- PetObject$`status`
}
},
toJSONString = function() {
sprintf(
'{
"id": %d,
"category": %s,
"name": "%s",
"photoUrls": ["%s"],
"name": %s,
"photoUrls": [%s],
"tags": [%s],
"status": "%s"
"status": %s
}',
self$`id`,
self$`category`$toJSON(),
@ -66,55 +124,15 @@ Pet <- R6::R6Class(
self$`status`
)
},
fromJSON = function(PetJson) {
fromJSONString = function(PetJson) {
PetObject <- jsonlite::fromJSON(PetJson)
self$`id` <- PetObject$`id`
self$`category` <- Category$new()$fromJSON(jsonlite::toJSON(PetObject$category))
CategoryObject <- Category$new()
self$`category` <- CategoryObject$fromJSON(jsonlite::toJSON(PetObject$category, auto_unbox = TRUE))
self$`name` <- PetObject$`name`
self$`photoUrls` <- PetObject$`photoUrls`
self$`tags` <- lapply(PetObject$`tags`, function(x) Tag$new()$fromJSON(jsonlite::toJSON(x)))
self$`tags` <- lapply(PetObject$`tags`, function(x) Tag$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)))
self$`status` <- PetObject$`status`
}
)
)
#' 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
}
)
)

View File

@ -1,13 +1,13 @@
# R API client for swagger
# R API client for 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.
This is a sample server Petstore server. 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.
This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI spec](https://openapis.org) 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
- Build package: org.openapitools.codegen.languages.RClientCodegen
## Installation
You'll need the `devtools` package in order to build the API.
@ -29,5 +29,5 @@ install(".")
## Author
apiteam@swagger.io

View File

@ -1,7 +1,7 @@
#!/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"
# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update"
git_user_id=$1
git_repo_id=$2
@ -36,7 +36,7 @@ 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."
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential 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

View File

@ -0,0 +1,12 @@
Package: petstore
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: Unlicense
LazyData: true
Suggests: testthat
Imports: jsonlite, httr, R6
RoxygenNote: 6.0.1.9000

View File

@ -0,0 +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)

View 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
}
)
)

View 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
}
)
)

View 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
}
)
)

View 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)
}
}
)
)

View 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)
}
}
)
)

View 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
}
)
)

View File

@ -1,25 +1,14 @@
# OpenAPI Petstore
# Swagger Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
# 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
#
# Generated by: https://openapi-generator.tech
# Contact: apiteam@swagger.io
# Generated by: https://github.com/swagger-api/swagger-codegen.git
#' User Class
#'
#' @field id
#' @field username
#' @field firstName
#' @field lastName
#' @field email
#' @field password
#' @field phone
#' @field userStatus
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
User <- R6::R6Class(
'User',
@ -67,72 +56,16 @@ User <- R6::R6Class(
}
},
toJSON = function() {
UserObject <- list()
if (!is.null(self$`id`)) {
UserObject[['id']] <- self$`id`
}
if (!is.null(self$`username`)) {
UserObject[['username']] <- self$`username`
}
if (!is.null(self$`firstName`)) {
UserObject[['firstName']] <- self$`firstName`
}
if (!is.null(self$`lastName`)) {
UserObject[['lastName']] <- self$`lastName`
}
if (!is.null(self$`email`)) {
UserObject[['email']] <- self$`email`
}
if (!is.null(self$`password`)) {
UserObject[['password']] <- self$`password`
}
if (!is.null(self$`phone`)) {
UserObject[['phone']] <- self$`phone`
}
if (!is.null(self$`userStatus`)) {
UserObject[['userStatus']] <- self$`userStatus`
}
UserObject
},
fromJSON = function(UserJson) {
UserObject <- jsonlite::fromJSON(UserJson)
if (!is.null(UserObject$`id`)) {
self$`id` <- UserObject$`id`
}
if (!is.null(UserObject$`username`)) {
self$`username` <- UserObject$`username`
}
if (!is.null(UserObject$`firstName`)) {
self$`firstName` <- UserObject$`firstName`
}
if (!is.null(UserObject$`lastName`)) {
self$`lastName` <- UserObject$`lastName`
}
if (!is.null(UserObject$`email`)) {
self$`email` <- UserObject$`email`
}
if (!is.null(UserObject$`password`)) {
self$`password` <- UserObject$`password`
}
if (!is.null(UserObject$`phone`)) {
self$`phone` <- UserObject$`phone`
}
if (!is.null(UserObject$`userStatus`)) {
self$`userStatus` <- UserObject$`userStatus`
}
},
toJSONString = function() {
sprintf(
'{
"id": %d,
"username": %s,
"firstName": %s,
"lastName": %s,
"email": %s,
"password": %s,
"phone": %s,
"userStatus": %d
"username": "%s",
"firstName": "%s",
"lastName": "%s",
"email": "%s",
"password": "%s",
"phone": "%s",
"userStatus": "%s"
}',
self$`id`,
self$`username`,
@ -144,7 +77,7 @@ User <- R6::R6Class(
self$`userStatus`
)
},
fromJSONString = function(UserJson) {
fromJSON = function(UserJson) {
UserObject <- jsonlite::fromJSON(UserJson)
self$`id` <- UserObject$`id`
self$`username` <- UserObject$`username`
@ -157,3 +90,44 @@ User <- R6::R6Class(
}
)
)
#' 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
}
)
)

View 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)
}
}
)
)

View File

@ -0,0 +1,120 @@
# 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',
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`
}
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(`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() {
sprintf(
'{
"id": %d,
"category": %s,
"name": "%s",
"photoUrls": ["%s"],
"tags": [%s],
"status": "%s"
}',
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`
}
)
)
#' 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
}
)
)

View File

@ -0,0 +1,33 @@
# 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

View File

@ -1,7 +1,7 @@
#!/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 openapi-pestore-perl "minor update"
# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update"
git_user_id=$1
git_repo_id=$2
@ -36,7 +36,7 @@ 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 credential in your environment."
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

View File

@ -1,2 +0,0 @@
^.*\.Rproj$
^\.Rproj\.user$

View File

@ -1,35 +0,0 @@
# 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

View File

@ -1,23 +0,0 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
# 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 OpenAPI Generator 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

View File

@ -1 +0,0 @@
3.0.0-SNAPSHOT

View File

@ -1,3 +0,0 @@
# ref: https://docs.travis-ci.com/user/languages/r/
language: r
cache: packages

View File

@ -1,12 +0,0 @@
Package: petstore
Title: R Package Client for OpenAPI Petstore
Version: 1.0.0
Authors@R: person("OpenAPI Generator community", email = "team@openapitools.org", role = c("aut", "cre"))
Description: This is a sample server Petstore server. 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: Unlicense
LazyData: true
Suggests: testthat
Imports: jsonlite, httr, R6
RoxygenNote: 6.0.1.9000

View File

@ -1,9 +0,0 @@
# Generated by openapi-generator: https://openapi-generator.tech
# Do not edit by hand
export(ApiResponse)
export(Category)
export(Order)
export(Pet)
export(Tag)
export(User)

View File

@ -1,84 +0,0 @@
# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# OpenAPI spec version: 1.0.0
#
# Generated by: https://openapi-generator.tech
#' ApiResponse Class
#'
#' @field code
#' @field type
#' @field message
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @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() {
ApiResponseObject <- list()
if (!is.null(self$`code`)) {
ApiResponseObject[['code']] <- self$`code`
}
if (!is.null(self$`type`)) {
ApiResponseObject[['type']] <- self$`type`
}
if (!is.null(self$`message`)) {
ApiResponseObject[['message']] <- self$`message`
}
ApiResponseObject
},
fromJSON = function(ApiResponseJson) {
ApiResponseObject <- jsonlite::fromJSON(ApiResponseJson)
if (!is.null(ApiResponseObject$`code`)) {
self$`code` <- ApiResponseObject$`code`
}
if (!is.null(ApiResponseObject$`type`)) {
self$`type` <- ApiResponseObject$`type`
}
if (!is.null(ApiResponseObject$`message`)) {
self$`message` <- ApiResponseObject$`message`
}
},
toJSONString = function() {
sprintf(
'{
"code": %d,
"type": %s,
"message": %s
}',
self$`code`,
self$`type`,
self$`message`
)
},
fromJSONString = function(ApiResponseJson) {
ApiResponseObject <- jsonlite::fromJSON(ApiResponseJson)
self$`code` <- ApiResponseObject$`code`
self$`type` <- ApiResponseObject$`type`
self$`message` <- ApiResponseObject$`message`
}
)
)

View File

@ -1,69 +0,0 @@
# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# OpenAPI spec version: 1.0.0
#
# Generated by: https://openapi-generator.tech
#' Category Class
#'
#' @field id
#' @field name
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @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() {
CategoryObject <- list()
if (!is.null(self$`id`)) {
CategoryObject[['id']] <- self$`id`
}
if (!is.null(self$`name`)) {
CategoryObject[['name']] <- self$`name`
}
CategoryObject
},
fromJSON = function(CategoryJson) {
CategoryObject <- jsonlite::fromJSON(CategoryJson)
if (!is.null(CategoryObject$`id`)) {
self$`id` <- CategoryObject$`id`
}
if (!is.null(CategoryObject$`name`)) {
self$`name` <- CategoryObject$`name`
}
},
toJSONString = function() {
sprintf(
'{
"id": %d,
"name": %s
}',
self$`id`,
self$`name`
)
},
fromJSONString = function(CategoryJson) {
CategoryObject <- jsonlite::fromJSON(CategoryJson)
self$`id` <- CategoryObject$`id`
self$`name` <- CategoryObject$`name`
}
)
)

View File

@ -1,128 +0,0 @@
# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# OpenAPI spec version: 1.0.0
#
# Generated by: https://openapi-generator.tech
#' Order Class
#'
#' @field id
#' @field petId
#' @field quantity
#' @field shipDate
#' @field status
#' @field complete
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @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() {
OrderObject <- list()
if (!is.null(self$`id`)) {
OrderObject[['id']] <- self$`id`
}
if (!is.null(self$`petId`)) {
OrderObject[['petId']] <- self$`petId`
}
if (!is.null(self$`quantity`)) {
OrderObject[['quantity']] <- self$`quantity`
}
if (!is.null(self$`shipDate`)) {
OrderObject[['shipDate']] <- self$`shipDate`
}
if (!is.null(self$`status`)) {
OrderObject[['status']] <- self$`status`
}
if (!is.null(self$`complete`)) {
OrderObject[['complete']] <- self$`complete`
}
OrderObject
},
fromJSON = function(OrderJson) {
OrderObject <- jsonlite::fromJSON(OrderJson)
if (!is.null(OrderObject$`id`)) {
self$`id` <- OrderObject$`id`
}
if (!is.null(OrderObject$`petId`)) {
self$`petId` <- OrderObject$`petId`
}
if (!is.null(OrderObject$`quantity`)) {
self$`quantity` <- OrderObject$`quantity`
}
if (!is.null(OrderObject$`shipDate`)) {
self$`shipDate` <- OrderObject$`shipDate`
}
if (!is.null(OrderObject$`status`)) {
self$`status` <- OrderObject$`status`
}
if (!is.null(OrderObject$`complete`)) {
self$`complete` <- OrderObject$`complete`
}
},
toJSONString = function() {
sprintf(
'{
"id": %d,
"petId": %d,
"quantity": %d,
"shipDate": %s,
"status": %s,
"complete": %s
}',
self$`id`,
self$`petId`,
self$`quantity`,
self$`shipDate`,
self$`status`,
self$`complete`
)
},
fromJSONString = 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`
}
)
)

View File

@ -1,138 +0,0 @@
# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# OpenAPI spec version: 1.0.0
#
# Generated by: https://openapi-generator.tech
#' Pet Class
#'
#' @field id
#' @field category
#' @field name
#' @field photoUrls
#' @field tags
#' @field status
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
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`
}
if (!missing(`category`)) {
stopifnot(R6::is.R6(`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`)) {
stopifnot(is.list(`tags`), length(`tags`) != 0)
lapply(`tags`, function(x) stopifnot(R6::is.R6(x)))
self$`tags` <- `tags`
}
if (!missing(`status`)) {
stopifnot(is.character(`status`), length(`status`) == 1)
self$`status` <- `status`
}
},
toJSON = function() {
PetObject <- list()
if (!is.null(self$`id`)) {
PetObject[['id']] <- self$`id`
}
if (!is.null(self$`category`)) {
PetObject[['category']] <- self$`category`$toJSON()
}
if (!is.null(self$`name`)) {
PetObject[['name']] <- self$`name`
}
if (!is.null(self$`photoUrls`)) {
PetObject[['photoUrls']] <- self$`photoUrls`
}
if (!is.null(self$`tags`)) {
PetObject[['tags']] <- lapply(self$`tags`, function(x) x$toJSON())
}
if (!is.null(self$`status`)) {
PetObject[['status']] <- self$`status`
}
PetObject
},
fromJSON = function(PetJson) {
PetObject <- jsonlite::fromJSON(PetJson)
if (!is.null(PetObject$`id`)) {
self$`id` <- PetObject$`id`
}
if (!is.null(PetObject$`category`)) {
categoryObject <- Category$new()
categoryObject$fromJSON(jsonlite::toJSON(PetObject$category, auto_unbox = TRUE))
self$`category` <- categoryObject
}
if (!is.null(PetObject$`name`)) {
self$`name` <- PetObject$`name`
}
if (!is.null(PetObject$`photoUrls`)) {
self$`photoUrls` <- PetObject$`photoUrls`
}
if (!is.null(PetObject$`tags`)) {
self$`tags` <- lapply(PetObject$`tags`, function(x) {
tagsObject <- Tag$new()
tagsObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))
tagsObject
})
}
if (!is.null(PetObject$`status`)) {
self$`status` <- PetObject$`status`
}
},
toJSONString = function() {
sprintf(
'{
"id": %d,
"category": %s,
"name": %s,
"photoUrls": [%s],
"tags": [%s],
"status": %s
}',
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`
)
},
fromJSONString = function(PetJson) {
PetObject <- jsonlite::fromJSON(PetJson)
self$`id` <- PetObject$`id`
CategoryObject <- Category$new()
self$`category` <- CategoryObject$fromJSON(jsonlite::toJSON(PetObject$category, auto_unbox = TRUE))
self$`name` <- PetObject$`name`
self$`photoUrls` <- PetObject$`photoUrls`
self$`tags` <- lapply(PetObject$`tags`, function(x) Tag$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)))
self$`status` <- PetObject$`status`
}
)
)

View File

@ -1,295 +0,0 @@
# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# OpenAPI spec version: 1.0.0
#
# Generated by: https://openapi-generator.tech
#' @title Pet operations
#' @description petstore.Pet
#'
#' @field path Stores url path of the request.
#' @field apiClient Handles the client-server communication.
#' @field userAgent Set the user agent of the request.
#'
#' @importFrom R6 R6Class
#'
#' @section Methods:
#' \describe{
#'
#' add_pet Add a new pet to the store
#'
#'
#' delete_pet Deletes a pet
#'
#'
#' find_pets_by_status Finds Pets by status
#'
#'
#' find_pets_by_tags Finds Pets by tags
#'
#'
#' get_pet_by_id Find pet by ID
#'
#'
#' update_pet Update an existing pet
#'
#'
#' update_pet_with_form Updates a pet in the store with form data
#'
#'
#' upload_file uploads an image
#'
#' }
#'
#' @export
PetApi <- R6::R6Class(
'PetApi',
public = list(
userAgent = "OpenAPI-Generator/1.0.0/r",
apiClient = NULL,
initialize = function(apiClient){
if (!missing(apiClient)) {
self$apiClient <- apiClient
}
else {
self$apiClient <- ApiClient$new()
}
},
add_pet = function(pet, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`pet`)) {
body <- `pet`$toJSONString()
} else {
body <- NULL
}
urlPath <- "/pet"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "POST",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`api_key`)) {
headerParams['api_key'] <- `api_key`
}
urlPath <- "/pet/{petId}"
if (!missing(`pet_id`)) {
urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet_id`, urlPath)
}
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "DELETE",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`status`)) {
queryParams['status'] <- status
}
urlPath <- "/pet/findByStatus"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
returnObject <- Pet$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, 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, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`tags`)) {
queryParams['tags'] <- tags
}
urlPath <- "/pet/findByTags"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
returnObject <- Pet$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, 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, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
urlPath <- "/pet/{petId}"
if (!missing(`pet_id`)) {
urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet_id`, urlPath)
}
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
returnObject <- Pet$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, 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(pet, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`pet`)) {
body <- `pet`$toJSONString()
} else {
body <- NULL
}
urlPath <- "/pet"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "PUT",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
body <- list(
"name" = name,
"status" = status
)
urlPath <- "/pet/{petId}"
if (!missing(`pet_id`)) {
urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet_id`, urlPath)
}
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "POST",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
body <- list(
"additionalMetadata" = additional_metadata,
"file" = httr::upload_file(file)
)
urlPath <- "/pet/{petId}/uploadImage"
if (!missing(`pet_id`)) {
urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet_id`, urlPath)
}
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "POST",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
returnObject <- ApiResponse$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, 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)
}
}
)
)

View File

@ -1,157 +0,0 @@
# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# OpenAPI spec version: 1.0.0
#
# Generated by: https://openapi-generator.tech
#' @title Store operations
#' @description petstore.Store
#'
#' @field path Stores url path of the request.
#' @field apiClient Handles the client-server communication.
#' @field userAgent Set the user agent of the request.
#'
#' @importFrom R6 R6Class
#'
#' @section Methods:
#' \describe{
#'
#' delete_order Delete purchase order by ID
#'
#'
#' get_inventory Returns pet inventories by status
#'
#'
#' get_order_by_id Find purchase order by ID
#'
#'
#' place_order Place an order for a pet
#'
#' }
#'
#' @export
StoreApi <- R6::R6Class(
'StoreApi',
public = list(
userAgent = "OpenAPI-Generator/1.0.0/r",
apiClient = NULL,
initialize = function(apiClient){
if (!missing(apiClient)) {
self$apiClient <- apiClient
}
else {
self$apiClient <- ApiClient$new()
}
},
delete_order = function(order_id, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
urlPath <- "/store/order/{orderId}"
if (!missing(`order_id`)) {
urlPath <- gsub(paste0("\\{", "orderId", "\\}"), `order_id`, urlPath)
}
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "DELETE",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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(...){
args <- list(...)
queryParams <- list()
headerParams <- character()
urlPath <- "/store/inventory"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
returnObject <- Integer$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, 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, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
urlPath <- "/store/order/{orderId}"
if (!missing(`order_id`)) {
urlPath <- gsub(paste0("\\{", "orderId", "\\}"), `order_id`, urlPath)
}
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
returnObject <- Order$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, 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(order, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`order`)) {
body <- `order`$toJSONString()
} else {
body <- NULL
}
urlPath <- "/store/order"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "POST",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
returnObject <- Order$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, 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)
}
}
)
)

View File

@ -1,69 +0,0 @@
# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# OpenAPI spec version: 1.0.0
#
# Generated by: https://openapi-generator.tech
#' Tag Class
#'
#' @field id
#' @field name
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @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() {
TagObject <- list()
if (!is.null(self$`id`)) {
TagObject[['id']] <- self$`id`
}
if (!is.null(self$`name`)) {
TagObject[['name']] <- self$`name`
}
TagObject
},
fromJSON = function(TagJson) {
TagObject <- jsonlite::fromJSON(TagJson)
if (!is.null(TagObject$`id`)) {
self$`id` <- TagObject$`id`
}
if (!is.null(TagObject$`name`)) {
self$`name` <- TagObject$`name`
}
},
toJSONString = function() {
sprintf(
'{
"id": %d,
"name": %s
}',
self$`id`,
self$`name`
)
},
fromJSONString = function(TagJson) {
TagObject <- jsonlite::fromJSON(TagJson)
self$`id` <- TagObject$`id`
self$`name` <- TagObject$`name`
}
)
)

View File

@ -1,285 +0,0 @@
# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# OpenAPI spec version: 1.0.0
#
# Generated by: https://openapi-generator.tech
#' @title User operations
#' @description petstore.User
#'
#' @field path Stores url path of the request.
#' @field apiClient Handles the client-server communication.
#' @field userAgent Set the user agent of the request.
#'
#' @importFrom R6 R6Class
#'
#' @section Methods:
#' \describe{
#'
#' create_user Create user
#'
#'
#' create_users_with_array_input Creates list of users with given input array
#'
#'
#' create_users_with_list_input Creates list of users with given input array
#'
#'
#' delete_user Delete user
#'
#'
#' get_user_by_name Get user by user name
#'
#'
#' login_user Logs user into the system
#'
#'
#' logout_user Logs out current logged in user session
#'
#'
#' update_user Updated user
#'
#' }
#'
#' @export
UserApi <- R6::R6Class(
'UserApi',
public = list(
userAgent = "OpenAPI-Generator/1.0.0/r",
apiClient = NULL,
initialize = function(apiClient){
if (!missing(apiClient)) {
self$apiClient <- apiClient
}
else {
self$apiClient <- ApiClient$new()
}
},
create_user = function(user, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`user`)) {
body <- `user`$toJSONString()
} else {
body <- NULL
}
urlPath <- "/user"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "POST",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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(user, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`user`)) {
body <- `user`$toJSONString()
} else {
body <- NULL
}
urlPath <- "/user/createWithArray"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "POST",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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(user, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`user`)) {
body <- `user`$toJSONString()
} else {
body <- NULL
}
urlPath <- "/user/createWithList"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "POST",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
urlPath <- "/user/{username}"
if (!missing(`username`)) {
urlPath <- gsub(paste0("\\{", "username", "\\}"), `username`, urlPath)
}
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "DELETE",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
urlPath <- "/user/{username}"
if (!missing(`username`)) {
urlPath <- gsub(paste0("\\{", "username", "\\}"), `username`, urlPath)
}
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
returnObject <- User$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, 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, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`username`)) {
queryParams['username'] <- username
}
if (!missing(`password`)) {
queryParams['password'] <- password
}
urlPath <- "/user/login"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
returnObject <- Character$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, 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(...){
args <- list(...)
queryParams <- list()
headerParams <- character()
urlPath <- "/user/logout"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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, user, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`user`)) {
body <- `user`$toJSONString()
} else {
body <- NULL
}
urlPath <- "/user/{username}"
if (!missing(`username`)) {
urlPath <- gsub(paste0("\\{", "username", "\\}"), `username`, urlPath)
}
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "PUT",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
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)
}
}
)
)

View File

@ -1,33 +0,0 @@
# R API client for petstore
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
## Overview
This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI spec](https://openapis.org) from a remote server, you can easily generate an API client.
- API version: 1.0.0
- Package version: 1.0.0
- Build package: org.openapitools.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