Bugfix/rheaders (#1965)

* debug headers in R client

* fixes to R client

* petstore samples

* missing space

* other space :)
This commit is contained in:
Joke Durnez 2019-01-26 01:27:24 -08:00 committed by William Cheng
parent 9ec594eec5
commit 1a07bd6573
15 changed files with 495 additions and 333 deletions

View File

@ -74,37 +74,29 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
)
);
defaultIncludes = new HashSet<String>(
Arrays.asList(
"map",
"array")
);
languageSpecificPrimitives = new HashSet<String>(
Arrays.asList(
"Integer",
"Numeric",
"Character")
);
instantiationTypes.clear();
languageSpecificPrimitives.clear();
languageSpecificPrimitives.add("integer");
languageSpecificPrimitives.add("numeric");
languageSpecificPrimitives.add("character");
languageSpecificPrimitives.add("data.frame");
languageSpecificPrimitives.add("object");
typeMapping.clear();
typeMapping.put("integer", "Integer");
typeMapping.put("long", "Integer");
typeMapping.put("number", "Numeric");
typeMapping.put("float", "Numeric");
typeMapping.put("double", "Numeric");
typeMapping.put("boolean", "Character");
typeMapping.put("string", "Character");
typeMapping.put("UUID", "Character");
typeMapping.put("date", "Character");
typeMapping.put("DateTime", "Character");
typeMapping.put("password", "Character");
typeMapping.put("integer", "integer");
typeMapping.put("long", "integer");
typeMapping.put("number", "numeric");
typeMapping.put("float", "numeric");
typeMapping.put("double", "numeric");
typeMapping.put("boolean", "character");
typeMapping.put("string", "character");
typeMapping.put("UUID", "character");
typeMapping.put("date", "character");
typeMapping.put("DateTime", "character");
typeMapping.put("password", "character");
typeMapping.put("file", "data.frame");
typeMapping.put("binary", "data.frame");
typeMapping.put("ByteArray", "Character");
typeMapping.put("object", "object");
typeMapping.put("ByteArray", "character");
typeMapping.put("map", "object");
cliOptions.clear();
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "R package name (convention: lowercase).")
@ -370,8 +362,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
@Override
protected boolean needToImport(String type) {
return !defaultIncludes.contains(type)
&& !languageSpecificPrimitives.contains(type);
return !languageSpecificPrimitives.contains(type);
}
public void setPackageName(String packageName) {

View File

@ -95,9 +95,14 @@
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
{{#returnType}}
{{#isPrimitiveType}}
returnObject <- {{returnType}}$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, resp)
{{/isPrimitiveType}}
{{^isPrimitiveType}}
jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
{{/isPrimitiveType}}
{{/returnType}}
{{^returnType}}
# void response, no need to return anything

View File

@ -36,19 +36,19 @@ ApiClient <- R6::R6Class(
self$`userAgent` <- '{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}OpenAPI-Generator/{{{packageVersion}}}/r{{/httpUserAgent}}'
},
callApi = function(url, method, queryParams, headerParams, body, ...){
headers <- httr::add_headers(headerParams)
headers <- httr::add_headers(c(headerParams, self$defaultHeaders))
if (method == "GET") {
httr::GET(url, queryParams, headers, ...)
}
else if (method == "POST") {
httr::POST(url, queryParams, headers, body = body, ...)
httr::POST(url, queryParams, headers, body = body, content_type("application/json"), ...)
}
else if (method == "PUT") {
httr::PUT(url, queryParams, headers, body = body, ...)
httr::PUT(url, queryParams, headers, body = body, content_type("application/json"), ...)
}
else if (method == "PATCH") {
httr::PATCH(url, queryParams, headers, body = body, ...)
httr::PATCH(url, queryParams, headers, body = body, content_type("application/json"), ...)
}
else if (method == "HEAD") {
httr::HEAD(url, queryParams, headers, ...)

View File

@ -48,12 +48,12 @@
{{/isListContainer}}
{{#isListContainer}}
{{#isPrimitiveType}}
stopifnot(is.list(`{{baseName}}`), length(`{{baseName}}`) != 0)
lapply(`{{baseName}}`, function(x) stopifnot(is.character(x)))
stopifnot(is.vector(`{{baseName}}`), length(`{{baseName}}`) != 0)
sapply(`{{baseName}}`, function(x) stopifnot(is.character(x)))
{{/isPrimitiveType}}
{{^isPrimitiveType}}
stopifnot(is.list(`{{baseName}}`), length(`{{baseName}}`) != 0)
lapply(`{{baseName}}`, function(x) stopifnot(R6::is.R6(x)))
stopifnot(is.vector(`{{baseName}}`), length(`{{baseName}}`) != 0)
sapply(`{{baseName}}`, function(x) stopifnot(R6::is.R6(x)))
{{/isPrimitiveType}}
{{/isListContainer}}
self$`{{baseName}}` <- `{{baseName}}`
@ -64,7 +64,23 @@
{{classname}}Object <- list()
{{#vars}}
if (!is.null(self$`{{baseName}}`)) {
{{classname}}Object[['{{baseName}}']] <- {{#isListContainer}}{{#isPrimitiveType}}self$`{{baseName}}`{{/isPrimitiveType}}{{^isPrimitiveType}}lapply(self$`{{baseName}}`, function(x) x$toJSON()){{/isPrimitiveType}}{{/isListContainer}}{{^isListContainer}}self$`{{baseName}}`{{^isPrimitiveType}}$toJSON(){{/isPrimitiveType}}{{/isListContainer}}
{{classname}}Object[['{{baseName}}']] <-
{{#isListContainer}}
{{#isPrimitiveType}}
self$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
sapply(self$`{{baseName}}`, function(x) x$toJSON())
{{/isPrimitiveType}}
{{/isListContainer}}
{{^isListContainer}}
{{#isPrimitiveType}}
self$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
self$`{{baseName}}`$toJSON()
{{/isPrimitiveType}}
{{/isListContainer}}
}
{{/vars}}
@ -74,63 +90,94 @@
{{classname}}Object <- jsonlite::fromJSON({{classname}}Json)
{{#vars}}
if (!is.null({{classname}}Object$`{{baseName}}`)) {
{{#isListContainer}}
{{#isPrimitiveType}}
self$`{{baseName}}` <- {{classname}}Object$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#isListContainer}}
self$`{{baseName}}` <- lapply({{classname}}Object$`{{baseName}}`, function(x) {
self$`{{baseName}}` <- sapply({{classname}}Object$`{{baseName}}`, function(x) {
{{baseName}}Object <- {{dataType}}$new()
{{baseName}}Object$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))
{{baseName}}Object
})
{{/isPrimitiveType}}
{{/isListContainer}}
{{^isListContainer}}
{{#isPrimitiveType}}
self$`{{baseName}}` <- {{classname}}Object$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{baseName}}Object <- {{dataType}}$new()
{{baseName}}Object$fromJSON(jsonlite::toJSON({{classname}}Object${{baseName}}, auto_unbox = TRUE))
self$`{{baseName}}` <- {{baseName}}Object
{{/isListContainer}}
{{/isPrimitiveType}}
{{/isListContainer}}
}
{{/vars}}
},
toJSONString = function() {
sprintf(
outstring <- sprintf(
'{
{{#vars}}
"{{baseName}}": {{#isListContainer}}[{{/isListContainer}}{{#isPrimitiveType}}{{#isNumeric}}%d{{/isNumeric}}{{^isNumeric}}%s{{/isNumeric}}{{/isPrimitiveType}}{{^isPrimitiveType}}%s{{/isPrimitiveType}}{{#isListContainer}}]{{/isListContainer}}{{#hasMore}},{{/hasMore}}
"{{baseName}}":
{{#isListContainer}}
{{#isPrimitiveType}}
{{#isNumeric}}[%d]{{/isNumeric}}
{{^isNumeric}}["%s"]{{/isNumeric}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}["%s"]{{/isPrimitiveType}}
{{/isListContainer}}
{{^isListContainer}}
{{#isPrimitiveType}}
{{#isNumeric}}%d{{/isNumeric}}
{{^isNumeric}}"%s"{{/isNumeric}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}"%s"{{/isPrimitiveType}}
{{/isListContainer}}
{{#hasMore}},{{/hasMore}}
{{/vars}}
}',
{{#vars}}
{{#isListContainer}}
{{#isPrimitiveType}}
lapply(self$`{{baseName}}`, function(x) paste(paste0('"', x, '"'), sep=",")){{#hasMore}},{{/hasMore}}
paste0(self$`{{baseName}}`, collapse='","'){{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
lapply(self$`{{baseName}}`, function(x) paste(x$toJSON(), sep=",")){{#hasMore}},{{/hasMore}}
paste0(sapply(self$`{{baseName}}`, function(x) x$toJSON()), collapse='","'){{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}}
{{/isListContainer}}
{{^isListContainer}}
self$`{{baseName}}`{{^isPrimitiveType}}$toJSON(){{/isPrimitiveType}}{{#hasMore}},{{/hasMore}}
{{#isPrimitiveType}}
self$`{{baseName}}`{{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
self$`{{baseName}}`$toJSON(){{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}}
{{/isListContainer}}
{{/vars}}
)
gsub("[\r\n]| ", "", outstring)
},
fromJSONString = function({{classname}}Json) {
{{classname}}Object <- jsonlite::fromJSON({{classname}}Json)
{{#vars}}
{{#isListContainer}}
{{#isPrimitiveType}}
self$`{{baseName}}` <- {{classname}}Object$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#isListContainer}}
self$`{{baseName}}` <- lapply({{classname}}Object$`{{baseName}}`, function(x) {{dataType}}$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)))
self$`{{baseName}}` <- sapply({{classname}}Object$`{{baseName}}`, function(x) {{dataType}}$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)))
{{/isPrimitiveType}}
{{/isListContainer}}
{{^isListContainer}}
{{#isPrimitiveType}}
self$`{{baseName}}` <- {{classname}}Object$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{dataType}}Object <- {{dataType}}$new()
self$`{{baseName}}` <- {{dataType}}Object$fromJSON(jsonlite::toJSON({{classname}}Object${{baseName}}, auto_unbox = TRUE))
{{/isListContainer}}
{{/isPrimitiveType}}
{{/isListContainer}}
{{/vars}}
}
)

View File

@ -1 +1 @@
3.0.0-SNAPSHOT
4.0.0-SNAPSHOT

View File

@ -43,19 +43,19 @@ ApiClient <- R6::R6Class(
self$`userAgent` <- 'OpenAPI-Generator/1.0.0/r'
},
callApi = function(url, method, queryParams, headerParams, body, ...){
headers <- httr::add_headers(headerParams)
headers <- httr::add_headers(c(headerParams, self$defaultHeaders))
if (method == "GET") {
httr::GET(url, queryParams, headers, ...)
}
else if (method == "POST") {
httr::POST(url, queryParams, headers, body = body, ...)
httr::POST(url, queryParams, headers, body = body, content_type("application/json"), ...)
}
else if (method == "PUT") {
httr::PUT(url, queryParams, headers, body = body, ...)
httr::PUT(url, queryParams, headers, body = body, content_type("application/json"), ...)
}
else if (method == "PATCH") {
httr::PATCH(url, queryParams, headers, body = body, ...)
httr::PATCH(url, queryParams, headers, body = body, content_type("application/json"), ...)
}
else if (method == "HEAD") {
httr::HEAD(url, queryParams, headers, ...)

View File

@ -39,13 +39,16 @@ ApiResponse <- R6::R6Class(
toJSON = function() {
ApiResponseObject <- list()
if (!is.null(self$`code`)) {
ApiResponseObject[['code']] <- self$`code`
ApiResponseObject[['code']] <-
self$`code`
}
if (!is.null(self$`type`)) {
ApiResponseObject[['type']] <- self$`type`
ApiResponseObject[['type']] <-
self$`type`
}
if (!is.null(self$`message`)) {
ApiResponseObject[['message']] <- self$`message`
ApiResponseObject[['message']] <-
self$`message`
}
ApiResponseObject
@ -63,16 +66,29 @@ ApiResponse <- R6::R6Class(
}
},
toJSONString = function() {
sprintf(
outstring <- sprintf(
'{
"code": %d,
"type": %s,
"message": %s
"code":
%d
,
"type":
"%s"
,
"message":
"%s"
}',
self$`code`,
self$`type`,
self$`message`
)
gsub("[\r\n]| ", "", outstring)
},
fromJSONString = function(ApiResponseJson) {
ApiResponseObject <- jsonlite::fromJSON(ApiResponseJson)

View File

@ -33,10 +33,12 @@ Category <- R6::R6Class(
toJSON = function() {
CategoryObject <- list()
if (!is.null(self$`id`)) {
CategoryObject[['id']] <- self$`id`
CategoryObject[['id']] <-
self$`id`
}
if (!is.null(self$`name`)) {
CategoryObject[['name']] <- self$`name`
CategoryObject[['name']] <-
self$`name`
}
CategoryObject
@ -51,14 +53,23 @@ Category <- R6::R6Class(
}
},
toJSONString = function() {
sprintf(
outstring <- sprintf(
'{
"id": %d,
"name": %s
"id":
%d
,
"name":
"%s"
}',
self$`id`,
self$`name`
)
gsub("[\r\n]| ", "", outstring)
},
fromJSONString = function(CategoryJson) {
CategoryObject <- jsonlite::fromJSON(CategoryJson)

View File

@ -56,22 +56,28 @@ Order <- R6::R6Class(
toJSON = function() {
OrderObject <- list()
if (!is.null(self$`id`)) {
OrderObject[['id']] <- self$`id`
OrderObject[['id']] <-
self$`id`
}
if (!is.null(self$`petId`)) {
OrderObject[['petId']] <- self$`petId`
OrderObject[['petId']] <-
self$`petId`
}
if (!is.null(self$`quantity`)) {
OrderObject[['quantity']] <- self$`quantity`
OrderObject[['quantity']] <-
self$`quantity`
}
if (!is.null(self$`shipDate`)) {
OrderObject[['shipDate']] <- self$`shipDate`
OrderObject[['shipDate']] <-
self$`shipDate`
}
if (!is.null(self$`status`)) {
OrderObject[['status']] <- self$`status`
OrderObject[['status']] <-
self$`status`
}
if (!is.null(self$`complete`)) {
OrderObject[['complete']] <- self$`complete`
OrderObject[['complete']] <-
self$`complete`
}
OrderObject
@ -98,14 +104,38 @@ Order <- R6::R6Class(
}
},
toJSONString = function() {
sprintf(
outstring <- sprintf(
'{
"id": %d,
"petId": %d,
"quantity": %d,
"shipDate": %s,
"status": %s,
"complete": %s
"id":
%d
,
"petId":
%d
,
"quantity":
%d
,
"shipDate":
"%s"
,
"status":
"%s"
,
"complete":
"%s"
}',
self$`id`,
self$`petId`,
@ -114,6 +144,7 @@ Order <- R6::R6Class(
self$`status`,
self$`complete`
)
gsub("[\r\n]| ", "", outstring)
},
fromJSONString = function(OrderJson) {
OrderObject <- jsonlite::fromJSON(OrderJson)

View File

@ -57,13 +57,13 @@ PetApi <- R6::R6Class(
self$apiClient <- ApiClient$new()
}
},
add_pet = function(pet, ...){
add_pet = function(body, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`pet`)) {
body <- `pet`$toJSONString()
if (!missing(`body`)) {
body <- `body`$toJSONString()
} else {
body <- NULL
}
@ -133,9 +133,7 @@ PetApi <- R6::R6Class(
...)
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)
jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
} 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) {
@ -161,9 +159,7 @@ PetApi <- R6::R6Class(
...)
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)
jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
} 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) {
@ -189,9 +185,7 @@ PetApi <- R6::R6Class(
...)
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)
jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
} 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) {
@ -199,13 +193,13 @@ PetApi <- R6::R6Class(
}
},
update_pet = function(pet, ...){
update_pet = function(body, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`pet`)) {
body <- `pet`$toJSONString()
if (!missing(`body`)) {
body <- `body`$toJSONString()
} else {
body <- NULL
}
@ -281,9 +275,7 @@ PetApi <- R6::R6Class(
...)
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)
jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
} 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) {

View File

@ -85,9 +85,7 @@ StoreApi <- R6::R6Class(
...)
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)
jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
} 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) {
@ -113,9 +111,7 @@ StoreApi <- R6::R6Class(
...)
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)
jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
} 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) {
@ -123,13 +119,13 @@ StoreApi <- R6::R6Class(
}
},
place_order = function(order, ...){
place_order = function(body, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`order`)) {
body <- `order`$toJSONString()
if (!missing(`body`)) {
body <- `body`$toJSONString()
} else {
body <- NULL
}
@ -143,9 +139,7 @@ StoreApi <- R6::R6Class(
...)
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)
jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
} 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) {

View File

@ -33,10 +33,12 @@ Tag <- R6::R6Class(
toJSON = function() {
TagObject <- list()
if (!is.null(self$`id`)) {
TagObject[['id']] <- self$`id`
TagObject[['id']] <-
self$`id`
}
if (!is.null(self$`name`)) {
TagObject[['name']] <- self$`name`
TagObject[['name']] <-
self$`name`
}
TagObject
@ -51,14 +53,23 @@ Tag <- R6::R6Class(
}
},
toJSONString = function() {
sprintf(
outstring <- sprintf(
'{
"id": %d,
"name": %s
"id":
%d
,
"name":
"%s"
}',
self$`id`,
self$`name`
)
gsub("[\r\n]| ", "", outstring)
},
fromJSONString = function(TagJson) {
TagObject <- jsonlite::fromJSON(TagJson)

View File

@ -69,28 +69,36 @@ User <- R6::R6Class(
toJSON = function() {
UserObject <- list()
if (!is.null(self$`id`)) {
UserObject[['id']] <- self$`id`
UserObject[['id']] <-
self$`id`
}
if (!is.null(self$`username`)) {
UserObject[['username']] <- self$`username`
UserObject[['username']] <-
self$`username`
}
if (!is.null(self$`firstName`)) {
UserObject[['firstName']] <- self$`firstName`
UserObject[['firstName']] <-
self$`firstName`
}
if (!is.null(self$`lastName`)) {
UserObject[['lastName']] <- self$`lastName`
UserObject[['lastName']] <-
self$`lastName`
}
if (!is.null(self$`email`)) {
UserObject[['email']] <- self$`email`
UserObject[['email']] <-
self$`email`
}
if (!is.null(self$`password`)) {
UserObject[['password']] <- self$`password`
UserObject[['password']] <-
self$`password`
}
if (!is.null(self$`phone`)) {
UserObject[['phone']] <- self$`phone`
UserObject[['phone']] <-
self$`phone`
}
if (!is.null(self$`userStatus`)) {
UserObject[['userStatus']] <- self$`userStatus`
UserObject[['userStatus']] <-
self$`userStatus`
}
UserObject
@ -123,16 +131,48 @@ User <- R6::R6Class(
}
},
toJSONString = function() {
sprintf(
outstring <- sprintf(
'{
"id": %d,
"username": %s,
"firstName": %s,
"lastName": %s,
"email": %s,
"password": %s,
"phone": %s,
"userStatus": %d
"id":
%d
,
"username":
"%s"
,
"firstName":
"%s"
,
"lastName":
"%s"
,
"email":
"%s"
,
"password":
"%s"
,
"phone":
"%s"
,
"userStatus":
%d
}',
self$`id`,
self$`username`,
@ -143,6 +183,7 @@ User <- R6::R6Class(
self$`phone`,
self$`userStatus`
)
gsub("[\r\n]| ", "", outstring)
},
fromJSONString = function(UserJson) {
UserObject <- jsonlite::fromJSON(UserJson)

View File

@ -57,13 +57,13 @@ UserApi <- R6::R6Class(
self$apiClient <- ApiClient$new()
}
},
create_user = function(user, ...){
create_user = function(body, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`user`)) {
body <- `user`$toJSONString()
if (!missing(`body`)) {
body <- `body`$toJSONString()
} else {
body <- NULL
}
@ -85,13 +85,13 @@ UserApi <- R6::R6Class(
}
},
create_users_with_array_input = function(user, ...){
create_users_with_array_input = function(body, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`user`)) {
body <- `user`$toJSONString()
if (!missing(`body`)) {
body <- `body`$toJSONString()
} else {
body <- NULL
}
@ -113,13 +113,13 @@ UserApi <- R6::R6Class(
}
},
create_users_with_list_input = function(user, ...){
create_users_with_list_input = function(body, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`user`)) {
body <- `user`$toJSONString()
if (!missing(`body`)) {
body <- `body`$toJSONString()
} else {
body <- NULL
}
@ -185,9 +185,7 @@ UserApi <- R6::R6Class(
...)
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)
jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
} 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) {
@ -217,9 +215,7 @@ UserApi <- R6::R6Class(
...)
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)
jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
} 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) {
@ -249,13 +245,13 @@ UserApi <- R6::R6Class(
}
},
update_user = function(username, user, ...){
update_user = function(username, body, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`user`)) {
body <- `user`$toJSONString()
if (!missing(`body`)) {
body <- `body`$toJSONString()
} else {
body <- NULL
}

View File

@ -42,13 +42,13 @@ Pet <- R6::R6Class(
self$`name` <- `name`
}
if (!missing(`photoUrls`)) {
stopifnot(is.list(`photoUrls`), length(`photoUrls`) != 0)
lapply(`photoUrls`, function(x) stopifnot(is.character(x)))
stopifnot(is.vector(`photoUrls`), length(`photoUrls`) != 0)
sapply(`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)))
stopifnot(is.vector(`tags`), length(`tags`) != 0)
sapply(`tags`, function(x) stopifnot(R6::is.R6(x)))
self$`tags` <- `tags`
}
if (!missing(`status`)) {
@ -59,22 +59,28 @@ Pet <- R6::R6Class(
toJSON = function() {
PetObject <- list()
if (!is.null(self$`id`)) {
PetObject[['id']] <- self$`id`
PetObject[['id']] <-
self$`id`
}
if (!is.null(self$`category`)) {
PetObject[['category']] <- self$`category`$toJSON()
PetObject[['category']] <-
self$`category`$toJSON()
}
if (!is.null(self$`name`)) {
PetObject[['name']] <- self$`name`
PetObject[['name']] <-
self$`name`
}
if (!is.null(self$`photoUrls`)) {
PetObject[['photoUrls']] <- self$`photoUrls`
PetObject[['photoUrls']] <-
self$`photoUrls`
}
if (!is.null(self$`tags`)) {
PetObject[['tags']] <- lapply(self$`tags`, function(x) x$toJSON())
PetObject[['tags']] <-
sapply(self$`tags`, function(x) x$toJSON())
}
if (!is.null(self$`status`)) {
PetObject[['status']] <- self$`status`
PetObject[['status']] <-
self$`status`
}
PetObject
@ -96,7 +102,7 @@ Pet <- R6::R6Class(
self$`photoUrls` <- PetObject$`photoUrls`
}
if (!is.null(PetObject$`tags`)) {
self$`tags` <- lapply(PetObject$`tags`, function(x) {
self$`tags` <- sapply(PetObject$`tags`, function(x) {
tagsObject <- Tag$new()
tagsObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))
tagsObject
@ -107,22 +113,43 @@ Pet <- R6::R6Class(
}
},
toJSONString = function() {
sprintf(
outstring <- sprintf(
'{
"id": %d,
"category": %s,
"name": %s,
"photoUrls": [%s],
"tags": [%s],
"status": %s
"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=",")),
paste0(self$`photoUrls`, collapse='","'),
paste0(sapply(self$`tags`, function(x) x$toJSON()), collapse='","'),
self$`status`
)
gsub("[\r\n]| ", "", outstring)
},
fromJSONString = function(PetJson) {
PetObject <- jsonlite::fromJSON(PetJson)
@ -131,7 +158,7 @@ Pet <- R6::R6Class(
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$`tags` <- sapply(PetObject$`tags`, function(x) Tag$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)))
self$`status` <- PetObject$`status`
}
)