From dcf2b16e6842fe2a520f0c98315dd22cc86aacd5 Mon Sep 17 00:00:00 2001 From: joXemMx Date: Thu, 21 Mar 2024 17:50:46 +0100 Subject: [PATCH 1/2] catch enum classes in toJSON functions --- .../src/main/resources/r/modelGeneric.mustache | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/r/modelGeneric.mustache b/modules/openapi-generator/src/main/resources/r/modelGeneric.mustache index cdafe398e0d8..0aa94aa0aee8 100644 --- a/modules/openapi-generator/src/main/resources/r/modelGeneric.mustache +++ b/modules/openapi-generator/src/main/resources/r/modelGeneric.mustache @@ -238,7 +238,11 @@ self$`{{name}}` {{/isPrimitiveType}} {{^isPrimitiveType}} - self$`{{name}}`$toJSON() + if (length(names(self$`{{name}}`$toJSON())) == 0L && is.character(jsonlite::fromJSON(self$`{{name}}`$toJSON()))) { + jsonlite::fromJSON(self$`{{name}}`$toJSON()) + } else { + self$`{{name}}`$toJSON() + } {{/isPrimitiveType}} {{/isContainer}} } From 4bb7c44f5204ac09c1827b3c78a6853a429bb74d Mon Sep 17 00:00:00 2001 From: joXemMx Date: Thu, 21 Mar 2024 17:51:04 +0100 Subject: [PATCH 2/2] regenerate samples --- samples/client/echo_api/r/R/pet.R | 6 +++++- samples/client/petstore/R-httr2-wrapper/R/nested_one_of.R | 6 +++++- samples/client/petstore/R-httr2-wrapper/R/pet.R | 6 +++++- .../client/petstore/R-httr2-wrapper/R/update_pet_request.R | 6 +++++- samples/client/petstore/R-httr2/R/nested_one_of.R | 6 +++++- samples/client/petstore/R-httr2/R/pet.R | 6 +++++- samples/client/petstore/R-httr2/R/update_pet_request.R | 6 +++++- samples/client/petstore/R/R/nested_one_of.R | 6 +++++- samples/client/petstore/R/R/pet.R | 6 +++++- samples/client/petstore/R/R/update_pet_request.R | 6 +++++- 10 files changed, 50 insertions(+), 10 deletions(-) diff --git a/samples/client/echo_api/r/R/pet.R b/samples/client/echo_api/r/R/pet.R index 9d2e80b3bb21..2dd3a996e326 100644 --- a/samples/client/echo_api/r/R/pet.R +++ b/samples/client/echo_api/r/R/pet.R @@ -94,7 +94,11 @@ Pet <- R6::R6Class( } if (!is.null(self$`category`)) { PetObject[["category"]] <- - self$`category`$toJSON() + if (length(names(self$`category`$toJSON())) == 0L && is.character(jsonlite::fromJSON(self$`category`$toJSON()))) { + jsonlite::fromJSON(self$`category`$toJSON()) + } else { + self$`category`$toJSON() + } } if (!is.null(self$`photoUrls`)) { PetObject[["photoUrls"]] <- 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 8fbdf43b466e..5a84bef826a5 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 @@ -63,7 +63,11 @@ NestedOneOf <- R6::R6Class( } if (!is.null(self$`nested_pig`)) { NestedOneOfObject[["nested_pig"]] <- - self$`nested_pig`$toJSON() + if (length(names(self$`nested_pig`$toJSON())) == 0L && is.character(jsonlite::fromJSON(self$`nested_pig`$toJSON()))) { + jsonlite::fromJSON(self$`nested_pig`$toJSON()) + } else { + self$`nested_pig`$toJSON() + } } for (key in names(self$additional_properties)) { NestedOneOfObject[[key]] <- self$additional_properties[[key]] diff --git a/samples/client/petstore/R-httr2-wrapper/R/pet.R b/samples/client/petstore/R-httr2-wrapper/R/pet.R index ea3b23ce9680..6a05a3cb871a 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/pet.R +++ b/samples/client/petstore/R-httr2-wrapper/R/pet.R @@ -100,7 +100,11 @@ Pet <- R6::R6Class( } if (!is.null(self$`category`)) { PetObject[["category"]] <- - self$`category`$toJSON() + if (length(names(self$`category`$toJSON())) == 0L && is.character(jsonlite::fromJSON(self$`category`$toJSON()))) { + jsonlite::fromJSON(self$`category`$toJSON()) + } else { + self$`category`$toJSON() + } } if (!is.null(self$`name`)) { PetObject[["name"]] <- 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 c29abc945abc..6a7a330498ce 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 @@ -56,7 +56,11 @@ UpdatePetRequest <- R6::R6Class( UpdatePetRequestObject <- list() if (!is.null(self$`jsonData`)) { UpdatePetRequestObject[["jsonData"]] <- - self$`jsonData`$toJSON() + if (length(names(self$`jsonData`$toJSON())) == 0L && is.character(jsonlite::fromJSON(self$`jsonData`$toJSON()))) { + jsonlite::fromJSON(self$`jsonData`$toJSON()) + } else { + self$`jsonData`$toJSON() + } } if (!is.null(self$`binaryDataN2Information`)) { UpdatePetRequestObject[["binaryDataN2Information"]] <- 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 a62902ac4fb1..2facee23566c 100644 --- a/samples/client/petstore/R-httr2/R/nested_one_of.R +++ b/samples/client/petstore/R-httr2/R/nested_one_of.R @@ -53,7 +53,11 @@ NestedOneOf <- R6::R6Class( } if (!is.null(self$`nested_pig`)) { NestedOneOfObject[["nested_pig"]] <- - self$`nested_pig`$toJSON() + if (length(names(self$`nested_pig`$toJSON())) == 0L && is.character(jsonlite::fromJSON(self$`nested_pig`$toJSON()))) { + jsonlite::fromJSON(self$`nested_pig`$toJSON()) + } else { + self$`nested_pig`$toJSON() + } } NestedOneOfObject }, diff --git a/samples/client/petstore/R-httr2/R/pet.R b/samples/client/petstore/R-httr2/R/pet.R index 7ce7c6336774..7fd496416639 100644 --- a/samples/client/petstore/R-httr2/R/pet.R +++ b/samples/client/petstore/R-httr2/R/pet.R @@ -90,7 +90,11 @@ Pet <- R6::R6Class( } if (!is.null(self$`category`)) { PetObject[["category"]] <- - self$`category`$toJSON() + if (length(names(self$`category`$toJSON())) == 0L && is.character(jsonlite::fromJSON(self$`category`$toJSON()))) { + jsonlite::fromJSON(self$`category`$toJSON()) + } else { + self$`category`$toJSON() + } } if (!is.null(self$`name`)) { PetObject[["name"]] <- 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 62f5c7948839..855129f5c57d 100644 --- a/samples/client/petstore/R-httr2/R/update_pet_request.R +++ b/samples/client/petstore/R-httr2/R/update_pet_request.R @@ -46,7 +46,11 @@ UpdatePetRequest <- R6::R6Class( UpdatePetRequestObject <- list() if (!is.null(self$`jsonData`)) { UpdatePetRequestObject[["jsonData"]] <- - self$`jsonData`$toJSON() + if (length(names(self$`jsonData`$toJSON())) == 0L && is.character(jsonlite::fromJSON(self$`jsonData`$toJSON()))) { + jsonlite::fromJSON(self$`jsonData`$toJSON()) + } else { + self$`jsonData`$toJSON() + } } if (!is.null(self$`binaryDataN2Information`)) { UpdatePetRequestObject[["binaryDataN2Information"]] <- diff --git a/samples/client/petstore/R/R/nested_one_of.R b/samples/client/petstore/R/R/nested_one_of.R index 8fbdf43b466e..5a84bef826a5 100644 --- a/samples/client/petstore/R/R/nested_one_of.R +++ b/samples/client/petstore/R/R/nested_one_of.R @@ -63,7 +63,11 @@ NestedOneOf <- R6::R6Class( } if (!is.null(self$`nested_pig`)) { NestedOneOfObject[["nested_pig"]] <- - self$`nested_pig`$toJSON() + if (length(names(self$`nested_pig`$toJSON())) == 0L && is.character(jsonlite::fromJSON(self$`nested_pig`$toJSON()))) { + jsonlite::fromJSON(self$`nested_pig`$toJSON()) + } else { + self$`nested_pig`$toJSON() + } } for (key in names(self$additional_properties)) { NestedOneOfObject[[key]] <- self$additional_properties[[key]] diff --git a/samples/client/petstore/R/R/pet.R b/samples/client/petstore/R/R/pet.R index ea3b23ce9680..6a05a3cb871a 100644 --- a/samples/client/petstore/R/R/pet.R +++ b/samples/client/petstore/R/R/pet.R @@ -100,7 +100,11 @@ Pet <- R6::R6Class( } if (!is.null(self$`category`)) { PetObject[["category"]] <- - self$`category`$toJSON() + if (length(names(self$`category`$toJSON())) == 0L && is.character(jsonlite::fromJSON(self$`category`$toJSON()))) { + jsonlite::fromJSON(self$`category`$toJSON()) + } else { + self$`category`$toJSON() + } } if (!is.null(self$`name`)) { PetObject[["name"]] <- diff --git a/samples/client/petstore/R/R/update_pet_request.R b/samples/client/petstore/R/R/update_pet_request.R index c29abc945abc..6a7a330498ce 100644 --- a/samples/client/petstore/R/R/update_pet_request.R +++ b/samples/client/petstore/R/R/update_pet_request.R @@ -56,7 +56,11 @@ UpdatePetRequest <- R6::R6Class( UpdatePetRequestObject <- list() if (!is.null(self$`jsonData`)) { UpdatePetRequestObject[["jsonData"]] <- - self$`jsonData`$toJSON() + if (length(names(self$`jsonData`$toJSON())) == 0L && is.character(jsonlite::fromJSON(self$`jsonData`$toJSON()))) { + jsonlite::fromJSON(self$`jsonData`$toJSON()) + } else { + self$`jsonData`$toJSON() + } } if (!is.null(self$`binaryDataN2Information`)) { UpdatePetRequestObject[["binaryDataN2Information"]] <-