From e3e06af5f4af3e0ac96ee2aa822fe8efe3ead529 Mon Sep 17 00:00:00 2001 From: Matt Pollock Date: Thu, 28 Nov 2024 03:31:21 -0500 Subject: [PATCH] [R] fix to-list and to-json functionality (#20132) * [r client] fix to-list and to-json functionality * fix type of json string * wip * refactor pr * regenerate samples * update to-dataframe example to use non-superceded tidyverse functions * fix typo --- .../src/main/resources/r/api.mustache | 2 +- .../src/main/resources/r/modelAnyOf.mustache | 29 +-- .../src/main/resources/r/modelEnum.mustache | 22 ++- .../main/resources/r/modelGeneric.mustache | 111 ++++-------- .../src/main/resources/r/modelOneOf.mustache | 28 ++- samples/client/echo_api/r/R/bird.R | 61 ++++--- samples/client/echo_api/r/R/body_api.R | 14 +- samples/client/echo_api/r/R/category.R | 61 ++++--- samples/client/echo_api/r/R/data_query.R | 85 ++++----- samples/client/echo_api/r/R/default_value.R | 111 ++++-------- .../echo_api/r/R/number_properties_only.R | 69 +++---- samples/client/echo_api/r/R/pet.R | 97 ++++------ samples/client/echo_api/r/R/query.R | 61 ++++--- samples/client/echo_api/r/R/string_enum_ref.R | 22 ++- samples/client/echo_api/r/R/tag.R | 61 ++++--- ...est_form_object_multipart_request_marker.R | 53 ++++-- ...rue_object_all_of_query_object_parameter.R | 77 ++++---- ...true_array_string_query_object_parameter.R | 53 ++++-- .../R/allof_tag_api_response.R | 89 ++++----- .../petstore/R-httr2-wrapper/R/animal.R | 65 ++++--- .../petstore/R-httr2-wrapper/R/any_of_pig.R | 29 +-- .../R/any_of_primitive_type_test.R | 28 ++- .../petstore/R-httr2-wrapper/R/basque_pig.R | 65 ++++--- .../client/petstore/R-httr2-wrapper/R/cat.R | 73 ++++---- .../petstore/R-httr2-wrapper/R/category.R | 65 ++++--- .../petstore/R-httr2-wrapper/R/danish_pig.R | 65 ++++--- .../client/petstore/R-httr2-wrapper/R/date.R | 73 ++++---- .../client/petstore/R-httr2-wrapper/R/dog.R | 73 ++++---- .../petstore/R-httr2-wrapper/R/dummy_model.R | 57 +++--- .../petstore/R-httr2-wrapper/R/fake_api.R | 2 +- .../petstore/R-httr2-wrapper/R/format_test.R | 169 ++++-------------- .../petstore/R-httr2-wrapper/R/mammal.R | 28 ++- .../R-httr2-wrapper/R/model_api_response.R | 73 ++++---- .../R-httr2-wrapper/R/nested_one_of.R | 67 +++---- .../R/one_of_primitive_type_test.R | 28 ++- .../client/petstore/R-httr2-wrapper/R/order.R | 97 ++++------ .../client/petstore/R-httr2-wrapper/R/pet.R | 101 ++++------- .../petstore/R-httr2-wrapper/R/pet_api.R | 4 +- .../petstore/R-httr2-wrapper/R/pet_map.R | 57 +++--- .../client/petstore/R-httr2-wrapper/R/pig.R | 28 ++- .../petstore/R-httr2-wrapper/R/special.R | 105 ++++------- .../petstore/R-httr2-wrapper/R/store_api.R | 2 +- .../client/petstore/R-httr2-wrapper/R/tag.R | 65 ++++--- .../R-httr2-wrapper/R/update_pet_request.R | 67 +++---- .../client/petstore/R-httr2-wrapper/R/user.R | 113 ++++-------- .../petstore/R-httr2-wrapper/R/user_api.R | 8 +- .../client/petstore/R-httr2-wrapper/R/whale.R | 73 ++++---- .../client/petstore/R-httr2-wrapper/R/zebra.R | 65 ++++--- .../tests/testthat/test_petstore.R | 6 +- .../R-httr2/R/allof_tag_api_response.R | 85 ++++----- samples/client/petstore/R-httr2/R/animal.R | 61 ++++--- .../client/petstore/R-httr2/R/any_of_pig.R | 29 +-- .../R-httr2/R/any_of_primitive_type_test.R | 28 ++- .../client/petstore/R-httr2/R/basque_pig.R | 61 ++++--- samples/client/petstore/R-httr2/R/cat.R | 69 +++---- samples/client/petstore/R-httr2/R/category.R | 61 ++++--- .../client/petstore/R-httr2/R/danish_pig.R | 61 ++++--- samples/client/petstore/R-httr2/R/date.R | 69 +++---- samples/client/petstore/R-httr2/R/dog.R | 69 +++---- samples/client/petstore/R-httr2/R/fake_api.R | 2 +- .../client/petstore/R-httr2/R/format_test.R | 165 ++++------------- .../client/petstore/R-httr2/R/just_model.R | 53 ++++-- samples/client/petstore/R-httr2/R/mammal.R | 28 ++- .../petstore/R-httr2/R/model_api_response.R | 69 +++---- .../client/petstore/R-httr2/R/nested_one_of.R | 63 ++++--- .../R-httr2/R/one_of_primitive_type_test.R | 28 ++- samples/client/petstore/R-httr2/R/order.R | 93 ++++------ samples/client/petstore/R-httr2/R/pet.R | 97 ++++------ samples/client/petstore/R-httr2/R/pet_api.R | 4 +- samples/client/petstore/R-httr2/R/pet_map.R | 53 ++++-- samples/client/petstore/R-httr2/R/pig.R | 28 ++- samples/client/petstore/R-httr2/R/special.R | 101 ++++------- samples/client/petstore/R-httr2/R/store_api.R | 2 +- samples/client/petstore/R-httr2/R/tag.R | 61 ++++--- .../petstore/R-httr2/R/update_pet_request.R | 63 ++++--- samples/client/petstore/R-httr2/R/user.R | 109 ++++------- samples/client/petstore/R-httr2/R/user_api.R | 8 +- samples/client/petstore/R-httr2/R/whale.R | 69 +++---- samples/client/petstore/R-httr2/R/zebra.R | 61 ++++--- .../R-httr2/tests/testthat/test_petstore.R | 6 +- .../petstore/R/R/allof_tag_api_response.R | 89 ++++----- samples/client/petstore/R/R/animal.R | 65 ++++--- samples/client/petstore/R/R/any_of_pig.R | 29 +-- .../petstore/R/R/any_of_primitive_type_test.R | 28 ++- samples/client/petstore/R/R/basque_pig.R | 65 ++++--- samples/client/petstore/R/R/cat.R | 73 ++++---- samples/client/petstore/R/R/category.R | 65 ++++--- samples/client/petstore/R/R/danish_pig.R | 65 ++++--- samples/client/petstore/R/R/date.R | 73 ++++---- samples/client/petstore/R/R/dog.R | 73 ++++---- samples/client/petstore/R/R/dummy_model.R | 57 +++--- samples/client/petstore/R/R/fake_api.R | 2 +- samples/client/petstore/R/R/format_test.R | 169 ++++-------------- samples/client/petstore/R/R/mammal.R | 28 ++- .../client/petstore/R/R/model_api_response.R | 73 ++++---- samples/client/petstore/R/R/nested_one_of.R | 67 +++---- .../petstore/R/R/one_of_primitive_type_test.R | 28 ++- samples/client/petstore/R/R/order.R | 97 ++++------ samples/client/petstore/R/R/pet.R | 101 ++++------- samples/client/petstore/R/R/pet_api.R | 4 +- samples/client/petstore/R/R/pet_map.R | 57 +++--- samples/client/petstore/R/R/pig.R | 28 ++- samples/client/petstore/R/R/special.R | 105 ++++------- samples/client/petstore/R/R/store_api.R | 2 +- samples/client/petstore/R/R/tag.R | 65 ++++--- .../client/petstore/R/R/update_pet_request.R | 67 +++---- samples/client/petstore/R/R/user.R | 113 ++++-------- samples/client/petstore/R/R/user_api.R | 8 +- samples/client/petstore/R/R/whale.R | 73 ++++---- samples/client/petstore/R/R/zebra.R | 65 ++++--- .../petstore/R/tests/testthat/test_petstore.R | 6 +- 111 files changed, 3072 insertions(+), 3381 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index 2895328c09c..4f18c214f11 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -456,7 +456,7 @@ local_var_body <- `{{paramName}}`$toJSONString() {{/isArray}} } else { - body <- NULL + local_var_body <- NULL } {{/bodyParams}} diff --git a/modules/openapi-generator/src/main/resources/r/modelAnyOf.mustache b/modules/openapi-generator/src/main/resources/r/modelAnyOf.mustache index 62e6dd7e41c..1cdb306be66 100644 --- a/modules/openapi-generator/src/main/resources/r/modelAnyOf.mustache +++ b/modules/openapi-generator/src/main/resources/r/modelAnyOf.mustache @@ -86,27 +86,32 @@ }, #' @description - #' Serialize {{{classname}}} to JSON string. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. + toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert {{{classname}}} to a base R type #' - #' @return JSON string representation of the {{{classname}}}. - toJSONString = function() { + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify((self$actual_instance$toJSONString()))) + return(self$actual_instance$toSimpleType()) } else { NULL } }, #' @description - #' Serialize {{{classname}}} to JSON. + #' Serialize {{{classname}}} to JSON string. #' - #' @return JSON representation of the {{{classname}}}. - toJSON = function() { - if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() - } else { - NULL - } + #' @param ... Parameters passed to `jsonlite::toJSON` + #' @return JSON string representation of the {{{classname}}}. + toJSONString = function(...) { + json <- jsonlite::toJSON(self$toSimpleType(), auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/modules/openapi-generator/src/main/resources/r/modelEnum.mustache b/modules/openapi-generator/src/main/resources/r/modelEnum.mustache index 64d136449be..c0dc60149aa 100644 --- a/modules/openapi-generator/src/main/resources/r/modelEnum.mustache +++ b/modules/openapi-generator/src/main/resources/r/modelEnum.mustache @@ -38,11 +38,18 @@ }, #' @description - #' To JSON String - #' - #' @return {{{classname}}} in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { - jsonlite::toJSON(private$value, auto_unbox = TRUE) + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert {{{classname}}} to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { + return(private$value) }, #' @description @@ -60,10 +67,11 @@ #' @description #' To JSON String #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return {{{classname}}} in JSON format - toJSONString = function() { - as.character(jsonlite::toJSON(private$value, - auto_unbox = TRUE)) + toJSONString = function(...) { + json <- jsonlite::toJSON(self$toSimpleType(), auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/modules/openapi-generator/src/main/resources/r/modelGeneric.mustache b/modules/openapi-generator/src/main/resources/r/modelGeneric.mustache index 24f0ddf8c8f..0da6607925a 100644 --- a/modules/openapi-generator/src/main/resources/r/modelGeneric.mustache +++ b/modules/openapi-generator/src/main/resources/r/modelGeneric.mustache @@ -203,10 +203,35 @@ }, #' @description - #' To JSON String - #' - #' @return {{{classname}}} in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return {{{classname}}} as a base R list. + #' @examples + #' # convert array of {{{classname}}} (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert {{{classname}}} to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { {{classname}}Object <- list() {{#vars}} if (!is.null(self$`{{name}}`)) { @@ -217,7 +242,7 @@ self$`{{name}}` {{/isPrimitiveType}} {{^isPrimitiveType}} - lapply(self$`{{name}}`, function(x) x$toJSON()) + lapply(self$`{{name}}`, function(x) x$toSimpleType()) {{/isPrimitiveType}} {{/isArray}} {{#isMap}} @@ -225,7 +250,7 @@ self$`{{name}}` {{/isPrimitiveType}} {{^isPrimitiveType}} - lapply(self$`{{name}}`, function(x) x$toJSON()) + lapply(self$`{{name}}`, function(x) x$toSimpleType()) {{/isPrimitiveType}} {{/isMap}} {{/isContainer}} @@ -234,7 +259,7 @@ self$`{{name}}` {{/isPrimitiveType}} {{^isPrimitiveType}} - self$`{{name}}`$toJSON() + self$`{{name}}`$toSimpleType() {{/isPrimitiveType}} {{/isContainer}} } @@ -245,7 +270,7 @@ } {{/isAdditionalPropertiesTrue}} - {{classname}}Object + return({{classname}}Object) }, #' @description @@ -304,76 +329,18 @@ #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return {{{classname}}} in JSON format - toJSONString = function() { - jsoncontent <- c( - {{#vars}} - if (!is.null(self$`{{name}}`)) { - sprintf( - '"{{baseName}}": - {{#isContainer}} - {{#isArray}} - {{#isPrimitiveType}} - {{#isNumeric}}[%d]{{/isNumeric}}{{^isNumeric}}[%s]{{/isNumeric}} - {{/isPrimitiveType}} - {{^isPrimitiveType}}[%s] - {{/isPrimitiveType}} - {{/isArray}} - {{#isMap}} - {{#isPrimitiveType}} - {{#isNumeric}}%d{{/isNumeric}}{{^isNumeric}}{{^isBoolean}}{{/isBoolean}}%s{{^isBoolean}}{{/isBoolean}}{{/isNumeric}} - {{/isPrimitiveType}} - {{^isPrimitiveType}}%s - {{/isPrimitiveType}} - {{/isMap}} - {{/isContainer}} - {{^isContainer}} - {{#isPrimitiveType}} - {{#isNumeric}}%d{{/isNumeric}}{{^isNumeric}}{{^isBoolean}}"{{/isBoolean}}%s{{^isBoolean}}"{{/isBoolean}}{{/isNumeric}} - {{/isPrimitiveType}} - {{^isPrimitiveType}}%s - {{/isPrimitiveType}} - {{/isContainer}}', - {{#isContainer}} - {{#isArray}} - {{#isPrimitiveType}} - paste(unlist(lapply(self$`{{{name}}}`, function(x) paste0('"', x, '"'))), collapse = ",") - {{/isPrimitiveType}} - {{^isPrimitiveType}} - paste(sapply(self$`{{{name}}}`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox = TRUE, digits = NA)), collapse = ",") - {{/isPrimitiveType}} - {{/isArray}} - {{#isMap}} - {{#isPrimitiveType}} - jsonlite::toJSON(lapply(self$`{{{name}}}`, function(x){ x }), auto_unbox = TRUE, digits = NA) - {{/isPrimitiveType}} - {{^isPrimitiveType}} - jsonlite::toJSON(lapply(self$`{{{name}}}`, function(x){ x$toJSON() }), auto_unbox = TRUE, digits = NA) - {{/isPrimitiveType}} - {{/isMap}} - {{/isContainer}} - {{^isContainer}} - {{#isPrimitiveType}} - {{#isBoolean}}tolower({{/isBoolean}}self$`{{name}}`{{#isBoolean}}){{/isBoolean}} - {{/isPrimitiveType}} - {{^isPrimitiveType}} - jsonlite::toJSON(self$`{{name}}`$toJSON(), auto_unbox = TRUE, digits = NA) - {{/isPrimitiveType}} - {{/isContainer}} - ) - }{{^-last}},{{/-last}} - {{/vars}} - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() {{#isAdditionalPropertiesTrue}} - json_obj <- jsonlite::fromJSON(json_string) for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) {{/isAdditionalPropertiesTrue}} + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/modules/openapi-generator/src/main/resources/r/modelOneOf.mustache b/modules/openapi-generator/src/main/resources/r/modelOneOf.mustache index 4fe94c4ad04..998687b5efb 100644 --- a/modules/openapi-generator/src/main/resources/r/modelOneOf.mustache +++ b/modules/openapi-generator/src/main/resources/r/modelOneOf.mustache @@ -139,25 +139,35 @@ #' @description #' Serialize {{{classname}}} to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the {{{classname}}}. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize {{{classname}}} to JSON. - #' - #' @return JSON representation of the {{{classname}}}. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert {{{classname}}} to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/echo_api/r/R/bird.R b/samples/client/echo_api/r/R/bird.R index 5132beb3788..97921b1c4c8 100644 --- a/samples/client/echo_api/r/R/bird.R +++ b/samples/client/echo_api/r/R/bird.R @@ -40,10 +40,35 @@ Bird <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Bird in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Bird as a base R list. + #' @examples + #' # convert array of Bird (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Bird to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { BirdObject <- list() if (!is.null(self$`size`)) { BirdObject[["size"]] <- @@ -53,7 +78,7 @@ Bird <- R6::R6Class( BirdObject[["color"]] <- self$`color` } - BirdObject + return(BirdObject) }, #' @description @@ -74,29 +99,13 @@ Bird <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Bird in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`size`)) { - sprintf( - '"size": - "%s" - ', - self$`size` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/echo_api/r/R/body_api.R b/samples/client/echo_api/r/R/body_api.R index 1be1cafba8b..9f16d197edc 100644 --- a/samples/client/echo_api/r/R/body_api.R +++ b/samples/client/echo_api/r/R/body_api.R @@ -304,7 +304,7 @@ BodyApi <- R6::R6Class( if (!is.null(`body`)) { local_var_body <- `body`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/body/application/octetstream/binary" @@ -586,7 +586,7 @@ BodyApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/echo/body/allOf/Pet" @@ -682,7 +682,7 @@ BodyApi <- R6::R6Class( if (!is.null(`body`)) { local_var_body <- `body`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/echo/body/FreeFormObject/response_string" @@ -778,7 +778,7 @@ BodyApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/echo/body/Pet" @@ -874,7 +874,7 @@ BodyApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/echo/body/Pet/response_string" @@ -970,7 +970,7 @@ BodyApi <- R6::R6Class( if (!is.null(`body`)) { local_var_body <- `body`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/echo/body/string_enum" @@ -1066,7 +1066,7 @@ BodyApi <- R6::R6Class( if (!is.null(`tag`)) { local_var_body <- `tag`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/echo/body/Tag/response_string" diff --git a/samples/client/echo_api/r/R/category.R b/samples/client/echo_api/r/R/category.R index cbf3a88b9dd..56aa6967177 100644 --- a/samples/client/echo_api/r/R/category.R +++ b/samples/client/echo_api/r/R/category.R @@ -40,10 +40,35 @@ Category <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Category in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Category as a base R list. + #' @examples + #' # convert array of Category (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Category to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { CategoryObject <- list() if (!is.null(self$`id`)) { CategoryObject[["id"]] <- @@ -53,7 +78,7 @@ Category <- R6::R6Class( CategoryObject[["name"]] <- self$`name` } - CategoryObject + return(CategoryObject) }, #' @description @@ -74,29 +99,13 @@ Category <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Category in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/echo_api/r/R/data_query.R b/samples/client/echo_api/r/R/data_query.R index edc0bcda0a7..1340544416d 100644 --- a/samples/client/echo_api/r/R/data_query.R +++ b/samples/client/echo_api/r/R/data_query.R @@ -67,10 +67,35 @@ DataQuery <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return DataQuery in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return DataQuery as a base R list. + #' @examples + #' # convert array of DataQuery (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert DataQuery to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DataQueryObject <- list() if (!is.null(self$`id`)) { DataQueryObject[["id"]] <- @@ -92,7 +117,7 @@ DataQuery <- R6::R6Class( DataQueryObject[["date"]] <- self$`date` } - DataQueryObject + return(DataQueryObject) }, #' @description @@ -122,53 +147,13 @@ DataQuery <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return DataQuery in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`outcomes`)) { - sprintf( - '"outcomes": - [%s] - ', - paste(unlist(lapply(self$`outcomes`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`suffix`)) { - sprintf( - '"suffix": - "%s" - ', - self$`suffix` - ) - }, - if (!is.null(self$`text`)) { - sprintf( - '"text": - "%s" - ', - self$`text` - ) - }, - if (!is.null(self$`date`)) { - sprintf( - '"date": - "%s" - ', - self$`date` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/echo_api/r/R/default_value.R b/samples/client/echo_api/r/R/default_value.R index 4456d7fcea0..2a3a83f3265 100644 --- a/samples/client/echo_api/r/R/default_value.R +++ b/samples/client/echo_api/r/R/default_value.R @@ -87,14 +87,39 @@ DefaultValue <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return DefaultValue in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return DefaultValue as a base R list. + #' @examples + #' # convert array of DefaultValue (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert DefaultValue to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DefaultValueObject <- list() if (!is.null(self$`array_string_enum_ref_default`)) { DefaultValueObject[["array_string_enum_ref_default"]] <- - lapply(self$`array_string_enum_ref_default`, function(x) x$toJSON()) + lapply(self$`array_string_enum_ref_default`, function(x) x$toSimpleType()) } if (!is.null(self$`array_string_enum_default`)) { DefaultValueObject[["array_string_enum_default"]] <- @@ -124,7 +149,7 @@ DefaultValue <- R6::R6Class( DefaultValueObject[["string_nullable"]] <- self$`string_nullable` } - DefaultValueObject + return(DefaultValueObject) }, #' @description @@ -163,77 +188,13 @@ DefaultValue <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return DefaultValue in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`array_string_enum_ref_default`)) { - sprintf( - '"array_string_enum_ref_default": - [%s] -', - paste(sapply(self$`array_string_enum_ref_default`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox = TRUE, digits = NA)), collapse = ",") - ) - }, - if (!is.null(self$`array_string_enum_default`)) { - sprintf( - '"array_string_enum_default": - [%s] - ', - paste(unlist(lapply(self$`array_string_enum_default`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`array_string_default`)) { - sprintf( - '"array_string_default": - [%s] - ', - paste(unlist(lapply(self$`array_string_default`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`array_integer_default`)) { - sprintf( - '"array_integer_default": - [%s] - ', - paste(unlist(lapply(self$`array_integer_default`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`array_string`)) { - sprintf( - '"array_string": - [%s] - ', - paste(unlist(lapply(self$`array_string`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`array_string_nullable`)) { - sprintf( - '"array_string_nullable": - [%s] - ', - paste(unlist(lapply(self$`array_string_nullable`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`array_string_extension_nullable`)) { - sprintf( - '"array_string_extension_nullable": - [%s] - ', - paste(unlist(lapply(self$`array_string_extension_nullable`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`string_nullable`)) { - sprintf( - '"string_nullable": - "%s" - ', - self$`string_nullable` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/echo_api/r/R/number_properties_only.R b/samples/client/echo_api/r/R/number_properties_only.R index 7b0b698630f..7b146800ad3 100644 --- a/samples/client/echo_api/r/R/number_properties_only.R +++ b/samples/client/echo_api/r/R/number_properties_only.R @@ -46,10 +46,35 @@ NumberPropertiesOnly <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return NumberPropertiesOnly in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return NumberPropertiesOnly as a base R list. + #' @examples + #' # convert array of NumberPropertiesOnly (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert NumberPropertiesOnly to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { NumberPropertiesOnlyObject <- list() if (!is.null(self$`number`)) { NumberPropertiesOnlyObject[["number"]] <- @@ -63,7 +88,7 @@ NumberPropertiesOnly <- R6::R6Class( NumberPropertiesOnlyObject[["double"]] <- self$`double` } - NumberPropertiesOnlyObject + return(NumberPropertiesOnlyObject) }, #' @description @@ -87,37 +112,13 @@ NumberPropertiesOnly <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return NumberPropertiesOnly in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`number`)) { - sprintf( - '"number": - %d - ', - self$`number` - ) - }, - if (!is.null(self$`float`)) { - sprintf( - '"float": - %d - ', - self$`float` - ) - }, - if (!is.null(self$`double`)) { - sprintf( - '"double": - %d - ', - self$`double` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/echo_api/r/R/pet.R b/samples/client/echo_api/r/R/pet.R index b03d04e66cd..6f59d7ea1f6 100644 --- a/samples/client/echo_api/r/R/pet.R +++ b/samples/client/echo_api/r/R/pet.R @@ -75,10 +75,35 @@ Pet <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Pet in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Pet as a base R list. + #' @examples + #' # convert array of Pet (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Pet to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { PetObject <- list() if (!is.null(self$`id`)) { PetObject[["id"]] <- @@ -90,7 +115,7 @@ Pet <- R6::R6Class( } if (!is.null(self$`category`)) { PetObject[["category"]] <- - self$`category`$toJSON() + self$`category`$toSimpleType() } if (!is.null(self$`photoUrls`)) { PetObject[["photoUrls"]] <- @@ -98,13 +123,13 @@ Pet <- R6::R6Class( } if (!is.null(self$`tags`)) { PetObject[["tags"]] <- - lapply(self$`tags`, function(x) x$toJSON()) + lapply(self$`tags`, function(x) x$toSimpleType()) } if (!is.null(self$`status`)) { PetObject[["status"]] <- self$`status` } - PetObject + return(PetObject) }, #' @description @@ -142,61 +167,13 @@ Pet <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Pet in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - }, - if (!is.null(self$`category`)) { - sprintf( - '"category": - %s - ', - jsonlite::toJSON(self$`category`$toJSON(), auto_unbox = TRUE, digits = NA) - ) - }, - if (!is.null(self$`photoUrls`)) { - sprintf( - '"photoUrls": - [%s] - ', - paste(unlist(lapply(self$`photoUrls`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`tags`)) { - sprintf( - '"tags": - [%s] -', - paste(sapply(self$`tags`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox = TRUE, digits = NA)), collapse = ",") - ) - }, - if (!is.null(self$`status`)) { - sprintf( - '"status": - "%s" - ', - self$`status` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/echo_api/r/R/query.R b/samples/client/echo_api/r/R/query.R index 527a97226b1..fd286ab3016 100644 --- a/samples/client/echo_api/r/R/query.R +++ b/samples/client/echo_api/r/R/query.R @@ -39,10 +39,35 @@ Query <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Query in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Query as a base R list. + #' @examples + #' # convert array of Query (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Query to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { QueryObject <- list() if (!is.null(self$`id`)) { QueryObject[["id"]] <- @@ -52,7 +77,7 @@ Query <- R6::R6Class( QueryObject[["outcomes"]] <- self$`outcomes` } - QueryObject + return(QueryObject) }, #' @description @@ -73,29 +98,13 @@ Query <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Query in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`outcomes`)) { - sprintf( - '"outcomes": - [%s] - ', - paste(unlist(lapply(self$`outcomes`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/echo_api/r/R/string_enum_ref.R b/samples/client/echo_api/r/R/string_enum_ref.R index 1be463a1655..ee9afe6cf4a 100644 --- a/samples/client/echo_api/r/R/string_enum_ref.R +++ b/samples/client/echo_api/r/R/string_enum_ref.R @@ -37,11 +37,18 @@ StringEnumRef <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return StringEnumRef in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { - jsonlite::toJSON(private$value, auto_unbox = TRUE) + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert StringEnumRef to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { + return(private$value) }, #' @description @@ -59,10 +66,11 @@ StringEnumRef <- R6::R6Class( #' @description #' To JSON String #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return StringEnumRef in JSON format - toJSONString = function() { - as.character(jsonlite::toJSON(private$value, - auto_unbox = TRUE)) + toJSONString = function(...) { + json <- jsonlite::toJSON(self$toSimpleType(), auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/echo_api/r/R/tag.R b/samples/client/echo_api/r/R/tag.R index b23305a43af..3a0d3c1d239 100644 --- a/samples/client/echo_api/r/R/tag.R +++ b/samples/client/echo_api/r/R/tag.R @@ -40,10 +40,35 @@ Tag <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Tag in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Tag as a base R list. + #' @examples + #' # convert array of Tag (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Tag to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { TagObject <- list() if (!is.null(self$`id`)) { TagObject[["id"]] <- @@ -53,7 +78,7 @@ Tag <- R6::R6Class( TagObject[["name"]] <- self$`name` } - TagObject + return(TagObject) }, #' @description @@ -74,29 +99,13 @@ Tag <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Tag in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/echo_api/r/R/test_form_object_multipart_request_marker.R b/samples/client/echo_api/r/R/test_form_object_multipart_request_marker.R index 6c523622cde..5c9776f78eb 100644 --- a/samples/client/echo_api/r/R/test_form_object_multipart_request_marker.R +++ b/samples/client/echo_api/r/R/test_form_object_multipart_request_marker.R @@ -31,16 +31,41 @@ TestFormObjectMultipartRequestMarker <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return TestFormObjectMultipartRequestMarker in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return TestFormObjectMultipartRequestMarker as a base R list. + #' @examples + #' # convert array of TestFormObjectMultipartRequestMarker (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert TestFormObjectMultipartRequestMarker to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { TestFormObjectMultipartRequestMarkerObject <- list() if (!is.null(self$`name`)) { TestFormObjectMultipartRequestMarkerObject[["name"]] <- self$`name` } - TestFormObjectMultipartRequestMarkerObject + return(TestFormObjectMultipartRequestMarkerObject) }, #' @description @@ -58,21 +83,13 @@ TestFormObjectMultipartRequestMarker <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return TestFormObjectMultipartRequestMarker in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/echo_api/r/R/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.R b/samples/client/echo_api/r/R/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.R index 8616e605bf9..a441c20a8be 100644 --- a/samples/client/echo_api/r/R/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.R +++ b/samples/client/echo_api/r/R/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.R @@ -58,10 +58,35 @@ TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter <- R6::R6Clas }, #' @description - #' To JSON String - #' - #' @return TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter as a base R list. + #' @examples + #' # convert array of TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameterObject <- list() if (!is.null(self$`size`)) { TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameterObject[["size"]] <- @@ -79,7 +104,7 @@ TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter <- R6::R6Clas TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameterObject[["name"]] <- self$`name` } - TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameterObject + return(TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameterObject) }, #' @description @@ -106,45 +131,13 @@ TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter <- R6::R6Clas #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`size`)) { - sprintf( - '"size": - "%s" - ', - self$`size` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - }, - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/echo_api/r/R/test_query_style_form_explode_true_array_string_query_object_parameter.R b/samples/client/echo_api/r/R/test_query_style_form_explode_true_array_string_query_object_parameter.R index a6e69b27f3b..9a874c05c0d 100644 --- a/samples/client/echo_api/r/R/test_query_style_form_explode_true_array_string_query_object_parameter.R +++ b/samples/client/echo_api/r/R/test_query_style_form_explode_true_array_string_query_object_parameter.R @@ -30,16 +30,41 @@ TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter as a base R list. + #' @examples + #' # convert array of TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameterObject <- list() if (!is.null(self$`values`)) { TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameterObject[["values"]] <- self$`values` } - TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameterObject + return(TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameterObject) }, #' @description @@ -57,21 +82,13 @@ TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`values`)) { - sprintf( - '"values": - [%s] - ', - paste(unlist(lapply(self$`values`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/allof_tag_api_response.R b/samples/client/petstore/R-httr2-wrapper/R/allof_tag_api_response.R index 454e378a5c1..018600362d3 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/allof_tag_api_response.R +++ b/samples/client/petstore/R-httr2-wrapper/R/allof_tag_api_response.R @@ -77,10 +77,35 @@ AllofTagApiResponse <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return AllofTagApiResponse in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return AllofTagApiResponse as a base R list. + #' @examples + #' # convert array of AllofTagApiResponse (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert AllofTagApiResponse to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { AllofTagApiResponseObject <- list() if (!is.null(self$`id`)) { AllofTagApiResponseObject[["id"]] <- @@ -106,7 +131,7 @@ AllofTagApiResponse <- R6::R6Class( AllofTagApiResponseObject[[key]] <- self$additional_properties[[key]] } - AllofTagApiResponseObject + return(AllofTagApiResponseObject) }, #' @description @@ -143,58 +168,16 @@ AllofTagApiResponse <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return AllofTagApiResponse in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - }, - if (!is.null(self$`code`)) { - sprintf( - '"code": - %d - ', - self$`code` - ) - }, - if (!is.null(self$`type`)) { - sprintf( - '"type": - "%s" - ', - self$`type` - ) - }, - if (!is.null(self$`message`)) { - sprintf( - '"message": - "%s" - ', - self$`message` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/animal.R b/samples/client/petstore/R-httr2-wrapper/R/animal.R index 471a01afef3..cf2e97f9af3 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/animal.R +++ b/samples/client/petstore/R-httr2-wrapper/R/animal.R @@ -52,10 +52,35 @@ Animal <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Animal in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Animal as a base R list. + #' @examples + #' # convert array of Animal (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Animal to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { AnimalObject <- list() if (!is.null(self$`className`)) { AnimalObject[["className"]] <- @@ -69,7 +94,7 @@ Animal <- R6::R6Class( AnimalObject[[key]] <- self$additional_properties[[key]] } - AnimalObject + return(AnimalObject) }, #' @description @@ -97,34 +122,16 @@ Animal <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Animal in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/any_of_pig.R b/samples/client/petstore/R-httr2-wrapper/R/any_of_pig.R index ba3c8ea856d..7480eec7696 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/any_of_pig.R +++ b/samples/client/petstore/R-httr2-wrapper/R/any_of_pig.R @@ -91,27 +91,32 @@ AnyOfPig <- R6::R6Class( }, #' @description - #' Serialize AnyOfPig to JSON string. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. + toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert AnyOfPig to a base R type #' - #' @return JSON string representation of the AnyOfPig. - toJSONString = function() { + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify((self$actual_instance$toJSONString()))) + return(self$actual_instance$toSimpleType()) } else { NULL } }, #' @description - #' Serialize AnyOfPig to JSON. + #' Serialize AnyOfPig to JSON string. #' - #' @return JSON representation of the AnyOfPig. - toJSON = function() { - if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() - } else { - NULL - } + #' @param ... Parameters passed to `jsonlite::toJSON` + #' @return JSON string representation of the AnyOfPig. + toJSONString = function(...) { + json <- jsonlite::toJSON(self$toSimpleType(), auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/any_of_primitive_type_test.R b/samples/client/petstore/R-httr2-wrapper/R/any_of_primitive_type_test.R index 99aa52c7342..f76defe9f4a 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/any_of_primitive_type_test.R +++ b/samples/client/petstore/R-httr2-wrapper/R/any_of_primitive_type_test.R @@ -111,25 +111,35 @@ AnyOfPrimitiveTypeTest <- R6::R6Class( #' @description #' Serialize AnyOfPrimitiveTypeTest to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the AnyOfPrimitiveTypeTest. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize AnyOfPrimitiveTypeTest to JSON. - #' - #' @return JSON representation of the AnyOfPrimitiveTypeTest. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert AnyOfPrimitiveTypeTest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R-httr2-wrapper/R/basque_pig.R b/samples/client/petstore/R-httr2-wrapper/R/basque_pig.R index cce82cd7d93..ca8601f4c3b 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/basque_pig.R +++ b/samples/client/petstore/R-httr2-wrapper/R/basque_pig.R @@ -50,10 +50,35 @@ BasquePig <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return BasquePig in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return BasquePig as a base R list. + #' @examples + #' # convert array of BasquePig (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert BasquePig to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { BasquePigObject <- list() if (!is.null(self$`className`)) { BasquePigObject[["className"]] <- @@ -67,7 +92,7 @@ BasquePig <- R6::R6Class( BasquePigObject[[key]] <- self$additional_properties[[key]] } - BasquePigObject + return(BasquePigObject) }, #' @description @@ -95,34 +120,16 @@ BasquePig <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return BasquePig in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/cat.R b/samples/client/petstore/R-httr2-wrapper/R/cat.R index b4014681ba4..270b87c2164 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/cat.R +++ b/samples/client/petstore/R-httr2-wrapper/R/cat.R @@ -60,10 +60,35 @@ Cat <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Cat in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Cat as a base R list. + #' @examples + #' # convert array of Cat (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Cat to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { CatObject <- list() if (!is.null(self$`className`)) { CatObject[["className"]] <- @@ -81,7 +106,7 @@ Cat <- R6::R6Class( CatObject[[key]] <- self$additional_properties[[key]] } - CatObject + return(CatObject) }, #' @description @@ -112,42 +137,16 @@ Cat <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Cat in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - }, - if (!is.null(self$`declawed`)) { - sprintf( - '"declawed": - %s - ', - tolower(self$`declawed`) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/category.R b/samples/client/petstore/R-httr2-wrapper/R/category.R index 31106a3bc9e..0dcbd1b8161 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/category.R +++ b/samples/client/petstore/R-httr2-wrapper/R/category.R @@ -50,10 +50,35 @@ Category <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Category in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Category as a base R list. + #' @examples + #' # convert array of Category (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Category to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { CategoryObject <- list() if (!is.null(self$`id`)) { CategoryObject[["id"]] <- @@ -67,7 +92,7 @@ Category <- R6::R6Class( CategoryObject[[key]] <- self$additional_properties[[key]] } - CategoryObject + return(CategoryObject) }, #' @description @@ -95,34 +120,16 @@ Category <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Category in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/danish_pig.R b/samples/client/petstore/R-httr2-wrapper/R/danish_pig.R index 08ca2b9e3ee..02d2208639b 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/danish_pig.R +++ b/samples/client/petstore/R-httr2-wrapper/R/danish_pig.R @@ -50,10 +50,35 @@ DanishPig <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return DanishPig in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return DanishPig as a base R list. + #' @examples + #' # convert array of DanishPig (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert DanishPig to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DanishPigObject <- list() if (!is.null(self$`className`)) { DanishPigObject[["className"]] <- @@ -67,7 +92,7 @@ DanishPig <- R6::R6Class( DanishPigObject[[key]] <- self$additional_properties[[key]] } - DanishPigObject + return(DanishPigObject) }, #' @description @@ -95,34 +120,16 @@ DanishPig <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return DanishPig in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`size`)) { - sprintf( - '"size": - %d - ', - self$`size` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/date.R b/samples/client/petstore/R-httr2-wrapper/R/date.R index d9b6ec0beb1..411249d3fba 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/date.R +++ b/samples/client/petstore/R-httr2-wrapper/R/date.R @@ -63,10 +63,35 @@ Date <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Date in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Date as a base R list. + #' @examples + #' # convert array of Date (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Date to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DateObject <- list() if (!is.null(self$`className`)) { DateObject[["className"]] <- @@ -84,7 +109,7 @@ Date <- R6::R6Class( DateObject[[key]] <- self$additional_properties[[key]] } - DateObject + return(DateObject) }, #' @description @@ -119,42 +144,16 @@ Date <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Date in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`percent_description`)) { - sprintf( - '"percent_description": - "%s" - ', - self$`percent_description` - ) - }, - if (!is.null(self$`url_property`)) { - sprintf( - '"url_property": - "%s" - ', - self$`url_property` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/dog.R b/samples/client/petstore/R-httr2-wrapper/R/dog.R index 34ae2912116..4d6dab71c61 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/dog.R +++ b/samples/client/petstore/R-httr2-wrapper/R/dog.R @@ -60,10 +60,35 @@ Dog <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Dog in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Dog as a base R list. + #' @examples + #' # convert array of Dog (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Dog to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DogObject <- list() if (!is.null(self$`className`)) { DogObject[["className"]] <- @@ -81,7 +106,7 @@ Dog <- R6::R6Class( DogObject[[key]] <- self$additional_properties[[key]] } - DogObject + return(DogObject) }, #' @description @@ -112,42 +137,16 @@ Dog <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Dog in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - }, - if (!is.null(self$`breed`)) { - sprintf( - '"breed": - "%s" - ', - self$`breed` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/dummy_model.R b/samples/client/petstore/R-httr2-wrapper/R/dummy_model.R index 12d3ab52a15..cbea7830b82 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/dummy_model.R +++ b/samples/client/petstore/R-httr2-wrapper/R/dummy_model.R @@ -41,10 +41,35 @@ DummyModel <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return DummyModel in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return DummyModel as a base R list. + #' @examples + #' # convert array of DummyModel (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert DummyModel to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DummyModelObject <- list() if (!is.null(self$`property`)) { DummyModelObject[["property"]] <- @@ -54,7 +79,7 @@ DummyModel <- R6::R6Class( DummyModelObject[[key]] <- self$additional_properties[[key]] } - DummyModelObject + return(DummyModelObject) }, #' @description @@ -79,26 +104,16 @@ DummyModel <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return DummyModel in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`property`)) { - sprintf( - '"property": - "%s" - ', - self$`property` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/fake_api.R b/samples/client/petstore/R-httr2-wrapper/R/fake_api.R index 5dae105c228..b314363f4b6 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/fake_api.R +++ b/samples/client/petstore/R-httr2-wrapper/R/fake_api.R @@ -225,7 +225,7 @@ FakeApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/fake/test_optional_body_parameter" diff --git a/samples/client/petstore/R-httr2-wrapper/R/format_test.R b/samples/client/petstore/R-httr2-wrapper/R/format_test.R index f93bf1435c9..7d1bded3c5a 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/format_test.R +++ b/samples/client/petstore/R-httr2-wrapper/R/format_test.R @@ -158,10 +158,35 @@ FormatTest <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return FormatTest in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return FormatTest as a base R list. + #' @examples + #' # convert array of FormatTest (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert FormatTest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { FormatTestObject <- list() if (!is.null(self$`integer`)) { FormatTestObject[["integer"]] <- @@ -227,7 +252,7 @@ FormatTest <- R6::R6Class( FormatTestObject[[key]] <- self$additional_properties[[key]] } - FormatTestObject + return(FormatTestObject) }, #' @description @@ -294,138 +319,16 @@ FormatTest <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return FormatTest in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`integer`)) { - sprintf( - '"integer": - %d - ', - self$`integer` - ) - }, - if (!is.null(self$`int32`)) { - sprintf( - '"int32": - %d - ', - self$`int32` - ) - }, - if (!is.null(self$`int64`)) { - sprintf( - '"int64": - %d - ', - self$`int64` - ) - }, - if (!is.null(self$`number`)) { - sprintf( - '"number": - %d - ', - self$`number` - ) - }, - if (!is.null(self$`float`)) { - sprintf( - '"float": - %d - ', - self$`float` - ) - }, - if (!is.null(self$`double`)) { - sprintf( - '"double": - %d - ', - self$`double` - ) - }, - if (!is.null(self$`string`)) { - sprintf( - '"string": - "%s" - ', - self$`string` - ) - }, - if (!is.null(self$`byte`)) { - sprintf( - '"byte": - "%s" - ', - self$`byte` - ) - }, - if (!is.null(self$`binary`)) { - sprintf( - '"binary": - "%s" - ', - self$`binary` - ) - }, - if (!is.null(self$`date`)) { - sprintf( - '"date": - "%s" - ', - self$`date` - ) - }, - if (!is.null(self$`dateTime`)) { - sprintf( - '"dateTime": - "%s" - ', - self$`dateTime` - ) - }, - if (!is.null(self$`uuid`)) { - sprintf( - '"uuid": - "%s" - ', - self$`uuid` - ) - }, - if (!is.null(self$`password`)) { - sprintf( - '"password": - "%s" - ', - self$`password` - ) - }, - if (!is.null(self$`pattern_with_digits`)) { - sprintf( - '"pattern_with_digits": - "%s" - ', - self$`pattern_with_digits` - ) - }, - if (!is.null(self$`pattern_with_digits_and_delimiter`)) { - sprintf( - '"pattern_with_digits_and_delimiter": - "%s" - ', - self$`pattern_with_digits_and_delimiter` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/mammal.R b/samples/client/petstore/R-httr2-wrapper/R/mammal.R index fe4f3577d0c..29b32a31bcb 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/mammal.R +++ b/samples/client/petstore/R-httr2-wrapper/R/mammal.R @@ -135,25 +135,35 @@ Mammal <- R6::R6Class( #' @description #' Serialize Mammal to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the Mammal. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize Mammal to JSON. - #' - #' @return JSON representation of the Mammal. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert Mammal to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R-httr2-wrapper/R/model_api_response.R b/samples/client/petstore/R-httr2-wrapper/R/model_api_response.R index 9116e438fed..a3a46dfb790 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/model_api_response.R +++ b/samples/client/petstore/R-httr2-wrapper/R/model_api_response.R @@ -59,10 +59,35 @@ ModelApiResponse <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return ModelApiResponse in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return ModelApiResponse as a base R list. + #' @examples + #' # convert array of ModelApiResponse (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert ModelApiResponse to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { ModelApiResponseObject <- list() if (!is.null(self$`code`)) { ModelApiResponseObject[["code"]] <- @@ -80,7 +105,7 @@ ModelApiResponse <- R6::R6Class( ModelApiResponseObject[[key]] <- self$additional_properties[[key]] } - ModelApiResponseObject + return(ModelApiResponseObject) }, #' @description @@ -111,42 +136,16 @@ ModelApiResponse <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return ModelApiResponse in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`code`)) { - sprintf( - '"code": - %d - ', - self$`code` - ) - }, - if (!is.null(self$`type`)) { - sprintf( - '"type": - "%s" - ', - self$`type` - ) - }, - if (!is.null(self$`message`)) { - sprintf( - '"message": - "%s" - ', - self$`message` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/nested_one_of.R b/samples/client/petstore/R-httr2-wrapper/R/nested_one_of.R index e04a31a69ac..31dcc2f10d0 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/nested_one_of.R +++ b/samples/client/petstore/R-httr2-wrapper/R/nested_one_of.R @@ -48,10 +48,35 @@ NestedOneOf <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return NestedOneOf in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return NestedOneOf as a base R list. + #' @examples + #' # convert array of NestedOneOf (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert NestedOneOf to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { NestedOneOfObject <- list() if (!is.null(self$`size`)) { NestedOneOfObject[["size"]] <- @@ -59,13 +84,13 @@ NestedOneOf <- R6::R6Class( } if (!is.null(self$`nested_pig`)) { NestedOneOfObject[["nested_pig"]] <- - self$`nested_pig`$toJSON() + self$`nested_pig`$toSimpleType() } for (key in names(self$additional_properties)) { NestedOneOfObject[[key]] <- self$additional_properties[[key]] } - NestedOneOfObject + return(NestedOneOfObject) }, #' @description @@ -95,34 +120,16 @@ NestedOneOf <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return NestedOneOf in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`size`)) { - sprintf( - '"size": - %d - ', - self$`size` - ) - }, - if (!is.null(self$`nested_pig`)) { - sprintf( - '"nested_pig": - %s - ', - jsonlite::toJSON(self$`nested_pig`$toJSON(), auto_unbox = TRUE, digits = NA) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/one_of_primitive_type_test.R b/samples/client/petstore/R-httr2-wrapper/R/one_of_primitive_type_test.R index 8a9280a9b21..e5b56698562 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/one_of_primitive_type_test.R +++ b/samples/client/petstore/R-httr2-wrapper/R/one_of_primitive_type_test.R @@ -111,25 +111,35 @@ OneOfPrimitiveTypeTest <- R6::R6Class( #' @description #' Serialize OneOfPrimitiveTypeTest to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the OneOfPrimitiveTypeTest. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize OneOfPrimitiveTypeTest to JSON. - #' - #' @return JSON representation of the OneOfPrimitiveTypeTest. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert OneOfPrimitiveTypeTest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R-httr2-wrapper/R/order.R b/samples/client/petstore/R-httr2-wrapper/R/order.R index cd84eed74ee..07378f03666 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/order.R +++ b/samples/client/petstore/R-httr2-wrapper/R/order.R @@ -89,10 +89,35 @@ Order <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Order in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Order as a base R list. + #' @examples + #' # convert array of Order (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Order to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { OrderObject <- list() if (!is.null(self$`id`)) { OrderObject[["id"]] <- @@ -122,7 +147,7 @@ Order <- R6::R6Class( OrderObject[[key]] <- self$additional_properties[[key]] } - OrderObject + return(OrderObject) }, #' @description @@ -165,66 +190,16 @@ Order <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Order in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`petId`)) { - sprintf( - '"petId": - %d - ', - self$`petId` - ) - }, - if (!is.null(self$`quantity`)) { - sprintf( - '"quantity": - %d - ', - self$`quantity` - ) - }, - if (!is.null(self$`shipDate`)) { - sprintf( - '"shipDate": - "%s" - ', - self$`shipDate` - ) - }, - if (!is.null(self$`status`)) { - sprintf( - '"status": - "%s" - ', - self$`status` - ) - }, - if (!is.null(self$`complete`)) { - sprintf( - '"complete": - %s - ', - tolower(self$`complete`) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/pet.R b/samples/client/petstore/R-httr2-wrapper/R/pet.R index 28e1693c419..27db68d8fdb 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/pet.R +++ b/samples/client/petstore/R-httr2-wrapper/R/pet.R @@ -85,10 +85,35 @@ Pet <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Pet in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Pet as a base R list. + #' @examples + #' # convert array of Pet (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Pet to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { PetObject <- list() if (!is.null(self$`id`)) { PetObject[["id"]] <- @@ -96,7 +121,7 @@ Pet <- R6::R6Class( } if (!is.null(self$`category`)) { PetObject[["category"]] <- - self$`category`$toJSON() + self$`category`$toSimpleType() } if (!is.null(self$`name`)) { PetObject[["name"]] <- @@ -108,7 +133,7 @@ Pet <- R6::R6Class( } if (!is.null(self$`tags`)) { PetObject[["tags"]] <- - lapply(self$`tags`, function(x) x$toJSON()) + lapply(self$`tags`, function(x) x$toSimpleType()) } if (!is.null(self$`status`)) { PetObject[["status"]] <- @@ -118,7 +143,7 @@ Pet <- R6::R6Class( PetObject[[key]] <- self$additional_properties[[key]] } - PetObject + return(PetObject) }, #' @description @@ -163,66 +188,16 @@ Pet <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Pet in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`category`)) { - sprintf( - '"category": - %s - ', - jsonlite::toJSON(self$`category`$toJSON(), auto_unbox = TRUE, digits = NA) - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - }, - if (!is.null(self$`photoUrls`)) { - sprintf( - '"photoUrls": - [%s] - ', - paste(unlist(lapply(self$`photoUrls`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`tags`)) { - sprintf( - '"tags": - [%s] -', - paste(sapply(self$`tags`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox = TRUE, digits = NA)), collapse = ",") - ) - }, - if (!is.null(self$`status`)) { - sprintf( - '"status": - "%s" - ', - self$`status` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/pet_api.R b/samples/client/petstore/R-httr2-wrapper/R/pet_api.R index b19e01d9d8a..e32bd6cea71 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/pet_api.R +++ b/samples/client/petstore/R-httr2-wrapper/R/pet_api.R @@ -435,7 +435,7 @@ PetApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/pet" @@ -1288,7 +1288,7 @@ PetApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/pet" diff --git a/samples/client/petstore/R-httr2-wrapper/R/pet_map.R b/samples/client/petstore/R-httr2-wrapper/R/pet_map.R index 1fc910ac1da..aa59c50a09c 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/pet_map.R +++ b/samples/client/petstore/R-httr2-wrapper/R/pet_map.R @@ -40,10 +40,35 @@ PetMap <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return PetMap in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return PetMap as a base R list. + #' @examples + #' # convert array of PetMap (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert PetMap to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { PetMapObject <- list() if (!is.null(self$`pet`)) { PetMapObject[["pet"]] <- @@ -53,7 +78,7 @@ PetMap <- R6::R6Class( PetMapObject[[key]] <- self$additional_properties[[key]] } - PetMapObject + return(PetMapObject) }, #' @description @@ -78,26 +103,16 @@ PetMap <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return PetMap in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`pet`)) { - sprintf( - '"pet": - %s - ', - jsonlite::toJSON(lapply(self$`pet`, function(x){ x }), auto_unbox = TRUE, digits = NA) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/pig.R b/samples/client/petstore/R-httr2-wrapper/R/pig.R index 6e0242ca3e9..11c4f531b94 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/pig.R +++ b/samples/client/petstore/R-httr2-wrapper/R/pig.R @@ -135,25 +135,35 @@ Pig <- R6::R6Class( #' @description #' Serialize Pig to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the Pig. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize Pig to JSON. - #' - #' @return JSON representation of the Pig. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert Pig to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R-httr2-wrapper/R/special.R b/samples/client/petstore/R-httr2-wrapper/R/special.R index 5841fc79dd3..4c27190313f 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/special.R +++ b/samples/client/petstore/R-httr2-wrapper/R/special.R @@ -97,10 +97,35 @@ Special <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Special in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Special as a base R list. + #' @examples + #' # convert array of Special (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Special to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { SpecialObject <- list() if (!is.null(self$`set_test`)) { SpecialObject[["set_test"]] <- @@ -134,7 +159,7 @@ Special <- R6::R6Class( SpecialObject[[key]] <- self$additional_properties[[key]] } - SpecialObject + return(SpecialObject) }, #' @description @@ -180,74 +205,16 @@ Special <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Special in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`set_test`)) { - sprintf( - '"set_test": - [%s] - ', - paste(unlist(lapply(self$`set_test`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`item_self`)) { - sprintf( - '"self": - %d - ', - self$`item_self` - ) - }, - if (!is.null(self$`item_private`)) { - sprintf( - '"private": - "%s" - ', - self$`item_private` - ) - }, - if (!is.null(self$`item_super`)) { - sprintf( - '"super": - "%s" - ', - self$`item_super` - ) - }, - if (!is.null(self$`123_number`)) { - sprintf( - '"123_number": - "%s" - ', - self$`123_number` - ) - }, - if (!is.null(self$`array[test]`)) { - sprintf( - '"array[test]": - "%s" - ', - self$`array[test]` - ) - }, - if (!is.null(self$`empty_string`)) { - sprintf( - '"empty_string": - "%s" - ', - self$`empty_string` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/store_api.R b/samples/client/petstore/R-httr2-wrapper/R/store_api.R index e49457700c0..bbf86c4f21c 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/store_api.R +++ b/samples/client/petstore/R-httr2-wrapper/R/store_api.R @@ -546,7 +546,7 @@ StoreApi <- R6::R6Class( if (!is.null(`order`)) { local_var_body <- `order`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/store/order" diff --git a/samples/client/petstore/R-httr2-wrapper/R/tag.R b/samples/client/petstore/R-httr2-wrapper/R/tag.R index c9ec58ae6b8..b4c893dfe77 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/tag.R +++ b/samples/client/petstore/R-httr2-wrapper/R/tag.R @@ -50,10 +50,35 @@ Tag <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Tag in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Tag as a base R list. + #' @examples + #' # convert array of Tag (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Tag to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { TagObject <- list() if (!is.null(self$`id`)) { TagObject[["id"]] <- @@ -67,7 +92,7 @@ Tag <- R6::R6Class( TagObject[[key]] <- self$additional_properties[[key]] } - TagObject + return(TagObject) }, #' @description @@ -95,34 +120,16 @@ Tag <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Tag in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/update_pet_request.R b/samples/client/petstore/R-httr2-wrapper/R/update_pet_request.R index 47369030cfa..3559d3c4d83 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/update_pet_request.R +++ b/samples/client/petstore/R-httr2-wrapper/R/update_pet_request.R @@ -45,14 +45,39 @@ UpdatePetRequest <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return UpdatePetRequest in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return UpdatePetRequest as a base R list. + #' @examples + #' # convert array of UpdatePetRequest (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert UpdatePetRequest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { UpdatePetRequestObject <- list() if (!is.null(self$`jsonData`)) { UpdatePetRequestObject[["jsonData"]] <- - self$`jsonData`$toJSON() + self$`jsonData`$toSimpleType() } if (!is.null(self$`binaryDataN2Information`)) { UpdatePetRequestObject[["binaryDataN2Information"]] <- @@ -62,7 +87,7 @@ UpdatePetRequest <- R6::R6Class( UpdatePetRequestObject[[key]] <- self$additional_properties[[key]] } - UpdatePetRequestObject + return(UpdatePetRequestObject) }, #' @description @@ -92,34 +117,16 @@ UpdatePetRequest <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return UpdatePetRequest in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`jsonData`)) { - sprintf( - '"jsonData": - %s - ', - jsonlite::toJSON(self$`jsonData`$toJSON(), auto_unbox = TRUE, digits = NA) - ) - }, - if (!is.null(self$`binaryDataN2Information`)) { - sprintf( - '"binaryDataN2Information": - "%s" - ', - self$`binaryDataN2Information` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/user.R b/samples/client/petstore/R-httr2-wrapper/R/user.R index df4396abb2c..361d0d454f2 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/user.R +++ b/samples/client/petstore/R-httr2-wrapper/R/user.R @@ -104,10 +104,35 @@ User <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return User in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return User as a base R list. + #' @examples + #' # convert array of User (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert User to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { UserObject <- list() if (!is.null(self$`id`)) { UserObject[["id"]] <- @@ -145,7 +170,7 @@ User <- R6::R6Class( UserObject[[key]] <- self$additional_properties[[key]] } - UserObject + return(UserObject) }, #' @description @@ -191,82 +216,16 @@ User <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return User in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`username`)) { - sprintf( - '"username": - "%s" - ', - self$`username` - ) - }, - if (!is.null(self$`firstName`)) { - sprintf( - '"firstName": - "%s" - ', - self$`firstName` - ) - }, - if (!is.null(self$`lastName`)) { - sprintf( - '"lastName": - "%s" - ', - self$`lastName` - ) - }, - if (!is.null(self$`email`)) { - sprintf( - '"email": - "%s" - ', - self$`email` - ) - }, - if (!is.null(self$`password`)) { - sprintf( - '"password": - "%s" - ', - self$`password` - ) - }, - if (!is.null(self$`phone`)) { - sprintf( - '"phone": - "%s" - ', - self$`phone` - ) - }, - if (!is.null(self$`userStatus`)) { - sprintf( - '"userStatus": - %d - ', - self$`userStatus` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/user_api.R b/samples/client/petstore/R-httr2-wrapper/R/user_api.R index 4c938c7ee3a..a99c036736f 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/user_api.R +++ b/samples/client/petstore/R-httr2-wrapper/R/user_api.R @@ -318,7 +318,7 @@ UserApi <- R6::R6Class( if (!is.null(`user`)) { local_var_body <- `user`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user" @@ -428,7 +428,7 @@ UserApi <- R6::R6Class( })), collapse = ",") local_var_body <- paste0("[", body.items, "]") } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user/createWithArray" @@ -538,7 +538,7 @@ UserApi <- R6::R6Class( })), collapse = ",") local_var_body <- paste0("[", body.items, "]") } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user/createWithList" @@ -1099,7 +1099,7 @@ UserApi <- R6::R6Class( if (!is.null(`user`)) { local_var_body <- `user`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user/{username}" diff --git a/samples/client/petstore/R-httr2-wrapper/R/whale.R b/samples/client/petstore/R-httr2-wrapper/R/whale.R index e39211045a7..ea54d3bdf71 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/whale.R +++ b/samples/client/petstore/R-httr2-wrapper/R/whale.R @@ -59,10 +59,35 @@ Whale <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Whale in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Whale as a base R list. + #' @examples + #' # convert array of Whale (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Whale to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { WhaleObject <- list() if (!is.null(self$`hasBaleen`)) { WhaleObject[["hasBaleen"]] <- @@ -80,7 +105,7 @@ Whale <- R6::R6Class( WhaleObject[[key]] <- self$additional_properties[[key]] } - WhaleObject + return(WhaleObject) }, #' @description @@ -111,42 +136,16 @@ Whale <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Whale in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`hasBaleen`)) { - sprintf( - '"hasBaleen": - %s - ', - tolower(self$`hasBaleen`) - ) - }, - if (!is.null(self$`hasTeeth`)) { - sprintf( - '"hasTeeth": - %s - ', - tolower(self$`hasTeeth`) - ) - }, - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/zebra.R b/samples/client/petstore/R-httr2-wrapper/R/zebra.R index fb6d90d4d98..6b85dbff409 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/zebra.R +++ b/samples/client/petstore/R-httr2-wrapper/R/zebra.R @@ -53,10 +53,35 @@ Zebra <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Zebra in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Zebra as a base R list. + #' @examples + #' # convert array of Zebra (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Zebra to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { ZebraObject <- list() if (!is.null(self$`type`)) { ZebraObject[["type"]] <- @@ -70,7 +95,7 @@ Zebra <- R6::R6Class( ZebraObject[[key]] <- self$additional_properties[[key]] } - ZebraObject + return(ZebraObject) }, #' @description @@ -101,34 +126,16 @@ Zebra <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Zebra in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`type`)) { - sprintf( - '"type": - "%s" - ', - self$`type` - ) - }, - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/tests/testthat/test_petstore.R b/samples/client/petstore/R-httr2-wrapper/tests/testthat/test_petstore.R index 917d3fb00ec..f5c8c4edabf 100644 --- a/samples/client/petstore/R-httr2-wrapper/tests/testthat/test_petstore.R +++ b/samples/client/petstore/R-httr2-wrapper/tests/testthat/test_petstore.R @@ -70,7 +70,7 @@ test_that("Test toJSON toJSONString fromJSON fromJSONString print", { # tests for other pet objects pet0 <- Pet$new() - jsonpet <- pet0$toJSON() + jsonpet <- pet0$toSimpleType() pet2 <- pet0$fromJSON( jsonlite::toJSON(jsonpet, auto_unbox = TRUE) ) @@ -96,7 +96,7 @@ test_that("Test toJSON toJSONString fromJSON fromJSONString print", { ), status = "available" ) - jsonpet <- pet1$toJSON() + jsonpet <- pet1$toSimpleType() pet2 <- pet1$fromJSON( jsonlite::toJSON(jsonpet, auto_unbox = TRUE) ) @@ -118,7 +118,7 @@ test_that("Test toJSON toJSONString fromJSON fromJSONString print", { test_that("Test Category", { c1 <- Category$new(id = 450, name = "test_cat") c2 <- Category$new() - c2$fromJSON(jsonlite::toJSON(c1$toJSON(), auto_unbox = TRUE)) + c2$fromJSON(jsonlite::toJSON(c1$toSimpleType(), auto_unbox = TRUE)) expect_equal(c1, c2) c2$fromJSONString(c1$toJSONString()) expect_equal(c1, c2) diff --git a/samples/client/petstore/R-httr2/R/allof_tag_api_response.R b/samples/client/petstore/R-httr2/R/allof_tag_api_response.R index ff239b9cda9..37fa07aaa47 100644 --- a/samples/client/petstore/R-httr2/R/allof_tag_api_response.R +++ b/samples/client/petstore/R-httr2/R/allof_tag_api_response.R @@ -67,10 +67,35 @@ AllofTagApiResponse <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return AllofTagApiResponse in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return AllofTagApiResponse as a base R list. + #' @examples + #' # convert array of AllofTagApiResponse (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert AllofTagApiResponse to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { AllofTagApiResponseObject <- list() if (!is.null(self$`id`)) { AllofTagApiResponseObject[["id"]] <- @@ -92,7 +117,7 @@ AllofTagApiResponse <- R6::R6Class( AllofTagApiResponseObject[["message"]] <- self$`message` } - AllofTagApiResponseObject + return(AllofTagApiResponseObject) }, #' @description @@ -122,53 +147,13 @@ AllofTagApiResponse <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return AllofTagApiResponse in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - }, - if (!is.null(self$`code`)) { - sprintf( - '"code": - %d - ', - self$`code` - ) - }, - if (!is.null(self$`type`)) { - sprintf( - '"type": - "%s" - ', - self$`type` - ) - }, - if (!is.null(self$`message`)) { - sprintf( - '"message": - "%s" - ', - self$`message` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/animal.R b/samples/client/petstore/R-httr2/R/animal.R index 4f1f8ab507c..8b7e9dba4ff 100644 --- a/samples/client/petstore/R-httr2/R/animal.R +++ b/samples/client/petstore/R-httr2/R/animal.R @@ -42,10 +42,35 @@ Animal <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Animal in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Animal as a base R list. + #' @examples + #' # convert array of Animal (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Animal to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { AnimalObject <- list() if (!is.null(self$`className`)) { AnimalObject[["className"]] <- @@ -55,7 +80,7 @@ Animal <- R6::R6Class( AnimalObject[["color"]] <- self$`color` } - AnimalObject + return(AnimalObject) }, #' @description @@ -76,29 +101,13 @@ Animal <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Animal in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/any_of_pig.R b/samples/client/petstore/R-httr2/R/any_of_pig.R index ba3c8ea856d..7480eec7696 100644 --- a/samples/client/petstore/R-httr2/R/any_of_pig.R +++ b/samples/client/petstore/R-httr2/R/any_of_pig.R @@ -91,27 +91,32 @@ AnyOfPig <- R6::R6Class( }, #' @description - #' Serialize AnyOfPig to JSON string. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. + toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert AnyOfPig to a base R type #' - #' @return JSON string representation of the AnyOfPig. - toJSONString = function() { + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify((self$actual_instance$toJSONString()))) + return(self$actual_instance$toSimpleType()) } else { NULL } }, #' @description - #' Serialize AnyOfPig to JSON. + #' Serialize AnyOfPig to JSON string. #' - #' @return JSON representation of the AnyOfPig. - toJSON = function() { - if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() - } else { - NULL - } + #' @param ... Parameters passed to `jsonlite::toJSON` + #' @return JSON string representation of the AnyOfPig. + toJSONString = function(...) { + json <- jsonlite::toJSON(self$toSimpleType(), auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/any_of_primitive_type_test.R b/samples/client/petstore/R-httr2/R/any_of_primitive_type_test.R index 99aa52c7342..f76defe9f4a 100644 --- a/samples/client/petstore/R-httr2/R/any_of_primitive_type_test.R +++ b/samples/client/petstore/R-httr2/R/any_of_primitive_type_test.R @@ -111,25 +111,35 @@ AnyOfPrimitiveTypeTest <- R6::R6Class( #' @description #' Serialize AnyOfPrimitiveTypeTest to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the AnyOfPrimitiveTypeTest. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize AnyOfPrimitiveTypeTest to JSON. - #' - #' @return JSON representation of the AnyOfPrimitiveTypeTest. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert AnyOfPrimitiveTypeTest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R-httr2/R/basque_pig.R b/samples/client/petstore/R-httr2/R/basque_pig.R index 6833f264bc7..77af09db6a0 100644 --- a/samples/client/petstore/R-httr2/R/basque_pig.R +++ b/samples/client/petstore/R-httr2/R/basque_pig.R @@ -40,10 +40,35 @@ BasquePig <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return BasquePig in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return BasquePig as a base R list. + #' @examples + #' # convert array of BasquePig (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert BasquePig to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { BasquePigObject <- list() if (!is.null(self$`className`)) { BasquePigObject[["className"]] <- @@ -53,7 +78,7 @@ BasquePig <- R6::R6Class( BasquePigObject[["color"]] <- self$`color` } - BasquePigObject + return(BasquePigObject) }, #' @description @@ -74,29 +99,13 @@ BasquePig <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return BasquePig in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/cat.R b/samples/client/petstore/R-httr2/R/cat.R index d50bf428d8e..54784f94e2b 100644 --- a/samples/client/petstore/R-httr2/R/cat.R +++ b/samples/client/petstore/R-httr2/R/cat.R @@ -50,10 +50,35 @@ Cat <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Cat in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Cat as a base R list. + #' @examples + #' # convert array of Cat (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Cat to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { CatObject <- list() if (!is.null(self$`className`)) { CatObject[["className"]] <- @@ -67,7 +92,7 @@ Cat <- R6::R6Class( CatObject[["declawed"]] <- self$`declawed` } - CatObject + return(CatObject) }, #' @description @@ -91,37 +116,13 @@ Cat <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Cat in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - }, - if (!is.null(self$`declawed`)) { - sprintf( - '"declawed": - %s - ', - tolower(self$`declawed`) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/category.R b/samples/client/petstore/R-httr2/R/category.R index 752d9b8024b..9448df38190 100644 --- a/samples/client/petstore/R-httr2/R/category.R +++ b/samples/client/petstore/R-httr2/R/category.R @@ -40,10 +40,35 @@ Category <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Category in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Category as a base R list. + #' @examples + #' # convert array of Category (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Category to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { CategoryObject <- list() if (!is.null(self$`id`)) { CategoryObject[["id"]] <- @@ -53,7 +78,7 @@ Category <- R6::R6Class( CategoryObject[["name"]] <- self$`name` } - CategoryObject + return(CategoryObject) }, #' @description @@ -74,29 +99,13 @@ Category <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Category in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/danish_pig.R b/samples/client/petstore/R-httr2/R/danish_pig.R index d7e35b52e5e..e5eeb444614 100644 --- a/samples/client/petstore/R-httr2/R/danish_pig.R +++ b/samples/client/petstore/R-httr2/R/danish_pig.R @@ -40,10 +40,35 @@ DanishPig <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return DanishPig in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return DanishPig as a base R list. + #' @examples + #' # convert array of DanishPig (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert DanishPig to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DanishPigObject <- list() if (!is.null(self$`className`)) { DanishPigObject[["className"]] <- @@ -53,7 +78,7 @@ DanishPig <- R6::R6Class( DanishPigObject[["size"]] <- self$`size` } - DanishPigObject + return(DanishPigObject) }, #' @description @@ -74,29 +99,13 @@ DanishPig <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return DanishPig in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`size`)) { - sprintf( - '"size": - %d - ', - self$`size` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/date.R b/samples/client/petstore/R-httr2/R/date.R index a822606b6b7..81dc68d4fee 100644 --- a/samples/client/petstore/R-httr2/R/date.R +++ b/samples/client/petstore/R-httr2/R/date.R @@ -53,10 +53,35 @@ Date <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Date in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Date as a base R list. + #' @examples + #' # convert array of Date (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Date to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DateObject <- list() if (!is.null(self$`className`)) { DateObject[["className"]] <- @@ -70,7 +95,7 @@ Date <- R6::R6Class( DateObject[["url_property"]] <- self$`url_property` } - DateObject + return(DateObject) }, #' @description @@ -98,37 +123,13 @@ Date <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Date in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`percent`)) { - sprintf( - '"percent_description": - "%s" - ', - self$`percent` - ) - }, - if (!is.null(self$`url_property`)) { - sprintf( - '"url_property": - "%s" - ', - self$`url_property` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/dog.R b/samples/client/petstore/R-httr2/R/dog.R index 0851d7461d9..1928ffc3985 100644 --- a/samples/client/petstore/R-httr2/R/dog.R +++ b/samples/client/petstore/R-httr2/R/dog.R @@ -50,10 +50,35 @@ Dog <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Dog in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Dog as a base R list. + #' @examples + #' # convert array of Dog (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Dog to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DogObject <- list() if (!is.null(self$`className`)) { DogObject[["className"]] <- @@ -67,7 +92,7 @@ Dog <- R6::R6Class( DogObject[["breed"]] <- self$`breed` } - DogObject + return(DogObject) }, #' @description @@ -91,37 +116,13 @@ Dog <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Dog in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - }, - if (!is.null(self$`breed`)) { - sprintf( - '"breed": - "%s" - ', - self$`breed` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/fake_api.R b/samples/client/petstore/R-httr2/R/fake_api.R index 175540cf5ee..2038aabaf7e 100644 --- a/samples/client/petstore/R-httr2/R/fake_api.R +++ b/samples/client/petstore/R-httr2/R/fake_api.R @@ -225,7 +225,7 @@ FakeApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/fake/test_optional_body_parameter" diff --git a/samples/client/petstore/R-httr2/R/format_test.R b/samples/client/petstore/R-httr2/R/format_test.R index 11749730498..1e8a62b2fd9 100644 --- a/samples/client/petstore/R-httr2/R/format_test.R +++ b/samples/client/petstore/R-httr2/R/format_test.R @@ -148,10 +148,35 @@ FormatTest <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return FormatTest in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return FormatTest as a base R list. + #' @examples + #' # convert array of FormatTest (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert FormatTest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { FormatTestObject <- list() if (!is.null(self$`integer`)) { FormatTestObject[["integer"]] <- @@ -213,7 +238,7 @@ FormatTest <- R6::R6Class( FormatTestObject[["pattern_with_digits_and_delimiter"]] <- self$`pattern_with_digits_and_delimiter` } - FormatTestObject + return(FormatTestObject) }, #' @description @@ -273,133 +298,13 @@ FormatTest <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return FormatTest in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`integer`)) { - sprintf( - '"integer": - %d - ', - self$`integer` - ) - }, - if (!is.null(self$`int32`)) { - sprintf( - '"int32": - %d - ', - self$`int32` - ) - }, - if (!is.null(self$`int64`)) { - sprintf( - '"int64": - %d - ', - self$`int64` - ) - }, - if (!is.null(self$`number`)) { - sprintf( - '"number": - %d - ', - self$`number` - ) - }, - if (!is.null(self$`float`)) { - sprintf( - '"float": - %d - ', - self$`float` - ) - }, - if (!is.null(self$`double`)) { - sprintf( - '"double": - %d - ', - self$`double` - ) - }, - if (!is.null(self$`string`)) { - sprintf( - '"string": - "%s" - ', - self$`string` - ) - }, - if (!is.null(self$`byte`)) { - sprintf( - '"byte": - "%s" - ', - self$`byte` - ) - }, - if (!is.null(self$`binary`)) { - sprintf( - '"binary": - "%s" - ', - self$`binary` - ) - }, - if (!is.null(self$`date`)) { - sprintf( - '"date": - "%s" - ', - self$`date` - ) - }, - if (!is.null(self$`dateTime`)) { - sprintf( - '"dateTime": - "%s" - ', - self$`dateTime` - ) - }, - if (!is.null(self$`uuid`)) { - sprintf( - '"uuid": - "%s" - ', - self$`uuid` - ) - }, - if (!is.null(self$`password`)) { - sprintf( - '"password": - "%s" - ', - self$`password` - ) - }, - if (!is.null(self$`pattern_with_digits`)) { - sprintf( - '"pattern_with_digits": - "%s" - ', - self$`pattern_with_digits` - ) - }, - if (!is.null(self$`pattern_with_digits_and_delimiter`)) { - sprintf( - '"pattern_with_digits_and_delimiter": - "%s" - ', - self$`pattern_with_digits_and_delimiter` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/just_model.R b/samples/client/petstore/R-httr2/R/just_model.R index 780533eb3db..89d14ef99c3 100644 --- a/samples/client/petstore/R-httr2/R/just_model.R +++ b/samples/client/petstore/R-httr2/R/just_model.R @@ -31,16 +31,41 @@ JustModel <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return JustModel in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return JustModel as a base R list. + #' @examples + #' # convert array of JustModel (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert JustModel to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { JustModelObject <- list() if (!is.null(self$`property`)) { JustModelObject[["property"]] <- self$`property` } - JustModelObject + return(JustModelObject) }, #' @description @@ -58,21 +83,13 @@ JustModel <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JustModel in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`property`)) { - sprintf( - '"property": - "%s" - ', - self$`property` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/mammal.R b/samples/client/petstore/R-httr2/R/mammal.R index bbd57ed00ac..3d93ab765e3 100644 --- a/samples/client/petstore/R-httr2/R/mammal.R +++ b/samples/client/petstore/R-httr2/R/mammal.R @@ -109,25 +109,35 @@ Mammal <- R6::R6Class( #' @description #' Serialize Mammal to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the Mammal. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize Mammal to JSON. - #' - #' @return JSON representation of the Mammal. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert Mammal to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R-httr2/R/model_api_response.R b/samples/client/petstore/R-httr2/R/model_api_response.R index 98814bedafb..d65c1860ce2 100644 --- a/samples/client/petstore/R-httr2/R/model_api_response.R +++ b/samples/client/petstore/R-httr2/R/model_api_response.R @@ -49,10 +49,35 @@ ModelApiResponse <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return ModelApiResponse in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return ModelApiResponse as a base R list. + #' @examples + #' # convert array of ModelApiResponse (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert ModelApiResponse to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { ModelApiResponseObject <- list() if (!is.null(self$`code`)) { ModelApiResponseObject[["code"]] <- @@ -66,7 +91,7 @@ ModelApiResponse <- R6::R6Class( ModelApiResponseObject[["message"]] <- self$`message` } - ModelApiResponseObject + return(ModelApiResponseObject) }, #' @description @@ -90,37 +115,13 @@ ModelApiResponse <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return ModelApiResponse in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`code`)) { - sprintf( - '"code": - %d - ', - self$`code` - ) - }, - if (!is.null(self$`type`)) { - sprintf( - '"type": - "%s" - ', - self$`type` - ) - }, - if (!is.null(self$`message`)) { - sprintf( - '"message": - "%s" - ', - self$`message` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/nested_one_of.R b/samples/client/petstore/R-httr2/R/nested_one_of.R index c1abefcacd8..d0ef1f9b67a 100644 --- a/samples/client/petstore/R-httr2/R/nested_one_of.R +++ b/samples/client/petstore/R-httr2/R/nested_one_of.R @@ -38,10 +38,35 @@ NestedOneOf <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return NestedOneOf in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return NestedOneOf as a base R list. + #' @examples + #' # convert array of NestedOneOf (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert NestedOneOf to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { NestedOneOfObject <- list() if (!is.null(self$`size`)) { NestedOneOfObject[["size"]] <- @@ -49,9 +74,9 @@ NestedOneOf <- R6::R6Class( } if (!is.null(self$`nested_pig`)) { NestedOneOfObject[["nested_pig"]] <- - self$`nested_pig`$toJSON() + self$`nested_pig`$toSimpleType() } - NestedOneOfObject + return(NestedOneOfObject) }, #' @description @@ -74,29 +99,13 @@ NestedOneOf <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return NestedOneOf in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`size`)) { - sprintf( - '"size": - %d - ', - self$`size` - ) - }, - if (!is.null(self$`nested_pig`)) { - sprintf( - '"nested_pig": - %s - ', - jsonlite::toJSON(self$`nested_pig`$toJSON(), auto_unbox = TRUE, digits = NA) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/one_of_primitive_type_test.R b/samples/client/petstore/R-httr2/R/one_of_primitive_type_test.R index 8a9280a9b21..e5b56698562 100644 --- a/samples/client/petstore/R-httr2/R/one_of_primitive_type_test.R +++ b/samples/client/petstore/R-httr2/R/one_of_primitive_type_test.R @@ -111,25 +111,35 @@ OneOfPrimitiveTypeTest <- R6::R6Class( #' @description #' Serialize OneOfPrimitiveTypeTest to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the OneOfPrimitiveTypeTest. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize OneOfPrimitiveTypeTest to JSON. - #' - #' @return JSON representation of the OneOfPrimitiveTypeTest. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert OneOfPrimitiveTypeTest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R-httr2/R/order.R b/samples/client/petstore/R-httr2/R/order.R index 4155b311f31..cf6bcb48bc8 100644 --- a/samples/client/petstore/R-httr2/R/order.R +++ b/samples/client/petstore/R-httr2/R/order.R @@ -79,10 +79,35 @@ Order <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Order in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Order as a base R list. + #' @examples + #' # convert array of Order (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Order to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { OrderObject <- list() if (!is.null(self$`id`)) { OrderObject[["id"]] <- @@ -108,7 +133,7 @@ Order <- R6::R6Class( OrderObject[["complete"]] <- self$`complete` } - OrderObject + return(OrderObject) }, #' @description @@ -144,61 +169,13 @@ Order <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Order in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`petId`)) { - sprintf( - '"petId": - %d - ', - self$`petId` - ) - }, - if (!is.null(self$`quantity`)) { - sprintf( - '"quantity": - %d - ', - self$`quantity` - ) - }, - if (!is.null(self$`shipDate`)) { - sprintf( - '"shipDate": - "%s" - ', - self$`shipDate` - ) - }, - if (!is.null(self$`status`)) { - sprintf( - '"status": - "%s" - ', - self$`status` - ) - }, - if (!is.null(self$`complete`)) { - sprintf( - '"complete": - %s - ', - tolower(self$`complete`) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/pet.R b/samples/client/petstore/R-httr2/R/pet.R index e3f3274dbc8..c3d0bc32fd6 100644 --- a/samples/client/petstore/R-httr2/R/pet.R +++ b/samples/client/petstore/R-httr2/R/pet.R @@ -75,10 +75,35 @@ Pet <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Pet in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Pet as a base R list. + #' @examples + #' # convert array of Pet (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Pet to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { PetObject <- list() if (!is.null(self$`id`)) { PetObject[["id"]] <- @@ -86,7 +111,7 @@ Pet <- R6::R6Class( } if (!is.null(self$`category`)) { PetObject[["category"]] <- - self$`category`$toJSON() + self$`category`$toSimpleType() } if (!is.null(self$`name`)) { PetObject[["name"]] <- @@ -98,13 +123,13 @@ Pet <- R6::R6Class( } if (!is.null(self$`tags`)) { PetObject[["tags"]] <- - lapply(self$`tags`, function(x) x$toJSON()) + lapply(self$`tags`, function(x) x$toSimpleType()) } if (!is.null(self$`status`)) { PetObject[["status"]] <- self$`status` } - PetObject + return(PetObject) }, #' @description @@ -142,61 +167,13 @@ Pet <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Pet in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`category`)) { - sprintf( - '"category": - %s - ', - jsonlite::toJSON(self$`category`$toJSON(), auto_unbox = TRUE, digits = NA) - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - }, - if (!is.null(self$`photoUrls`)) { - sprintf( - '"photoUrls": - [%s] - ', - paste(unlist(lapply(self$`photoUrls`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`tags`)) { - sprintf( - '"tags": - [%s] -', - paste(sapply(self$`tags`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox = TRUE, digits = NA)), collapse = ",") - ) - }, - if (!is.null(self$`status`)) { - sprintf( - '"status": - "%s" - ', - self$`status` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/pet_api.R b/samples/client/petstore/R-httr2/R/pet_api.R index f832c2ea5cb..12e65404d91 100644 --- a/samples/client/petstore/R-httr2/R/pet_api.R +++ b/samples/client/petstore/R-httr2/R/pet_api.R @@ -435,7 +435,7 @@ PetApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/pet" @@ -1288,7 +1288,7 @@ PetApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/pet" diff --git a/samples/client/petstore/R-httr2/R/pet_map.R b/samples/client/petstore/R-httr2/R/pet_map.R index 6a8b62a0a69..e0e63305d0f 100644 --- a/samples/client/petstore/R-httr2/R/pet_map.R +++ b/samples/client/petstore/R-httr2/R/pet_map.R @@ -30,16 +30,41 @@ PetMap <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return PetMap in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return PetMap as a base R list. + #' @examples + #' # convert array of PetMap (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert PetMap to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { PetMapObject <- list() if (!is.null(self$`pet`)) { PetMapObject[["pet"]] <- self$`pet` } - PetMapObject + return(PetMapObject) }, #' @description @@ -57,21 +82,13 @@ PetMap <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return PetMap in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`pet`)) { - sprintf( - '"pet": - %s - ', - jsonlite::toJSON(lapply(self$`pet`, function(x){ x }), auto_unbox = TRUE, digits = NA) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/pig.R b/samples/client/petstore/R-httr2/R/pig.R index 596a9307d4d..94067ec4d72 100644 --- a/samples/client/petstore/R-httr2/R/pig.R +++ b/samples/client/petstore/R-httr2/R/pig.R @@ -109,25 +109,35 @@ Pig <- R6::R6Class( #' @description #' Serialize Pig to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the Pig. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize Pig to JSON. - #' - #' @return JSON representation of the Pig. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert Pig to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R-httr2/R/special.R b/samples/client/petstore/R-httr2/R/special.R index 4e4250f78d3..2e4c8ccdc0c 100644 --- a/samples/client/petstore/R-httr2/R/special.R +++ b/samples/client/petstore/R-httr2/R/special.R @@ -87,10 +87,35 @@ Special <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Special in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Special as a base R list. + #' @examples + #' # convert array of Special (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Special to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { SpecialObject <- list() if (!is.null(self$`set_test`)) { SpecialObject[["set_test"]] <- @@ -120,7 +145,7 @@ Special <- R6::R6Class( SpecialObject[["empty_string"]] <- self$`empty_string` } - SpecialObject + return(SpecialObject) }, #' @description @@ -159,69 +184,13 @@ Special <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Special in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`set_test`)) { - sprintf( - '"set_test": - [%s] - ', - paste(unlist(lapply(self$`set_test`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`item_self`)) { - sprintf( - '"self": - %d - ', - self$`item_self` - ) - }, - if (!is.null(self$`item_private`)) { - sprintf( - '"private": - "%s" - ', - self$`item_private` - ) - }, - if (!is.null(self$`item_super`)) { - sprintf( - '"super": - "%s" - ', - self$`item_super` - ) - }, - if (!is.null(self$`123_number`)) { - sprintf( - '"123_number": - "%s" - ', - self$`123_number` - ) - }, - if (!is.null(self$`array[test]`)) { - sprintf( - '"array[test]": - "%s" - ', - self$`array[test]` - ) - }, - if (!is.null(self$`empty_string`)) { - sprintf( - '"empty_string": - "%s" - ', - self$`empty_string` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/store_api.R b/samples/client/petstore/R-httr2/R/store_api.R index f445fabf3c2..fc4ff66dcab 100644 --- a/samples/client/petstore/R-httr2/R/store_api.R +++ b/samples/client/petstore/R-httr2/R/store_api.R @@ -546,7 +546,7 @@ StoreApi <- R6::R6Class( if (!is.null(`order`)) { local_var_body <- `order`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/store/order" diff --git a/samples/client/petstore/R-httr2/R/tag.R b/samples/client/petstore/R-httr2/R/tag.R index 574b5c0395a..96383b87f07 100644 --- a/samples/client/petstore/R-httr2/R/tag.R +++ b/samples/client/petstore/R-httr2/R/tag.R @@ -40,10 +40,35 @@ Tag <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Tag in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Tag as a base R list. + #' @examples + #' # convert array of Tag (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Tag to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { TagObject <- list() if (!is.null(self$`id`)) { TagObject[["id"]] <- @@ -53,7 +78,7 @@ Tag <- R6::R6Class( TagObject[["name"]] <- self$`name` } - TagObject + return(TagObject) }, #' @description @@ -74,29 +99,13 @@ Tag <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Tag in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/update_pet_request.R b/samples/client/petstore/R-httr2/R/update_pet_request.R index a5070554b03..e42c9a11454 100644 --- a/samples/client/petstore/R-httr2/R/update_pet_request.R +++ b/samples/client/petstore/R-httr2/R/update_pet_request.R @@ -35,20 +35,45 @@ UpdatePetRequest <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return UpdatePetRequest in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return UpdatePetRequest as a base R list. + #' @examples + #' # convert array of UpdatePetRequest (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert UpdatePetRequest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { UpdatePetRequestObject <- list() if (!is.null(self$`jsonData`)) { UpdatePetRequestObject[["jsonData"]] <- - self$`jsonData`$toJSON() + self$`jsonData`$toSimpleType() } if (!is.null(self$`binaryDataN2Information`)) { UpdatePetRequestObject[["binaryDataN2Information"]] <- self$`binaryDataN2Information` } - UpdatePetRequestObject + return(UpdatePetRequestObject) }, #' @description @@ -71,29 +96,13 @@ UpdatePetRequest <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return UpdatePetRequest in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`jsonData`)) { - sprintf( - '"jsonData": - %s - ', - jsonlite::toJSON(self$`jsonData`$toJSON(), auto_unbox = TRUE, digits = NA) - ) - }, - if (!is.null(self$`binaryDataN2Information`)) { - sprintf( - '"binaryDataN2Information": - "%s" - ', - self$`binaryDataN2Information` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/user.R b/samples/client/petstore/R-httr2/R/user.R index e7b911abc31..76c4970a45d 100644 --- a/samples/client/petstore/R-httr2/R/user.R +++ b/samples/client/petstore/R-httr2/R/user.R @@ -94,10 +94,35 @@ User <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return User in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return User as a base R list. + #' @examples + #' # convert array of User (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert User to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { UserObject <- list() if (!is.null(self$`id`)) { UserObject[["id"]] <- @@ -131,7 +156,7 @@ User <- R6::R6Class( UserObject[["userStatus"]] <- self$`userStatus` } - UserObject + return(UserObject) }, #' @description @@ -170,77 +195,13 @@ User <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return User in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`username`)) { - sprintf( - '"username": - "%s" - ', - self$`username` - ) - }, - if (!is.null(self$`firstName`)) { - sprintf( - '"firstName": - "%s" - ', - self$`firstName` - ) - }, - if (!is.null(self$`lastName`)) { - sprintf( - '"lastName": - "%s" - ', - self$`lastName` - ) - }, - if (!is.null(self$`email`)) { - sprintf( - '"email": - "%s" - ', - self$`email` - ) - }, - if (!is.null(self$`password`)) { - sprintf( - '"password": - "%s" - ', - self$`password` - ) - }, - if (!is.null(self$`phone`)) { - sprintf( - '"phone": - "%s" - ', - self$`phone` - ) - }, - if (!is.null(self$`userStatus`)) { - sprintf( - '"userStatus": - %d - ', - self$`userStatus` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/user_api.R b/samples/client/petstore/R-httr2/R/user_api.R index 9487ca7835b..a1496d50472 100644 --- a/samples/client/petstore/R-httr2/R/user_api.R +++ b/samples/client/petstore/R-httr2/R/user_api.R @@ -318,7 +318,7 @@ UserApi <- R6::R6Class( if (!is.null(`user`)) { local_var_body <- `user`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user" @@ -428,7 +428,7 @@ UserApi <- R6::R6Class( })), collapse = ",") local_var_body <- paste0("[", body.items, "]") } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user/createWithArray" @@ -538,7 +538,7 @@ UserApi <- R6::R6Class( })), collapse = ",") local_var_body <- paste0("[", body.items, "]") } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user/createWithList" @@ -1099,7 +1099,7 @@ UserApi <- R6::R6Class( if (!is.null(`user`)) { local_var_body <- `user`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user/{username}" diff --git a/samples/client/petstore/R-httr2/R/whale.R b/samples/client/petstore/R-httr2/R/whale.R index 4656c11680d..fef88a7c637 100644 --- a/samples/client/petstore/R-httr2/R/whale.R +++ b/samples/client/petstore/R-httr2/R/whale.R @@ -49,10 +49,35 @@ Whale <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Whale in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Whale as a base R list. + #' @examples + #' # convert array of Whale (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Whale to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { WhaleObject <- list() if (!is.null(self$`hasBaleen`)) { WhaleObject[["hasBaleen"]] <- @@ -66,7 +91,7 @@ Whale <- R6::R6Class( WhaleObject[["className"]] <- self$`className` } - WhaleObject + return(WhaleObject) }, #' @description @@ -90,37 +115,13 @@ Whale <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Whale in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`hasBaleen`)) { - sprintf( - '"hasBaleen": - %s - ', - tolower(self$`hasBaleen`) - ) - }, - if (!is.null(self$`hasTeeth`)) { - sprintf( - '"hasTeeth": - %s - ', - tolower(self$`hasTeeth`) - ) - }, - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/zebra.R b/samples/client/petstore/R-httr2/R/zebra.R index 95f216c3ce5..c5165a86708 100644 --- a/samples/client/petstore/R-httr2/R/zebra.R +++ b/samples/client/petstore/R-httr2/R/zebra.R @@ -43,10 +43,35 @@ Zebra <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Zebra in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Zebra as a base R list. + #' @examples + #' # convert array of Zebra (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Zebra to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { ZebraObject <- list() if (!is.null(self$`type`)) { ZebraObject[["type"]] <- @@ -56,7 +81,7 @@ Zebra <- R6::R6Class( ZebraObject[["className"]] <- self$`className` } - ZebraObject + return(ZebraObject) }, #' @description @@ -80,29 +105,13 @@ Zebra <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Zebra in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`type`)) { - sprintf( - '"type": - "%s" - ', - self$`type` - ) - }, - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/tests/testthat/test_petstore.R b/samples/client/petstore/R-httr2/tests/testthat/test_petstore.R index b612714b812..ec1816d3c39 100644 --- a/samples/client/petstore/R-httr2/tests/testthat/test_petstore.R +++ b/samples/client/petstore/R-httr2/tests/testthat/test_petstore.R @@ -23,7 +23,7 @@ test_that("Test toJSON toJSONString fromJSON fromJSONString", { # tests for other pet objects pet0 <- Pet$new() - jsonpet <- pet0$toJSON() + jsonpet <- pet0$toSimpleType() pet2 <- pet0$fromJSON( jsonlite::toJSON(jsonpet, auto_unbox = TRUE) ) @@ -49,7 +49,7 @@ test_that("Test toJSON toJSONString fromJSON fromJSONString", { ), status = "available" ) - jsonpet <- pet1$toJSON() + jsonpet <- pet1$toSimpleType() pet2 <- pet1$fromJSON( jsonlite::toJSON(jsonpet, auto_unbox = TRUE) ) @@ -71,7 +71,7 @@ test_that("Test toJSON toJSONString fromJSON fromJSONString", { test_that("Test Category", { c1 <- Category$new(id = 450, name = "test_cat") c2 <- Category$new() - c2$fromJSON(jsonlite::toJSON(c1$toJSON(), auto_unbox = TRUE)) + c2$fromJSON(jsonlite::toJSON(c1$toSimpleType(), auto_unbox = TRUE)) expect_equal(c1, c2) c2$fromJSONString(c1$toJSONString()) expect_equal(c1, c2) diff --git a/samples/client/petstore/R/R/allof_tag_api_response.R b/samples/client/petstore/R/R/allof_tag_api_response.R index 454e378a5c1..018600362d3 100644 --- a/samples/client/petstore/R/R/allof_tag_api_response.R +++ b/samples/client/petstore/R/R/allof_tag_api_response.R @@ -77,10 +77,35 @@ AllofTagApiResponse <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return AllofTagApiResponse in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return AllofTagApiResponse as a base R list. + #' @examples + #' # convert array of AllofTagApiResponse (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert AllofTagApiResponse to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { AllofTagApiResponseObject <- list() if (!is.null(self$`id`)) { AllofTagApiResponseObject[["id"]] <- @@ -106,7 +131,7 @@ AllofTagApiResponse <- R6::R6Class( AllofTagApiResponseObject[[key]] <- self$additional_properties[[key]] } - AllofTagApiResponseObject + return(AllofTagApiResponseObject) }, #' @description @@ -143,58 +168,16 @@ AllofTagApiResponse <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return AllofTagApiResponse in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - }, - if (!is.null(self$`code`)) { - sprintf( - '"code": - %d - ', - self$`code` - ) - }, - if (!is.null(self$`type`)) { - sprintf( - '"type": - "%s" - ', - self$`type` - ) - }, - if (!is.null(self$`message`)) { - sprintf( - '"message": - "%s" - ', - self$`message` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/animal.R b/samples/client/petstore/R/R/animal.R index 471a01afef3..cf2e97f9af3 100644 --- a/samples/client/petstore/R/R/animal.R +++ b/samples/client/petstore/R/R/animal.R @@ -52,10 +52,35 @@ Animal <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Animal in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Animal as a base R list. + #' @examples + #' # convert array of Animal (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Animal to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { AnimalObject <- list() if (!is.null(self$`className`)) { AnimalObject[["className"]] <- @@ -69,7 +94,7 @@ Animal <- R6::R6Class( AnimalObject[[key]] <- self$additional_properties[[key]] } - AnimalObject + return(AnimalObject) }, #' @description @@ -97,34 +122,16 @@ Animal <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Animal in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/any_of_pig.R b/samples/client/petstore/R/R/any_of_pig.R index ba3c8ea856d..7480eec7696 100644 --- a/samples/client/petstore/R/R/any_of_pig.R +++ b/samples/client/petstore/R/R/any_of_pig.R @@ -91,27 +91,32 @@ AnyOfPig <- R6::R6Class( }, #' @description - #' Serialize AnyOfPig to JSON string. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. + toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert AnyOfPig to a base R type #' - #' @return JSON string representation of the AnyOfPig. - toJSONString = function() { + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify((self$actual_instance$toJSONString()))) + return(self$actual_instance$toSimpleType()) } else { NULL } }, #' @description - #' Serialize AnyOfPig to JSON. + #' Serialize AnyOfPig to JSON string. #' - #' @return JSON representation of the AnyOfPig. - toJSON = function() { - if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() - } else { - NULL - } + #' @param ... Parameters passed to `jsonlite::toJSON` + #' @return JSON string representation of the AnyOfPig. + toJSONString = function(...) { + json <- jsonlite::toJSON(self$toSimpleType(), auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/any_of_primitive_type_test.R b/samples/client/petstore/R/R/any_of_primitive_type_test.R index 99aa52c7342..f76defe9f4a 100644 --- a/samples/client/petstore/R/R/any_of_primitive_type_test.R +++ b/samples/client/petstore/R/R/any_of_primitive_type_test.R @@ -111,25 +111,35 @@ AnyOfPrimitiveTypeTest <- R6::R6Class( #' @description #' Serialize AnyOfPrimitiveTypeTest to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the AnyOfPrimitiveTypeTest. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize AnyOfPrimitiveTypeTest to JSON. - #' - #' @return JSON representation of the AnyOfPrimitiveTypeTest. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert AnyOfPrimitiveTypeTest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R/R/basque_pig.R b/samples/client/petstore/R/R/basque_pig.R index cce82cd7d93..ca8601f4c3b 100644 --- a/samples/client/petstore/R/R/basque_pig.R +++ b/samples/client/petstore/R/R/basque_pig.R @@ -50,10 +50,35 @@ BasquePig <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return BasquePig in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return BasquePig as a base R list. + #' @examples + #' # convert array of BasquePig (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert BasquePig to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { BasquePigObject <- list() if (!is.null(self$`className`)) { BasquePigObject[["className"]] <- @@ -67,7 +92,7 @@ BasquePig <- R6::R6Class( BasquePigObject[[key]] <- self$additional_properties[[key]] } - BasquePigObject + return(BasquePigObject) }, #' @description @@ -95,34 +120,16 @@ BasquePig <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return BasquePig in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/cat.R b/samples/client/petstore/R/R/cat.R index b4014681ba4..270b87c2164 100644 --- a/samples/client/petstore/R/R/cat.R +++ b/samples/client/petstore/R/R/cat.R @@ -60,10 +60,35 @@ Cat <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Cat in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Cat as a base R list. + #' @examples + #' # convert array of Cat (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Cat to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { CatObject <- list() if (!is.null(self$`className`)) { CatObject[["className"]] <- @@ -81,7 +106,7 @@ Cat <- R6::R6Class( CatObject[[key]] <- self$additional_properties[[key]] } - CatObject + return(CatObject) }, #' @description @@ -112,42 +137,16 @@ Cat <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Cat in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - }, - if (!is.null(self$`declawed`)) { - sprintf( - '"declawed": - %s - ', - tolower(self$`declawed`) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/category.R b/samples/client/petstore/R/R/category.R index 31106a3bc9e..0dcbd1b8161 100644 --- a/samples/client/petstore/R/R/category.R +++ b/samples/client/petstore/R/R/category.R @@ -50,10 +50,35 @@ Category <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Category in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Category as a base R list. + #' @examples + #' # convert array of Category (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Category to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { CategoryObject <- list() if (!is.null(self$`id`)) { CategoryObject[["id"]] <- @@ -67,7 +92,7 @@ Category <- R6::R6Class( CategoryObject[[key]] <- self$additional_properties[[key]] } - CategoryObject + return(CategoryObject) }, #' @description @@ -95,34 +120,16 @@ Category <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Category in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/danish_pig.R b/samples/client/petstore/R/R/danish_pig.R index 08ca2b9e3ee..02d2208639b 100644 --- a/samples/client/petstore/R/R/danish_pig.R +++ b/samples/client/petstore/R/R/danish_pig.R @@ -50,10 +50,35 @@ DanishPig <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return DanishPig in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return DanishPig as a base R list. + #' @examples + #' # convert array of DanishPig (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert DanishPig to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DanishPigObject <- list() if (!is.null(self$`className`)) { DanishPigObject[["className"]] <- @@ -67,7 +92,7 @@ DanishPig <- R6::R6Class( DanishPigObject[[key]] <- self$additional_properties[[key]] } - DanishPigObject + return(DanishPigObject) }, #' @description @@ -95,34 +120,16 @@ DanishPig <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return DanishPig in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`size`)) { - sprintf( - '"size": - %d - ', - self$`size` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/date.R b/samples/client/petstore/R/R/date.R index d9b6ec0beb1..411249d3fba 100644 --- a/samples/client/petstore/R/R/date.R +++ b/samples/client/petstore/R/R/date.R @@ -63,10 +63,35 @@ Date <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Date in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Date as a base R list. + #' @examples + #' # convert array of Date (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Date to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DateObject <- list() if (!is.null(self$`className`)) { DateObject[["className"]] <- @@ -84,7 +109,7 @@ Date <- R6::R6Class( DateObject[[key]] <- self$additional_properties[[key]] } - DateObject + return(DateObject) }, #' @description @@ -119,42 +144,16 @@ Date <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Date in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`percent_description`)) { - sprintf( - '"percent_description": - "%s" - ', - self$`percent_description` - ) - }, - if (!is.null(self$`url_property`)) { - sprintf( - '"url_property": - "%s" - ', - self$`url_property` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/dog.R b/samples/client/petstore/R/R/dog.R index 34ae2912116..4d6dab71c61 100644 --- a/samples/client/petstore/R/R/dog.R +++ b/samples/client/petstore/R/R/dog.R @@ -60,10 +60,35 @@ Dog <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Dog in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Dog as a base R list. + #' @examples + #' # convert array of Dog (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Dog to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DogObject <- list() if (!is.null(self$`className`)) { DogObject[["className"]] <- @@ -81,7 +106,7 @@ Dog <- R6::R6Class( DogObject[[key]] <- self$additional_properties[[key]] } - DogObject + return(DogObject) }, #' @description @@ -112,42 +137,16 @@ Dog <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Dog in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - }, - if (!is.null(self$`breed`)) { - sprintf( - '"breed": - "%s" - ', - self$`breed` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/dummy_model.R b/samples/client/petstore/R/R/dummy_model.R index 12d3ab52a15..cbea7830b82 100644 --- a/samples/client/petstore/R/R/dummy_model.R +++ b/samples/client/petstore/R/R/dummy_model.R @@ -41,10 +41,35 @@ DummyModel <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return DummyModel in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return DummyModel as a base R list. + #' @examples + #' # convert array of DummyModel (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert DummyModel to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DummyModelObject <- list() if (!is.null(self$`property`)) { DummyModelObject[["property"]] <- @@ -54,7 +79,7 @@ DummyModel <- R6::R6Class( DummyModelObject[[key]] <- self$additional_properties[[key]] } - DummyModelObject + return(DummyModelObject) }, #' @description @@ -79,26 +104,16 @@ DummyModel <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return DummyModel in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`property`)) { - sprintf( - '"property": - "%s" - ', - self$`property` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/fake_api.R b/samples/client/petstore/R/R/fake_api.R index ee88e7eba78..452eab587de 100644 --- a/samples/client/petstore/R/R/fake_api.R +++ b/samples/client/petstore/R/R/fake_api.R @@ -225,7 +225,7 @@ FakeApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/fake/test_optional_body_parameter" diff --git a/samples/client/petstore/R/R/format_test.R b/samples/client/petstore/R/R/format_test.R index f93bf1435c9..7d1bded3c5a 100644 --- a/samples/client/petstore/R/R/format_test.R +++ b/samples/client/petstore/R/R/format_test.R @@ -158,10 +158,35 @@ FormatTest <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return FormatTest in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return FormatTest as a base R list. + #' @examples + #' # convert array of FormatTest (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert FormatTest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { FormatTestObject <- list() if (!is.null(self$`integer`)) { FormatTestObject[["integer"]] <- @@ -227,7 +252,7 @@ FormatTest <- R6::R6Class( FormatTestObject[[key]] <- self$additional_properties[[key]] } - FormatTestObject + return(FormatTestObject) }, #' @description @@ -294,138 +319,16 @@ FormatTest <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return FormatTest in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`integer`)) { - sprintf( - '"integer": - %d - ', - self$`integer` - ) - }, - if (!is.null(self$`int32`)) { - sprintf( - '"int32": - %d - ', - self$`int32` - ) - }, - if (!is.null(self$`int64`)) { - sprintf( - '"int64": - %d - ', - self$`int64` - ) - }, - if (!is.null(self$`number`)) { - sprintf( - '"number": - %d - ', - self$`number` - ) - }, - if (!is.null(self$`float`)) { - sprintf( - '"float": - %d - ', - self$`float` - ) - }, - if (!is.null(self$`double`)) { - sprintf( - '"double": - %d - ', - self$`double` - ) - }, - if (!is.null(self$`string`)) { - sprintf( - '"string": - "%s" - ', - self$`string` - ) - }, - if (!is.null(self$`byte`)) { - sprintf( - '"byte": - "%s" - ', - self$`byte` - ) - }, - if (!is.null(self$`binary`)) { - sprintf( - '"binary": - "%s" - ', - self$`binary` - ) - }, - if (!is.null(self$`date`)) { - sprintf( - '"date": - "%s" - ', - self$`date` - ) - }, - if (!is.null(self$`dateTime`)) { - sprintf( - '"dateTime": - "%s" - ', - self$`dateTime` - ) - }, - if (!is.null(self$`uuid`)) { - sprintf( - '"uuid": - "%s" - ', - self$`uuid` - ) - }, - if (!is.null(self$`password`)) { - sprintf( - '"password": - "%s" - ', - self$`password` - ) - }, - if (!is.null(self$`pattern_with_digits`)) { - sprintf( - '"pattern_with_digits": - "%s" - ', - self$`pattern_with_digits` - ) - }, - if (!is.null(self$`pattern_with_digits_and_delimiter`)) { - sprintf( - '"pattern_with_digits_and_delimiter": - "%s" - ', - self$`pattern_with_digits_and_delimiter` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/mammal.R b/samples/client/petstore/R/R/mammal.R index bbd57ed00ac..3d93ab765e3 100644 --- a/samples/client/petstore/R/R/mammal.R +++ b/samples/client/petstore/R/R/mammal.R @@ -109,25 +109,35 @@ Mammal <- R6::R6Class( #' @description #' Serialize Mammal to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the Mammal. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize Mammal to JSON. - #' - #' @return JSON representation of the Mammal. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert Mammal to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R/R/model_api_response.R b/samples/client/petstore/R/R/model_api_response.R index 9116e438fed..a3a46dfb790 100644 --- a/samples/client/petstore/R/R/model_api_response.R +++ b/samples/client/petstore/R/R/model_api_response.R @@ -59,10 +59,35 @@ ModelApiResponse <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return ModelApiResponse in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return ModelApiResponse as a base R list. + #' @examples + #' # convert array of ModelApiResponse (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert ModelApiResponse to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { ModelApiResponseObject <- list() if (!is.null(self$`code`)) { ModelApiResponseObject[["code"]] <- @@ -80,7 +105,7 @@ ModelApiResponse <- R6::R6Class( ModelApiResponseObject[[key]] <- self$additional_properties[[key]] } - ModelApiResponseObject + return(ModelApiResponseObject) }, #' @description @@ -111,42 +136,16 @@ ModelApiResponse <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return ModelApiResponse in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`code`)) { - sprintf( - '"code": - %d - ', - self$`code` - ) - }, - if (!is.null(self$`type`)) { - sprintf( - '"type": - "%s" - ', - self$`type` - ) - }, - if (!is.null(self$`message`)) { - sprintf( - '"message": - "%s" - ', - self$`message` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/nested_one_of.R b/samples/client/petstore/R/R/nested_one_of.R index e04a31a69ac..31dcc2f10d0 100644 --- a/samples/client/petstore/R/R/nested_one_of.R +++ b/samples/client/petstore/R/R/nested_one_of.R @@ -48,10 +48,35 @@ NestedOneOf <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return NestedOneOf in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return NestedOneOf as a base R list. + #' @examples + #' # convert array of NestedOneOf (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert NestedOneOf to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { NestedOneOfObject <- list() if (!is.null(self$`size`)) { NestedOneOfObject[["size"]] <- @@ -59,13 +84,13 @@ NestedOneOf <- R6::R6Class( } if (!is.null(self$`nested_pig`)) { NestedOneOfObject[["nested_pig"]] <- - self$`nested_pig`$toJSON() + self$`nested_pig`$toSimpleType() } for (key in names(self$additional_properties)) { NestedOneOfObject[[key]] <- self$additional_properties[[key]] } - NestedOneOfObject + return(NestedOneOfObject) }, #' @description @@ -95,34 +120,16 @@ NestedOneOf <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return NestedOneOf in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`size`)) { - sprintf( - '"size": - %d - ', - self$`size` - ) - }, - if (!is.null(self$`nested_pig`)) { - sprintf( - '"nested_pig": - %s - ', - jsonlite::toJSON(self$`nested_pig`$toJSON(), auto_unbox = TRUE, digits = NA) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/one_of_primitive_type_test.R b/samples/client/petstore/R/R/one_of_primitive_type_test.R index 8a9280a9b21..e5b56698562 100644 --- a/samples/client/petstore/R/R/one_of_primitive_type_test.R +++ b/samples/client/petstore/R/R/one_of_primitive_type_test.R @@ -111,25 +111,35 @@ OneOfPrimitiveTypeTest <- R6::R6Class( #' @description #' Serialize OneOfPrimitiveTypeTest to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the OneOfPrimitiveTypeTest. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize OneOfPrimitiveTypeTest to JSON. - #' - #' @return JSON representation of the OneOfPrimitiveTypeTest. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert OneOfPrimitiveTypeTest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R/R/order.R b/samples/client/petstore/R/R/order.R index cd84eed74ee..07378f03666 100644 --- a/samples/client/petstore/R/R/order.R +++ b/samples/client/petstore/R/R/order.R @@ -89,10 +89,35 @@ Order <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Order in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Order as a base R list. + #' @examples + #' # convert array of Order (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Order to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { OrderObject <- list() if (!is.null(self$`id`)) { OrderObject[["id"]] <- @@ -122,7 +147,7 @@ Order <- R6::R6Class( OrderObject[[key]] <- self$additional_properties[[key]] } - OrderObject + return(OrderObject) }, #' @description @@ -165,66 +190,16 @@ Order <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Order in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`petId`)) { - sprintf( - '"petId": - %d - ', - self$`petId` - ) - }, - if (!is.null(self$`quantity`)) { - sprintf( - '"quantity": - %d - ', - self$`quantity` - ) - }, - if (!is.null(self$`shipDate`)) { - sprintf( - '"shipDate": - "%s" - ', - self$`shipDate` - ) - }, - if (!is.null(self$`status`)) { - sprintf( - '"status": - "%s" - ', - self$`status` - ) - }, - if (!is.null(self$`complete`)) { - sprintf( - '"complete": - %s - ', - tolower(self$`complete`) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/pet.R b/samples/client/petstore/R/R/pet.R index 28e1693c419..27db68d8fdb 100644 --- a/samples/client/petstore/R/R/pet.R +++ b/samples/client/petstore/R/R/pet.R @@ -85,10 +85,35 @@ Pet <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Pet in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Pet as a base R list. + #' @examples + #' # convert array of Pet (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Pet to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { PetObject <- list() if (!is.null(self$`id`)) { PetObject[["id"]] <- @@ -96,7 +121,7 @@ Pet <- R6::R6Class( } if (!is.null(self$`category`)) { PetObject[["category"]] <- - self$`category`$toJSON() + self$`category`$toSimpleType() } if (!is.null(self$`name`)) { PetObject[["name"]] <- @@ -108,7 +133,7 @@ Pet <- R6::R6Class( } if (!is.null(self$`tags`)) { PetObject[["tags"]] <- - lapply(self$`tags`, function(x) x$toJSON()) + lapply(self$`tags`, function(x) x$toSimpleType()) } if (!is.null(self$`status`)) { PetObject[["status"]] <- @@ -118,7 +143,7 @@ Pet <- R6::R6Class( PetObject[[key]] <- self$additional_properties[[key]] } - PetObject + return(PetObject) }, #' @description @@ -163,66 +188,16 @@ Pet <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Pet in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`category`)) { - sprintf( - '"category": - %s - ', - jsonlite::toJSON(self$`category`$toJSON(), auto_unbox = TRUE, digits = NA) - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - }, - if (!is.null(self$`photoUrls`)) { - sprintf( - '"photoUrls": - [%s] - ', - paste(unlist(lapply(self$`photoUrls`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`tags`)) { - sprintf( - '"tags": - [%s] -', - paste(sapply(self$`tags`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox = TRUE, digits = NA)), collapse = ",") - ) - }, - if (!is.null(self$`status`)) { - sprintf( - '"status": - "%s" - ', - self$`status` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/pet_api.R b/samples/client/petstore/R/R/pet_api.R index a19e0148629..6c74624fad2 100644 --- a/samples/client/petstore/R/R/pet_api.R +++ b/samples/client/petstore/R/R/pet_api.R @@ -435,7 +435,7 @@ PetApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/pet" @@ -1288,7 +1288,7 @@ PetApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/pet" diff --git a/samples/client/petstore/R/R/pet_map.R b/samples/client/petstore/R/R/pet_map.R index 1fc910ac1da..aa59c50a09c 100644 --- a/samples/client/petstore/R/R/pet_map.R +++ b/samples/client/petstore/R/R/pet_map.R @@ -40,10 +40,35 @@ PetMap <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return PetMap in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return PetMap as a base R list. + #' @examples + #' # convert array of PetMap (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert PetMap to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { PetMapObject <- list() if (!is.null(self$`pet`)) { PetMapObject[["pet"]] <- @@ -53,7 +78,7 @@ PetMap <- R6::R6Class( PetMapObject[[key]] <- self$additional_properties[[key]] } - PetMapObject + return(PetMapObject) }, #' @description @@ -78,26 +103,16 @@ PetMap <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return PetMap in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`pet`)) { - sprintf( - '"pet": - %s - ', - jsonlite::toJSON(lapply(self$`pet`, function(x){ x }), auto_unbox = TRUE, digits = NA) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/pig.R b/samples/client/petstore/R/R/pig.R index 596a9307d4d..94067ec4d72 100644 --- a/samples/client/petstore/R/R/pig.R +++ b/samples/client/petstore/R/R/pig.R @@ -109,25 +109,35 @@ Pig <- R6::R6Class( #' @description #' Serialize Pig to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the Pig. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize Pig to JSON. - #' - #' @return JSON representation of the Pig. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert Pig to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R/R/special.R b/samples/client/petstore/R/R/special.R index 5841fc79dd3..4c27190313f 100644 --- a/samples/client/petstore/R/R/special.R +++ b/samples/client/petstore/R/R/special.R @@ -97,10 +97,35 @@ Special <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Special in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Special as a base R list. + #' @examples + #' # convert array of Special (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Special to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { SpecialObject <- list() if (!is.null(self$`set_test`)) { SpecialObject[["set_test"]] <- @@ -134,7 +159,7 @@ Special <- R6::R6Class( SpecialObject[[key]] <- self$additional_properties[[key]] } - SpecialObject + return(SpecialObject) }, #' @description @@ -180,74 +205,16 @@ Special <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Special in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`set_test`)) { - sprintf( - '"set_test": - [%s] - ', - paste(unlist(lapply(self$`set_test`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`item_self`)) { - sprintf( - '"self": - %d - ', - self$`item_self` - ) - }, - if (!is.null(self$`item_private`)) { - sprintf( - '"private": - "%s" - ', - self$`item_private` - ) - }, - if (!is.null(self$`item_super`)) { - sprintf( - '"super": - "%s" - ', - self$`item_super` - ) - }, - if (!is.null(self$`123_number`)) { - sprintf( - '"123_number": - "%s" - ', - self$`123_number` - ) - }, - if (!is.null(self$`array[test]`)) { - sprintf( - '"array[test]": - "%s" - ', - self$`array[test]` - ) - }, - if (!is.null(self$`empty_string`)) { - sprintf( - '"empty_string": - "%s" - ', - self$`empty_string` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/store_api.R b/samples/client/petstore/R/R/store_api.R index 6889cdf7aa7..81acb942675 100644 --- a/samples/client/petstore/R/R/store_api.R +++ b/samples/client/petstore/R/R/store_api.R @@ -546,7 +546,7 @@ StoreApi <- R6::R6Class( if (!is.null(`order`)) { local_var_body <- `order`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/store/order" diff --git a/samples/client/petstore/R/R/tag.R b/samples/client/petstore/R/R/tag.R index c9ec58ae6b8..b4c893dfe77 100644 --- a/samples/client/petstore/R/R/tag.R +++ b/samples/client/petstore/R/R/tag.R @@ -50,10 +50,35 @@ Tag <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Tag in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Tag as a base R list. + #' @examples + #' # convert array of Tag (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Tag to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { TagObject <- list() if (!is.null(self$`id`)) { TagObject[["id"]] <- @@ -67,7 +92,7 @@ Tag <- R6::R6Class( TagObject[[key]] <- self$additional_properties[[key]] } - TagObject + return(TagObject) }, #' @description @@ -95,34 +120,16 @@ Tag <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Tag in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/update_pet_request.R b/samples/client/petstore/R/R/update_pet_request.R index 47369030cfa..3559d3c4d83 100644 --- a/samples/client/petstore/R/R/update_pet_request.R +++ b/samples/client/petstore/R/R/update_pet_request.R @@ -45,14 +45,39 @@ UpdatePetRequest <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return UpdatePetRequest in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return UpdatePetRequest as a base R list. + #' @examples + #' # convert array of UpdatePetRequest (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert UpdatePetRequest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { UpdatePetRequestObject <- list() if (!is.null(self$`jsonData`)) { UpdatePetRequestObject[["jsonData"]] <- - self$`jsonData`$toJSON() + self$`jsonData`$toSimpleType() } if (!is.null(self$`binaryDataN2Information`)) { UpdatePetRequestObject[["binaryDataN2Information"]] <- @@ -62,7 +87,7 @@ UpdatePetRequest <- R6::R6Class( UpdatePetRequestObject[[key]] <- self$additional_properties[[key]] } - UpdatePetRequestObject + return(UpdatePetRequestObject) }, #' @description @@ -92,34 +117,16 @@ UpdatePetRequest <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return UpdatePetRequest in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`jsonData`)) { - sprintf( - '"jsonData": - %s - ', - jsonlite::toJSON(self$`jsonData`$toJSON(), auto_unbox = TRUE, digits = NA) - ) - }, - if (!is.null(self$`binaryDataN2Information`)) { - sprintf( - '"binaryDataN2Information": - "%s" - ', - self$`binaryDataN2Information` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/user.R b/samples/client/petstore/R/R/user.R index df4396abb2c..361d0d454f2 100644 --- a/samples/client/petstore/R/R/user.R +++ b/samples/client/petstore/R/R/user.R @@ -104,10 +104,35 @@ User <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return User in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return User as a base R list. + #' @examples + #' # convert array of User (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert User to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { UserObject <- list() if (!is.null(self$`id`)) { UserObject[["id"]] <- @@ -145,7 +170,7 @@ User <- R6::R6Class( UserObject[[key]] <- self$additional_properties[[key]] } - UserObject + return(UserObject) }, #' @description @@ -191,82 +216,16 @@ User <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return User in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`username`)) { - sprintf( - '"username": - "%s" - ', - self$`username` - ) - }, - if (!is.null(self$`firstName`)) { - sprintf( - '"firstName": - "%s" - ', - self$`firstName` - ) - }, - if (!is.null(self$`lastName`)) { - sprintf( - '"lastName": - "%s" - ', - self$`lastName` - ) - }, - if (!is.null(self$`email`)) { - sprintf( - '"email": - "%s" - ', - self$`email` - ) - }, - if (!is.null(self$`password`)) { - sprintf( - '"password": - "%s" - ', - self$`password` - ) - }, - if (!is.null(self$`phone`)) { - sprintf( - '"phone": - "%s" - ', - self$`phone` - ) - }, - if (!is.null(self$`userStatus`)) { - sprintf( - '"userStatus": - %d - ', - self$`userStatus` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/user_api.R b/samples/client/petstore/R/R/user_api.R index 389cc69b57e..39b793e40f7 100644 --- a/samples/client/petstore/R/R/user_api.R +++ b/samples/client/petstore/R/R/user_api.R @@ -318,7 +318,7 @@ UserApi <- R6::R6Class( if (!is.null(`user`)) { local_var_body <- `user`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user" @@ -428,7 +428,7 @@ UserApi <- R6::R6Class( })), collapse = ",") local_var_body <- paste0("[", body.items, "]") } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user/createWithArray" @@ -538,7 +538,7 @@ UserApi <- R6::R6Class( })), collapse = ",") local_var_body <- paste0("[", body.items, "]") } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user/createWithList" @@ -1099,7 +1099,7 @@ UserApi <- R6::R6Class( if (!is.null(`user`)) { local_var_body <- `user`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user/{username}" diff --git a/samples/client/petstore/R/R/whale.R b/samples/client/petstore/R/R/whale.R index e39211045a7..ea54d3bdf71 100644 --- a/samples/client/petstore/R/R/whale.R +++ b/samples/client/petstore/R/R/whale.R @@ -59,10 +59,35 @@ Whale <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Whale in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Whale as a base R list. + #' @examples + #' # convert array of Whale (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Whale to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { WhaleObject <- list() if (!is.null(self$`hasBaleen`)) { WhaleObject[["hasBaleen"]] <- @@ -80,7 +105,7 @@ Whale <- R6::R6Class( WhaleObject[[key]] <- self$additional_properties[[key]] } - WhaleObject + return(WhaleObject) }, #' @description @@ -111,42 +136,16 @@ Whale <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Whale in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`hasBaleen`)) { - sprintf( - '"hasBaleen": - %s - ', - tolower(self$`hasBaleen`) - ) - }, - if (!is.null(self$`hasTeeth`)) { - sprintf( - '"hasTeeth": - %s - ', - tolower(self$`hasTeeth`) - ) - }, - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/zebra.R b/samples/client/petstore/R/R/zebra.R index fb6d90d4d98..6b85dbff409 100644 --- a/samples/client/petstore/R/R/zebra.R +++ b/samples/client/petstore/R/R/zebra.R @@ -53,10 +53,35 @@ Zebra <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Zebra in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Zebra as a base R list. + #' @examples + #' # convert array of Zebra (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Zebra to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { ZebraObject <- list() if (!is.null(self$`type`)) { ZebraObject[["type"]] <- @@ -70,7 +95,7 @@ Zebra <- R6::R6Class( ZebraObject[[key]] <- self$additional_properties[[key]] } - ZebraObject + return(ZebraObject) }, #' @description @@ -101,34 +126,16 @@ Zebra <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Zebra in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`type`)) { - sprintf( - '"type": - "%s" - ', - self$`type` - ) - }, - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/tests/testthat/test_petstore.R b/samples/client/petstore/R/tests/testthat/test_petstore.R index f7a70df4f9d..641e2cbb275 100644 --- a/samples/client/petstore/R/tests/testthat/test_petstore.R +++ b/samples/client/petstore/R/tests/testthat/test_petstore.R @@ -42,7 +42,7 @@ test_that("Test FindPetByStatus", { test_that("Test toJSON toJSONString fromJSON fromJSONString", { pet0 <- Pet$new() - jsonpet <- pet0$toJSON() + jsonpet <- pet0$toSimpleType() pet2 <- pet0$fromJSON( jsonlite::toJSON(jsonpet, auto_unbox = TRUE) ) @@ -68,7 +68,7 @@ test_that("Test toJSON toJSONString fromJSON fromJSONString", { ), status = "available" ) - jsonpet <- pet1$toJSON() + jsonpet <- pet1$toSimpleType() pet2 <- pet1$fromJSON( jsonlite::toJSON(jsonpet, auto_unbox = TRUE) ) @@ -90,7 +90,7 @@ test_that("Test toJSON toJSONString fromJSON fromJSONString", { test_that("Test Category", { c1 <- Category$new(id = 450, name = "test_cat") c2 <- Category$new() - c2$fromJSON(jsonlite::toJSON(c1$toJSON(), auto_unbox = TRUE)) + c2$fromJSON(jsonlite::toJSON(c1$toSimpleType(), auto_unbox = TRUE)) expect_equal(c1, c2) c2$fromJSONString(c1$toJSONString()) expect_equal(c1, c2)