diff --git a/bin/configs/r-httr2-client.yaml b/bin/configs/r-httr2-client.yaml index 15779e26d36..c842eefa49e 100644 --- a/bin/configs/r-httr2-client.yaml +++ b/bin/configs/r-httr2-client.yaml @@ -4,6 +4,12 @@ inputSpec: modules/openapi-generator/src/test/resources/3_0/r/petstore.yaml templateDir: modules/openapi-generator/src/main/resources/r httpUserAgent: PetstoreAgent library: httr2 +modelNameMappings: + dummy_model: JustModel +parameterNameMappings: + path_array: path_array_parameter +nameMappings: + percent_description: percent additionalProperties: packageName: petstore exceptionPackage: rlang @@ -11,3 +17,4 @@ additionalProperties: returnExceptionOnFailure: true errorObjectType: "ModelApiResponse" operationIdNaming: snake_case + diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java index 5514520c0d0..872c75239d2 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java @@ -393,6 +393,11 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig { @Override public String toParamName(String name) { + // obtain the name from parameterNameMapping directly if provided + if (parameterNameMapping.containsKey(name)) { + return parameterNameMapping.get(name); + } + // replace - with _ e.g. created-at => created_at name = sanitizeName(name.replaceAll("-", "_")); @@ -417,6 +422,11 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig { @Override public String toVarName(String name) { + // obtain the name from nameMapping directly if provided + if (nameMapping.containsKey(name)) { + return nameMapping.get(name); + } + // escape item reserved words with "item_" prefix if (itemReservedWords.contains(name)) { LOGGER.info("The item `{}` has been renamed to `item_{}` as it's a reserved word.", name, name); @@ -434,11 +444,21 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig { @Override public String toModelFilename(String name) { + // obtain the name from modelNameMapping directly if provided + if (modelNameMapping.containsKey(name)) { + return underscore(modelNameMapping.get(name)); + } + return underscore(toModelName(name)); } @Override public String toModelName(String name) { + // obtain the name from modelNameMapping directly if provided + if (modelNameMapping.containsKey(name)) { + return modelNameMapping.get(name); + } + // We need to check if schema-mapping has a different model for this class, so we use it // instead of the auto-generated one. if (schemaMapping.containsKey(name)) { diff --git a/modules/openapi-generator/src/test/resources/3_0/r/petstore.yaml b/modules/openapi-generator/src/test/resources/3_0/r/petstore.yaml index fcddaaa8d60..2fd09bffbf8 100644 --- a/modules/openapi-generator/src/test/resources/3_0/r/petstore.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/r/petstore.yaml @@ -1121,6 +1121,12 @@ components: required: - className - url_property + dummy_model: + description: to test the model name mapping + type: object + properties: + property: + type: string format_test: type: object required: @@ -1189,3 +1195,4 @@ components: description: A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01. type: string pattern: '/^image_\d{1,3}$/i' + diff --git a/samples/client/petstore/R-httr2-wrapper/.openapi-generator/FILES b/samples/client/petstore/R-httr2-wrapper/.openapi-generator/FILES index 3d39761f135..5023966da14 100644 --- a/samples/client/petstore/R-httr2-wrapper/.openapi-generator/FILES +++ b/samples/client/petstore/R-httr2-wrapper/.openapi-generator/FILES @@ -18,6 +18,7 @@ R/category.R R/danish_pig.R R/date.R R/dog.R +R/dummy_model.R R/fake_api.R R/format_test.R R/mammal.R @@ -48,6 +49,7 @@ docs/Category.md docs/DanishPig.md docs/Date.md docs/Dog.md +docs/DummyModel.md docs/FakeApi.md docs/FormatTest.md docs/Mammal.md diff --git a/samples/client/petstore/R-httr2-wrapper/NAMESPACE b/samples/client/petstore/R-httr2-wrapper/NAMESPACE index c4a03c84270..fd062786db1 100644 --- a/samples/client/petstore/R-httr2-wrapper/NAMESPACE +++ b/samples/client/petstore/R-httr2-wrapper/NAMESPACE @@ -26,6 +26,7 @@ export(Category) export(DanishPig) export(Date) export(Dog) +export(DummyModel) export(FormatTest) export(Mammal) export(ModelApiResponse) diff --git a/samples/client/petstore/R-httr2-wrapper/R/dummy_model.R b/samples/client/petstore/R-httr2-wrapper/R/dummy_model.R new file mode 100644 index 00000000000..75c7c5f8a56 --- /dev/null +++ b/samples/client/petstore/R-httr2-wrapper/R/dummy_model.R @@ -0,0 +1,196 @@ +#' Create a new DummyModel +#' +#' @description +#' to test the model name mapping +#' +#' @docType class +#' @title DummyModel +#' @description DummyModel Class +#' @format An \code{R6Class} generator object +#' @field property character [optional] +#' @field _field_list a list of fields list(character) +#' @field additional_properties additional properties list(character) [optional] +#' @importFrom R6 R6Class +#' @importFrom jsonlite fromJSON toJSON +#' @export +DummyModel <- R6::R6Class( + "DummyModel", + public = list( + `property` = NULL, + `_field_list` = c("property"), + `additional_properties` = list(), + #' Initialize a new DummyModel class. + #' + #' @description + #' Initialize a new DummyModel class. + #' + #' @param property property + #' @param additional_properties additional properties (optional) + #' @param ... Other optional arguments. + #' @export + initialize = function(`property` = NULL, additional_properties = NULL, ...) { + if (!is.null(`property`)) { + if (!(is.character(`property`) && length(`property`) == 1)) { + stop(paste("Error! Invalid data for `property`. Must be a string:", `property`)) + } + self$`property` <- `property` + } + if (!is.null(additional_properties)) { + for (key in names(additional_properties)) { + self$additional_properties[[key]] <- additional_properties[[key]] + } + } + }, + #' To JSON string + #' + #' @description + #' To JSON String + #' + #' @return DummyModel in JSON format + #' @export + toJSON = function() { + DummyModelObject <- list() + if (!is.null(self$`property`)) { + DummyModelObject[["property"]] <- + self$`property` + } + for (key in names(self$additional_properties)) { + DummyModelObject[[key]] <- self$additional_properties[[key]] + } + + DummyModelObject + }, + #' Deserialize JSON string into an instance of DummyModel + #' + #' @description + #' Deserialize JSON string into an instance of DummyModel + #' + #' @param input_json the JSON input + #' @return the instance of DummyModel + #' @export + fromJSON = function(input_json) { + this_object <- jsonlite::fromJSON(input_json) + if (!is.null(this_object$`property`)) { + self$`property` <- this_object$`property` + } + # process additional properties/fields in the payload + for (key in names(this_object)) { + if (!(key %in% self$`_field_list`)) { # json key not in list of fields + self$additional_properties[[key]] <- this_object[[key]] + } + } + + self + }, + #' To JSON string + #' + #' @description + #' To JSON String + #' + #' @return DummyModel in JSON format + #' @export + 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) + for (key in names(self$additional_properties)) { + json_obj[[key]] <- self$additional_properties[[key]] + } + json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + }, + #' Deserialize JSON string into an instance of DummyModel + #' + #' @description + #' Deserialize JSON string into an instance of DummyModel + #' + #' @param input_json the JSON input + #' @return the instance of DummyModel + #' @export + fromJSONString = function(input_json) { + this_object <- jsonlite::fromJSON(input_json) + self$`property` <- this_object$`property` + # process additional properties/fields in the payload + for (key in names(this_object)) { + if (!(key %in% self$`_field_list`)) { # json key not in list of fields + self$additional_properties[[key]] <- this_object[[key]] + } + } + + self + }, + #' Validate JSON input with respect to DummyModel + #' + #' @description + #' Validate JSON input with respect to DummyModel and throw an exception if invalid + #' + #' @param input the JSON input + #' @export + validateJSON = function(input) { + input_json <- jsonlite::fromJSON(input) + }, + #' To string (JSON format) + #' + #' @description + #' To string (JSON format) + #' + #' @return String representation of DummyModel + #' @export + toString = function() { + self$toJSONString() + }, + #' Return true if the values in all fields are valid. + #' + #' @description + #' Return true if the values in all fields are valid. + #' + #' @return true if the values in all fields are valid. + #' @export + isValid = function() { + TRUE + }, + #' Return a list of invalid fields (if any). + #' + #' @description + #' Return a list of invalid fields (if any). + #' + #' @return A list of invalid fields (if any). + #' @export + getInvalidFields = function() { + invalid_fields <- list() + invalid_fields + }, + #' Print the object + #' + #' @description + #' Print the object + #' + #' @export + print = function() { + print(jsonlite::prettify(self$toJSONString())) + invisible(self) + } + ), + # Lock the class to prevent modifications to the method or field + lock_class = TRUE +) +## Uncomment below to unlock the class to allow modifications of the method or field +# DummyModel$unlock() +# +## Below is an example to define the print function +# DummyModel$set("public", "print", function(...) { +# print(jsonlite::prettify(self$toJSONString())) +# invisible(self) +# }) +## Uncomment below to lock the class to prevent modifications to the method or field +# DummyModel$lock() + diff --git a/samples/client/petstore/R-httr2-wrapper/README.md b/samples/client/petstore/R-httr2-wrapper/README.md index e09946a3a05..1fbd788e2bb 100644 --- a/samples/client/petstore/R-httr2-wrapper/README.md +++ b/samples/client/petstore/R-httr2-wrapper/README.md @@ -113,6 +113,7 @@ Class | Method | HTTP request | Description - [DanishPig](docs/DanishPig.md) - [Date](docs/Date.md) - [Dog](docs/Dog.md) + - [DummyModel](docs/DummyModel.md) - [FormatTest](docs/FormatTest.md) - [Mammal](docs/Mammal.md) - [ModelApiResponse](docs/ModelApiResponse.md) diff --git a/samples/client/petstore/R-httr2-wrapper/docs/DummyModel.md b/samples/client/petstore/R-httr2-wrapper/docs/DummyModel.md new file mode 100644 index 00000000000..fdf3ba12203 --- /dev/null +++ b/samples/client/petstore/R-httr2-wrapper/docs/DummyModel.md @@ -0,0 +1,10 @@ +# petstore::DummyModel + +to test the model name mapping + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**property** | **character** | | [optional] + + diff --git a/samples/client/petstore/R-httr2-wrapper/tests/testthat/test_dummy_model.R b/samples/client/petstore/R-httr2-wrapper/tests/testthat/test_dummy_model.R new file mode 100644 index 00000000000..b4f8e11b7f5 --- /dev/null +++ b/samples/client/petstore/R-httr2-wrapper/tests/testthat/test_dummy_model.R @@ -0,0 +1,13 @@ +# Automatically generated by openapi-generator (https://openapi-generator.tech) +# Please update as you see appropriate + +context("Test DummyModel") + +model_instance <- DummyModel$new() + +test_that("property", { + # tests for the property `property` (character) + + # uncomment below to test the property + #expect_equal(model.instance$`property`, "EXPECTED_RESULT") +}) diff --git a/samples/client/petstore/R-httr2/.openapi-generator/FILES b/samples/client/petstore/R-httr2/.openapi-generator/FILES index 781b048629b..e3ca4f60cbc 100644 --- a/samples/client/petstore/R-httr2/.openapi-generator/FILES +++ b/samples/client/petstore/R-httr2/.openapi-generator/FILES @@ -20,6 +20,7 @@ R/date.R R/dog.R R/fake_api.R R/format_test.R +R/just_model.R R/mammal.R R/model_api_response.R R/nested_one_of.R @@ -49,6 +50,7 @@ docs/Date.md docs/Dog.md docs/FakeApi.md docs/FormatTest.md +docs/JustModel.md docs/Mammal.md docs/ModelApiResponse.md docs/NestedOneOf.md diff --git a/samples/client/petstore/R-httr2/NAMESPACE b/samples/client/petstore/R-httr2/NAMESPACE index 26ea22705ad..e196ce103b3 100644 --- a/samples/client/petstore/R-httr2/NAMESPACE +++ b/samples/client/petstore/R-httr2/NAMESPACE @@ -25,6 +25,7 @@ export(DanishPig) export(Date) export(Dog) export(FormatTest) +export(JustModel) export(Mammal) export(ModelApiResponse) export(NestedOneOf) diff --git a/samples/client/petstore/R-httr2/R/date.R b/samples/client/petstore/R-httr2/R/date.R index 482bb1ef037..9a09f05a5a9 100644 --- a/samples/client/petstore/R-httr2/R/date.R +++ b/samples/client/petstore/R-httr2/R/date.R @@ -8,7 +8,7 @@ #' @description Date Class #' @format An \code{R6Class} generator object #' @field className character -#' @field percent_description using \% in the description character [optional] +#' @field percent using \% in the description character [optional] #' @field url_property character #' @importFrom R6 R6Class #' @importFrom jsonlite fromJSON toJSON @@ -17,7 +17,7 @@ Date <- R6::R6Class( "Date", public = list( `className` = NULL, - `percent_description` = NULL, + `percent` = NULL, `url_property` = NULL, #' Initialize a new Date class. #' @@ -26,10 +26,10 @@ Date <- R6::R6Class( #' #' @param className className #' @param url_property url_property - #' @param percent_description using \% in the description + #' @param percent using \% in the description #' @param ... Other optional arguments. #' @export - initialize = function(`className`, `url_property`, `percent_description` = NULL, ...) { + initialize = function(`className`, `url_property`, `percent` = NULL, ...) { if (!missing(`className`)) { if (!(is.character(`className`) && length(`className`) == 1)) { stop(paste("Error! Invalid data for `className`. Must be a string:", `className`)) @@ -46,11 +46,11 @@ Date <- R6::R6Class( } self$`url_property` <- `url_property` } - if (!is.null(`percent_description`)) { - if (!(is.character(`percent_description`) && length(`percent_description`) == 1)) { - stop(paste("Error! Invalid data for `percent_description`. Must be a string:", `percent_description`)) + if (!is.null(`percent`)) { + if (!(is.character(`percent`) && length(`percent`) == 1)) { + stop(paste("Error! Invalid data for `percent`. Must be a string:", `percent`)) } - self$`percent_description` <- `percent_description` + self$`percent` <- `percent` } }, #' To JSON string @@ -66,9 +66,9 @@ Date <- R6::R6Class( DateObject[["className"]] <- self$`className` } - if (!is.null(self$`percent_description`)) { + if (!is.null(self$`percent`)) { DateObject[["percent_description"]] <- - self$`percent_description` + self$`percent` } if (!is.null(self$`url_property`)) { DateObject[["url_property"]] <- @@ -90,7 +90,7 @@ Date <- R6::R6Class( self$`className` <- this_object$`className` } if (!is.null(this_object$`percent_description`)) { - self$`percent_description` <- this_object$`percent_description` + self$`percent` <- this_object$`percent_description` } if (!is.null(this_object$`url_property`)) { # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r @@ -118,12 +118,12 @@ Date <- R6::R6Class( self$`className` ) }, - if (!is.null(self$`percent_description`)) { + if (!is.null(self$`percent`)) { sprintf( '"percent_description": "%s" ', - self$`percent_description` + self$`percent` ) }, if (!is.null(self$`url_property`)) { @@ -149,7 +149,7 @@ Date <- R6::R6Class( fromJSONString = function(input_json) { this_object <- jsonlite::fromJSON(input_json) self$`className` <- this_object$`className` - self$`percent_description` <- this_object$`percent_description` + self$`percent` <- this_object$`percent` # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r if (!stringr::str_detect(this_object$`url_property`, "(https?|ftp)://[^ /$.?#].[^\\s]*")) { stop(paste("Error! Invalid data for `url_property`. Must be a URL:", this_object$`url_property`)) diff --git a/samples/client/petstore/R-httr2/R/fake_api.R b/samples/client/petstore/R-httr2/R/fake_api.R index e5977eb139a..c0c1324e56b 100644 --- a/samples/client/petstore/R-httr2/R/fake_api.R +++ b/samples/client/petstore/R-httr2/R/fake_api.R @@ -61,7 +61,7 @@ #' #' #' \itemize{ -#' \item \emph{ @param } path_array list( character ) +#' \item \emph{ @param } path_array_parameter list( character ) #' #' \item On encountering errors, an error of subclass ApiException will be thrown. #' @@ -188,14 +188,14 @@ #' #################### fake_path_array #################### #' #' library(petstore) -#' var_path_array <- c("inner_example") # array[character] | dummy path parameter +#' var_path_array_parameter <- c("inner_example") # array[character] | dummy path parameter #' #' #test array parameter in path #' api_instance <- FakeApi$new() #' #' result <- tryCatch( #' -#' api_instance$fake_path_array(var_path_array), +#' api_instance$fake_path_array(var_path_array_parameter), #' ApiException = function(ex) ex #' ) #' # In case of error, print the error object @@ -525,12 +525,12 @@ FakeApi <- R6::R6Class( #' @description #' test array parameter in path #' - #' @param path_array dummy path parameter + #' @param path_array_parameter dummy path parameter #' @param ... Other optional arguments #' @return void #' @export - fake_path_array = function(path_array, ...) { - local_var_response <- self$fake_path_array_with_http_info(path_array, ...) + fake_path_array = function(path_array_parameter, ...) { + local_var_response <- self$fake_path_array_with_http_info(path_array_parameter, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { local_var_response$content } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { @@ -546,11 +546,11 @@ FakeApi <- R6::R6Class( #' @description #' test array parameter in path #' - #' @param path_array dummy path parameter + #' @param path_array_parameter dummy path parameter #' @param ... Other optional arguments #' @return API response (void) with additional information such as HTTP status code, headers #' @export - fake_path_array_with_http_info = function(path_array, ...) { + fake_path_array_with_http_info = function(path_array_parameter, ...) { args <- list(...) query_params <- list() header_params <- c() @@ -560,17 +560,17 @@ FakeApi <- R6::R6Class( oauth_scopes <- NULL is_oauth <- FALSE - if (missing(`path_array`)) { - rlang::abort(message = "Missing required parameter `path_array`.", + if (missing(`path_array_parameter`)) { + rlang::abort(message = "Missing required parameter `path_array_parameter`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, - reason = "Missing required parameter `path_array`.")) + reason = "Missing required parameter `path_array_parameter`.")) } local_var_url_path <- "/fake/path_array/{path_array}/testing" - if (!missing(`path_array`)) { - local_var_url_path <- gsub("\\{path_array\\}", paste(URLencode(as.character(`path_array`), reserved = TRUE), collapse= ",", sep=""), local_var_url_path) + if (!missing(`path_array_parameter`)) { + local_var_url_path <- gsub("\\{path_array\\}", paste(URLencode(as.character(`path_array_parameter`), reserved = TRUE), collapse= ",", sep=""), local_var_url_path) } diff --git a/samples/client/petstore/R-httr2/R/just_model.R b/samples/client/petstore/R-httr2/R/just_model.R new file mode 100644 index 00000000000..163e3721638 --- /dev/null +++ b/samples/client/petstore/R-httr2/R/just_model.R @@ -0,0 +1,163 @@ +#' Create a new JustModel +#' +#' @description +#' to test the model name mapping +#' +#' @docType class +#' @title JustModel +#' @description JustModel Class +#' @format An \code{R6Class} generator object +#' @field property character [optional] +#' @importFrom R6 R6Class +#' @importFrom jsonlite fromJSON toJSON +#' @export +JustModel <- R6::R6Class( + "JustModel", + public = list( + `property` = NULL, + #' Initialize a new JustModel class. + #' + #' @description + #' Initialize a new JustModel class. + #' + #' @param property property + #' @param ... Other optional arguments. + #' @export + initialize = function(`property` = NULL, ...) { + if (!is.null(`property`)) { + if (!(is.character(`property`) && length(`property`) == 1)) { + stop(paste("Error! Invalid data for `property`. Must be a string:", `property`)) + } + self$`property` <- `property` + } + }, + #' To JSON string + #' + #' @description + #' To JSON String + #' + #' @return JustModel in JSON format + #' @export + toJSON = function() { + JustModelObject <- list() + if (!is.null(self$`property`)) { + JustModelObject[["property"]] <- + self$`property` + } + JustModelObject + }, + #' Deserialize JSON string into an instance of JustModel + #' + #' @description + #' Deserialize JSON string into an instance of JustModel + #' + #' @param input_json the JSON input + #' @return the instance of JustModel + #' @export + fromJSON = function(input_json) { + this_object <- jsonlite::fromJSON(input_json) + if (!is.null(this_object$`property`)) { + self$`property` <- this_object$`property` + } + self + }, + #' To JSON string + #' + #' @description + #' To JSON String + #' + #' @return JustModel in JSON format + #' @export + 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 = ""))) + }, + #' Deserialize JSON string into an instance of JustModel + #' + #' @description + #' Deserialize JSON string into an instance of JustModel + #' + #' @param input_json the JSON input + #' @return the instance of JustModel + #' @export + fromJSONString = function(input_json) { + this_object <- jsonlite::fromJSON(input_json) + self$`property` <- this_object$`property` + self + }, + #' Validate JSON input with respect to JustModel + #' + #' @description + #' Validate JSON input with respect to JustModel and throw an exception if invalid + #' + #' @param input the JSON input + #' @export + validateJSON = function(input) { + input_json <- jsonlite::fromJSON(input) + }, + #' To string (JSON format) + #' + #' @description + #' To string (JSON format) + #' + #' @return String representation of JustModel + #' @export + toString = function() { + self$toJSONString() + }, + #' Return true if the values in all fields are valid. + #' + #' @description + #' Return true if the values in all fields are valid. + #' + #' @return true if the values in all fields are valid. + #' @export + isValid = function() { + TRUE + }, + #' Return a list of invalid fields (if any). + #' + #' @description + #' Return a list of invalid fields (if any). + #' + #' @return A list of invalid fields (if any). + #' @export + getInvalidFields = function() { + invalid_fields <- list() + invalid_fields + }, + #' Print the object + #' + #' @description + #' Print the object + #' + #' @export + print = function() { + print(jsonlite::prettify(self$toJSONString())) + invisible(self) + } + ), + # Lock the class to prevent modifications to the method or field + lock_class = TRUE +) +## Uncomment below to unlock the class to allow modifications of the method or field +# JustModel$unlock() +# +## Below is an example to define the print function +# JustModel$set("public", "print", function(...) { +# print(jsonlite::prettify(self$toJSONString())) +# invisible(self) +# }) +## Uncomment below to lock the class to prevent modifications to the method or field +# JustModel$lock() + diff --git a/samples/client/petstore/R-httr2/README.md b/samples/client/petstore/R-httr2/README.md index e09946a3a05..a64dcb83e2c 100644 --- a/samples/client/petstore/R-httr2/README.md +++ b/samples/client/petstore/R-httr2/README.md @@ -114,6 +114,7 @@ Class | Method | HTTP request | Description - [Date](docs/Date.md) - [Dog](docs/Dog.md) - [FormatTest](docs/FormatTest.md) + - [JustModel](docs/JustModel.md) - [Mammal](docs/Mammal.md) - [ModelApiResponse](docs/ModelApiResponse.md) - [NestedOneOf](docs/NestedOneOf.md) diff --git a/samples/client/petstore/R-httr2/docs/Date.md b/samples/client/petstore/R-httr2/docs/Date.md index ed61f58682c..756d058569c 100644 --- a/samples/client/petstore/R-httr2/docs/Date.md +++ b/samples/client/petstore/R-httr2/docs/Date.md @@ -6,7 +6,7 @@ to test the model name `Date` Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **className** | **character** | | -**percent_description** | **character** | using % in the description | [optional] +**percent** | **character** | using % in the description | [optional] **url_property** | **character** | | diff --git a/samples/client/petstore/R-httr2/docs/FakeApi.md b/samples/client/petstore/R-httr2/docs/FakeApi.md index a6a30c06e09..3bdabfe235c 100644 --- a/samples/client/petstore/R-httr2/docs/FakeApi.md +++ b/samples/client/petstore/R-httr2/docs/FakeApi.md @@ -140,7 +140,7 @@ No authorization required | **200** | successful operation | - | # **fake_path_array** -> fake_path_array(path_array) +> fake_path_array(path_array_parameter) test array parameter in path @@ -153,11 +153,11 @@ library(petstore) # test array parameter in path # # prepare function argument(s) -var_path_array <- c("inner_example") # array[character] | dummy path parameter +var_path_array_parameter <- c("inner_example") # array[character] | dummy path parameter api_instance <- FakeApi$new() result <- tryCatch( - api_instance$fake_path_array(var_path_array), + api_instance$fake_path_array(var_path_array_parameter), ApiException = function(ex) ex ) # In case of error, print the error object @@ -174,7 +174,7 @@ if (!is.null(result$ApiException)) { Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **path_array** | list( **character** )| dummy path parameter | + **path_array_parameter** | list( **character** )| dummy path parameter | ### Return type diff --git a/samples/client/petstore/R-httr2/docs/JustModel.md b/samples/client/petstore/R-httr2/docs/JustModel.md new file mode 100644 index 00000000000..f5420acfe06 --- /dev/null +++ b/samples/client/petstore/R-httr2/docs/JustModel.md @@ -0,0 +1,10 @@ +# petstore::JustModel + +to test the model name mapping + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**property** | **character** | | [optional] + + diff --git a/samples/client/petstore/R-httr2/tests/testthat/test_just_model.R b/samples/client/petstore/R-httr2/tests/testthat/test_just_model.R new file mode 100644 index 00000000000..01a5592d575 --- /dev/null +++ b/samples/client/petstore/R-httr2/tests/testthat/test_just_model.R @@ -0,0 +1,13 @@ +# Automatically generated by openapi-generator (https://openapi-generator.tech) +# Please update as you see appropriate + +context("Test JustModel") + +model_instance <- JustModel$new() + +test_that("property", { + # tests for the property `property` (character) + + # uncomment below to test the property + #expect_equal(model.instance$`property`, "EXPECTED_RESULT") +}) diff --git a/samples/client/petstore/R/.openapi-generator/FILES b/samples/client/petstore/R/.openapi-generator/FILES index 781b048629b..9a7a9f21724 100644 --- a/samples/client/petstore/R/.openapi-generator/FILES +++ b/samples/client/petstore/R/.openapi-generator/FILES @@ -18,6 +18,7 @@ R/category.R R/danish_pig.R R/date.R R/dog.R +R/dummy_model.R R/fake_api.R R/format_test.R R/mammal.R @@ -47,6 +48,7 @@ docs/Category.md docs/DanishPig.md docs/Date.md docs/Dog.md +docs/DummyModel.md docs/FakeApi.md docs/FormatTest.md docs/Mammal.md diff --git a/samples/client/petstore/R/NAMESPACE b/samples/client/petstore/R/NAMESPACE index e392e3ea9bd..afcc404eca7 100644 --- a/samples/client/petstore/R/NAMESPACE +++ b/samples/client/petstore/R/NAMESPACE @@ -24,6 +24,7 @@ export(Category) export(DanishPig) export(Date) export(Dog) +export(DummyModel) export(FormatTest) export(Mammal) export(ModelApiResponse) diff --git a/samples/client/petstore/R/R/dummy_model.R b/samples/client/petstore/R/R/dummy_model.R new file mode 100644 index 00000000000..75c7c5f8a56 --- /dev/null +++ b/samples/client/petstore/R/R/dummy_model.R @@ -0,0 +1,196 @@ +#' Create a new DummyModel +#' +#' @description +#' to test the model name mapping +#' +#' @docType class +#' @title DummyModel +#' @description DummyModel Class +#' @format An \code{R6Class} generator object +#' @field property character [optional] +#' @field _field_list a list of fields list(character) +#' @field additional_properties additional properties list(character) [optional] +#' @importFrom R6 R6Class +#' @importFrom jsonlite fromJSON toJSON +#' @export +DummyModel <- R6::R6Class( + "DummyModel", + public = list( + `property` = NULL, + `_field_list` = c("property"), + `additional_properties` = list(), + #' Initialize a new DummyModel class. + #' + #' @description + #' Initialize a new DummyModel class. + #' + #' @param property property + #' @param additional_properties additional properties (optional) + #' @param ... Other optional arguments. + #' @export + initialize = function(`property` = NULL, additional_properties = NULL, ...) { + if (!is.null(`property`)) { + if (!(is.character(`property`) && length(`property`) == 1)) { + stop(paste("Error! Invalid data for `property`. Must be a string:", `property`)) + } + self$`property` <- `property` + } + if (!is.null(additional_properties)) { + for (key in names(additional_properties)) { + self$additional_properties[[key]] <- additional_properties[[key]] + } + } + }, + #' To JSON string + #' + #' @description + #' To JSON String + #' + #' @return DummyModel in JSON format + #' @export + toJSON = function() { + DummyModelObject <- list() + if (!is.null(self$`property`)) { + DummyModelObject[["property"]] <- + self$`property` + } + for (key in names(self$additional_properties)) { + DummyModelObject[[key]] <- self$additional_properties[[key]] + } + + DummyModelObject + }, + #' Deserialize JSON string into an instance of DummyModel + #' + #' @description + #' Deserialize JSON string into an instance of DummyModel + #' + #' @param input_json the JSON input + #' @return the instance of DummyModel + #' @export + fromJSON = function(input_json) { + this_object <- jsonlite::fromJSON(input_json) + if (!is.null(this_object$`property`)) { + self$`property` <- this_object$`property` + } + # process additional properties/fields in the payload + for (key in names(this_object)) { + if (!(key %in% self$`_field_list`)) { # json key not in list of fields + self$additional_properties[[key]] <- this_object[[key]] + } + } + + self + }, + #' To JSON string + #' + #' @description + #' To JSON String + #' + #' @return DummyModel in JSON format + #' @export + 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) + for (key in names(self$additional_properties)) { + json_obj[[key]] <- self$additional_properties[[key]] + } + json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + }, + #' Deserialize JSON string into an instance of DummyModel + #' + #' @description + #' Deserialize JSON string into an instance of DummyModel + #' + #' @param input_json the JSON input + #' @return the instance of DummyModel + #' @export + fromJSONString = function(input_json) { + this_object <- jsonlite::fromJSON(input_json) + self$`property` <- this_object$`property` + # process additional properties/fields in the payload + for (key in names(this_object)) { + if (!(key %in% self$`_field_list`)) { # json key not in list of fields + self$additional_properties[[key]] <- this_object[[key]] + } + } + + self + }, + #' Validate JSON input with respect to DummyModel + #' + #' @description + #' Validate JSON input with respect to DummyModel and throw an exception if invalid + #' + #' @param input the JSON input + #' @export + validateJSON = function(input) { + input_json <- jsonlite::fromJSON(input) + }, + #' To string (JSON format) + #' + #' @description + #' To string (JSON format) + #' + #' @return String representation of DummyModel + #' @export + toString = function() { + self$toJSONString() + }, + #' Return true if the values in all fields are valid. + #' + #' @description + #' Return true if the values in all fields are valid. + #' + #' @return true if the values in all fields are valid. + #' @export + isValid = function() { + TRUE + }, + #' Return a list of invalid fields (if any). + #' + #' @description + #' Return a list of invalid fields (if any). + #' + #' @return A list of invalid fields (if any). + #' @export + getInvalidFields = function() { + invalid_fields <- list() + invalid_fields + }, + #' Print the object + #' + #' @description + #' Print the object + #' + #' @export + print = function() { + print(jsonlite::prettify(self$toJSONString())) + invisible(self) + } + ), + # Lock the class to prevent modifications to the method or field + lock_class = TRUE +) +## Uncomment below to unlock the class to allow modifications of the method or field +# DummyModel$unlock() +# +## Below is an example to define the print function +# DummyModel$set("public", "print", function(...) { +# print(jsonlite::prettify(self$toJSONString())) +# invisible(self) +# }) +## Uncomment below to lock the class to prevent modifications to the method or field +# DummyModel$lock() + diff --git a/samples/client/petstore/R/README.md b/samples/client/petstore/R/README.md index 5975b55d476..95f7e3e8650 100644 --- a/samples/client/petstore/R/README.md +++ b/samples/client/petstore/R/README.md @@ -113,6 +113,7 @@ Class | Method | HTTP request | Description - [DanishPig](docs/DanishPig.md) - [Date](docs/Date.md) - [Dog](docs/Dog.md) + - [DummyModel](docs/DummyModel.md) - [FormatTest](docs/FormatTest.md) - [Mammal](docs/Mammal.md) - [ModelApiResponse](docs/ModelApiResponse.md) diff --git a/samples/client/petstore/R/docs/DummyModel.md b/samples/client/petstore/R/docs/DummyModel.md new file mode 100644 index 00000000000..fdf3ba12203 --- /dev/null +++ b/samples/client/petstore/R/docs/DummyModel.md @@ -0,0 +1,10 @@ +# petstore::DummyModel + +to test the model name mapping + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**property** | **character** | | [optional] + + diff --git a/samples/client/petstore/R/tests/testthat/test_dummy_model.R b/samples/client/petstore/R/tests/testthat/test_dummy_model.R new file mode 100644 index 00000000000..b4f8e11b7f5 --- /dev/null +++ b/samples/client/petstore/R/tests/testthat/test_dummy_model.R @@ -0,0 +1,13 @@ +# Automatically generated by openapi-generator (https://openapi-generator.tech) +# Please update as you see appropriate + +context("Test DummyModel") + +model_instance <- DummyModel$new() + +test_that("property", { + # tests for the property `property` (character) + + # uncomment below to test the property + #expect_equal(model.instance$`property`, "EXPECTED_RESULT") +})