diff --git a/modules/openapi-generator/src/main/resources/r/modelAnyOf.mustache b/modules/openapi-generator/src/main/resources/r/modelAnyOf.mustache index d27c5cedbb5..06bbe572734 100644 --- a/modules/openapi-generator/src/main/resources/r/modelAnyOf.mustache +++ b/modules/openapi-generator/src/main/resources/r/modelAnyOf.mustache @@ -69,11 +69,11 @@ #' @description #' Serialize {{{classname}}} to JSON string. #' - #' @return JSON string reprenation of the {{{classname}}}. + #' @return JSON string representation of the {{{classname}}}. #' @export toJSONString = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSONString() + as.character(jsonlite::minify((self$actual_instance$toJSONString()))) } else { NULL } @@ -83,7 +83,7 @@ #' @description #' Serialize {{{classname}}} to JSON. #' - #' @return JSON reprenation of the {{{classname}}}. + #' @return JSON representation of the {{{classname}}}. #' @export toJSON = function() { if (!is.null(self$actual_instance)) { @@ -111,6 +111,22 @@ # no error thrown, restore old values self$actual_instance <- actual_instance_bak self$actual_type <- actual_type_bak - } + }, + #' Returns the string representation of the instance. + #' + #' @description + #' Returns the string representation of the instance. + #' + #' @return The string representation of the instance. + #' @export + toString = function() { + jsoncontent <- c( + sprintf('"actual_instance": %s', if (is.null(self$actual_instance)) {NULL} else {self$actual_instance$toJSONString()}), + sprintf('"actual_type": "%s"', self$actual_type), + sprintf('"any_of": "%s"', paste( unlist(self$any_of), collapse=', ')) + ) + jsoncontent <- paste(jsoncontent, collapse = ",") + as.character(jsonlite::prettify(paste('{', jsoncontent, '}', sep = ""))) + } ) ) diff --git a/modules/openapi-generator/src/main/resources/r/modelOneOf.mustache b/modules/openapi-generator/src/main/resources/r/modelOneOf.mustache index d53f32f59fa..20077cccdf8 100644 --- a/modules/openapi-generator/src/main/resources/r/modelOneOf.mustache +++ b/modules/openapi-generator/src/main/resources/r/modelOneOf.mustache @@ -84,11 +84,11 @@ #' @description #' Serialize {{{classname}}} to JSON string. #' - #' @return JSON string reprenation of the {{{classname}}}. + #' @return JSON string representation of the {{{classname}}}. #' @export toJSONString = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSONString() + as.character(jsonlite::minify(self$actual_instance$toJSONString())) } else { NULL } @@ -98,7 +98,7 @@ #' @description #' Serialize {{{classname}}} to JSON. #' - #' @return JSON reprenation of the {{{classname}}}. + #' @return JSON representation of the {{{classname}}}. #' @export toJSON = function() { if (!is.null(self$actual_instance)) { @@ -126,6 +126,22 @@ # no error thrown, restore old values self$actual_instance <- actual_instance_bak self$actual_type <- actual_type_bak + }, + #' Returns the string representation of the instance. + #' + #' @description + #' Returns the string representation of the instance. + #' + #' @return The string representation of the instance. + #' @export + toString = function() { + jsoncontent <- c( + sprintf('"actual_instance": %s', if (is.null(self$actual_instance)) {NULL} else {self$actual_instance$toJSONString()}), + sprintf('"actual_type": "%s"', self$actual_type), + sprintf('"one_of": "%s"', paste( unlist(self$one_of), collapse=', ')) + ) + jsoncontent <- paste(jsoncontent, collapse = ",") + as.character(jsonlite::prettify(paste('{', jsoncontent, '}', sep = ""))) } ) ) diff --git a/samples/client/petstore/R/R/any_of_pig.R b/samples/client/petstore/R/R/any_of_pig.R index 73b8e89c6f9..31044e62b18 100644 --- a/samples/client/petstore/R/R/any_of_pig.R +++ b/samples/client/petstore/R/R/any_of_pig.R @@ -92,11 +92,11 @@ AnyOfPig <- R6::R6Class( #' @description #' Serialize AnyOfPig to JSON string. #' - #' @return JSON string reprenation of the AnyOfPig. + #' @return JSON string representation of the AnyOfPig. #' @export toJSONString = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSONString() + as.character(jsonlite::minify((self$actual_instance$toJSONString()))) } else { NULL } @@ -106,7 +106,7 @@ AnyOfPig <- R6::R6Class( #' @description #' Serialize AnyOfPig to JSON. #' - #' @return JSON reprenation of the AnyOfPig. + #' @return JSON representation of the AnyOfPig. #' @export toJSON = function() { if (!is.null(self$actual_instance)) { @@ -134,7 +134,23 @@ AnyOfPig <- R6::R6Class( # no error thrown, restore old values self$actual_instance <- actual_instance_bak self$actual_type <- actual_type_bak - } + }, + #' Returns the string representation of the instance. + #' + #' @description + #' Returns the string representation of the instance. + #' + #' @return The string representation of the instance. + #' @export + toString = function() { + jsoncontent <- c( + sprintf('"actual_instance": %s', if (is.null(self$actual_instance)) {NULL} else {self$actual_instance$toJSONString()}), + sprintf('"actual_type": "%s"', self$actual_type), + sprintf('"any_of": "%s"', paste( unlist(self$any_of), collapse=', ')) + ) + jsoncontent <- paste(jsoncontent, collapse = ",") + as.character(jsonlite::prettify(paste('{', jsoncontent, '}', sep = ""))) + } ) ) diff --git a/samples/client/petstore/R/R/pig.R b/samples/client/petstore/R/R/pig.R index 565df078209..60f7ecbc002 100644 --- a/samples/client/petstore/R/R/pig.R +++ b/samples/client/petstore/R/R/pig.R @@ -108,11 +108,11 @@ Pig <- R6::R6Class( #' @description #' Serialize Pig to JSON string. #' - #' @return JSON string reprenation of the Pig. + #' @return JSON string representation of the Pig. #' @export toJSONString = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSONString() + as.character(jsonlite::minify(self$actual_instance$toJSONString())) } else { NULL } @@ -122,7 +122,7 @@ Pig <- R6::R6Class( #' @description #' Serialize Pig to JSON. #' - #' @return JSON reprenation of the Pig. + #' @return JSON representation of the Pig. #' @export toJSON = function() { if (!is.null(self$actual_instance)) { @@ -150,6 +150,22 @@ Pig <- R6::R6Class( # no error thrown, restore old values self$actual_instance <- actual_instance_bak self$actual_type <- actual_type_bak + }, + #' Returns the string representation of the instance. + #' + #' @description + #' Returns the string representation of the instance. + #' + #' @return The string representation of the instance. + #' @export + toString = function() { + jsoncontent <- c( + sprintf('"actual_instance": %s', if (is.null(self$actual_instance)) {NULL} else {self$actual_instance$toJSONString()}), + sprintf('"actual_type": "%s"', self$actual_type), + sprintf('"one_of": "%s"', paste( unlist(self$one_of), collapse=', ')) + ) + jsoncontent <- paste(jsoncontent, collapse = ",") + as.character(jsonlite::prettify(paste('{', jsoncontent, '}', sep = ""))) } ) ) diff --git a/samples/client/petstore/R/tests/testthat/test_petstore.R b/samples/client/petstore/R/tests/testthat/test_petstore.R index 424fc5c291a..7db1cc4dcac 100644 --- a/samples/client/petstore/R/tests/testthat/test_petstore.R +++ b/samples/client/petstore/R/tests/testthat/test_petstore.R @@ -236,7 +236,10 @@ test_that("Tests oneOf", { nested_oneof$nested_pig <- pig nested_oneof$size <- 15 expect_equal(nested_oneof$toJSONString(), '{"size":15,"nested_pig":{"className":"BasquePig","color":"red"}}') - + + # test toString + expect_equal(as.character(jsonlite::minify(pig$toString())), "{\"actual_instance\":{\"className\":\"BasquePig\",\"color\":\"red\"},\"actual_type\":\"BasquePig\",\"one_of\":\"BasquePig, DanishPig\"}") + expect_equal(as.character(jsonlite::minify(Pig$new()$toString())), "{\"one_of\":\"BasquePig, DanishPig\"}") }) test_that("Tests anyOf", {