diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index 2d1bf6affd1..1df5a69287c 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -253,6 +253,100 @@ } {{/requiredParams}} + {{#allParams}} + {{#maxLength}} + if (nchar(`{{paramName}}`) > {{maxLength}}) { + {{#useDefaultExceptionHandling}} + stop("Invalid length for `{{paramName}}` when calling {{classname}}${{operationId}}, must be smaller than or equal to {{maxLength}}.") + {{/useDefaultExceptionHandling}} + {{#useRlangExceptionHandling}} + rlang::abort(message = "Invalid length for `{{paramName}}` when calling {{classname}}${{operationId}}, must be smaller than or equal to {{maxLength}}.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "Invalid length for ${{paramName}} when calling {{classname}}.{{operationId}}, must be smaller than or equal to {{maxLength}}.")) + {{/useRlangExceptionHandling}} + } + {{/maxLength}} + {{#minLength}} + if (nchar(`{{paramName}}`) < {{minLength}}) { + {{#useDefaultExceptionHandling}} + stop("Invalid length for `{{paramName}}` when calling {{classname}}${{operationId}}, must be bigger than or equal to {{minLength}}.") + {{/useDefaultExceptionHandling}} + {{#useRlangExceptionHandling}} + rlang::abort(message = "Invalid length for `{{paramName}}` when calling {{classname}}${{operationId}}, must be bigger than or equal to {{minLength}}.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "Invalid length for `{{paramName}}` when calling {{classname}}${{operationId}}, must be bigger than or equal to {{minLength}}.")) + {{/useRlangExceptionHandling}} + } + {{/minLength}} + {{#maximum}} + if (`{{paramName}}` >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}) { + {{#useDefaultExceptionHandling}} + stop("Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}, must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{maximum}}.") + {{/useDefaultExceptionHandling}} + {{#useRlangExceptionHandling}} + rlang::abort(message = "Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}, must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{maximum}}.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}, must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{maximum}}.")) + {{/useRlangExceptionHandling}} + } + {{/maximum}} + {{#minimum}} + if (`{{paramName}}` <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}) { + {{#useDefaultExceptionHandling}} + stop("Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}, must be bigger than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{minimum}}.") + {{/useDefaultExceptionHandling}} + {{#useRlangExceptionHandling}} + rlang::abort(message = "Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}, must be bigger than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{minimum}}.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}, must be bigger than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{minimum}}.")) + {{/useRlangExceptionHandling}} + } + {{/minimum}} + {{#pattern}} + if (!str_detect(`{{paramName}}`, "{{{pattern}}}")) { + {{#useDefaultExceptionHandling}} + stop("Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}, must conform to the pattern {{{pattern}}}.") + {{/useDefaultExceptionHandling}} + {{#useRlangExceptionHandling}} + rlang::abort(message = "Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}, must conform to the pattern {{{pattern}}}.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}, must conform to the pattern {{{pattern}}}.")) + {{/useRlangExceptionHandling}} + } + {{/pattern}} + {{#maxItems}} + if (length(`{{paramName}}`) > {{maxItems}}) { + {{#useDefaultExceptionHandling}} + stop("Invalid length for `{{paramName}}` when calling {{classname}}${{operationId}}, number of items must be less than or equal to {{maxItems}}.") + {{/useDefaultExceptionHandling}} + {{#useRlangExceptionHandling}} + rlang::abort(message = "Invalid length for `{{paramName}}` when calling {{classname}}${{operationId}}, number of items must be less than or equal to {{maxItems}}.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "Invalid length for `{{paramName}}` when calling {{classname}}${{operationId}}, number of items must be less than or equal to {{maxItems}}.")) + {{/useRlangExceptionHandling}} + } + {{/maxItems}} + {{#minItems}} + if (length(`{{paramName}}`) < {{minItems}}) { + {{#useDefaultExceptionHandling}} + stop("Invalid length for `{{paramName}}` when calling {{classname}}${{operationId}}, number of items must be greater than or equal to {{minItems}}.") + {{/useDefaultExceptionHandling}} + {{#useRlangExceptionHandling}} + rlang::abort(message = "Invalid length for `{{paramName}}` when calling {{classname}}${{operationId}}, number of items must be greater than or equal to {{minItems}}.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "Invalid length for `{{paramName}}` when calling {{classname}}${{operationId}}, number of items must be greater than or equal to {{minItems}}.")) + {{/useRlangExceptionHandling}} + } + {{/minItems}} + + {{/allParams}} {{#headerParams}} header_params["{{baseName}}"] <- `{{paramName}}` diff --git a/samples/client/petstore/R-httr2/R/fake_api.R b/samples/client/petstore/R-httr2/R/fake_api.R index b5d560f7484..29316cc62bb 100644 --- a/samples/client/petstore/R-httr2/R/fake_api.R +++ b/samples/client/petstore/R-httr2/R/fake_api.R @@ -136,6 +136,8 @@ FakeApi <- R6::R6Class( reason = "Missing required parameter `dummy`.")) } + + header_params["dummy"] <- `dummy` header_params["data_file"] <- `var_data_file` diff --git a/samples/client/petstore/R-httr2/R/pet_api.R b/samples/client/petstore/R-httr2/R/pet_api.R index 6b2bd6fe542..1cca443a90e 100644 --- a/samples/client/petstore/R-httr2/R/pet_api.R +++ b/samples/client/petstore/R-httr2/R/pet_api.R @@ -640,6 +640,7 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `pet`.")) } + if (!missing(`pet`)) { local_var_body <- `pet`$toJSONString() } else { @@ -762,6 +763,8 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `pet_id`.")) } + + header_params["api_key"] <- `api_key` local_var_url_path <- "/pet/{petId}" @@ -867,6 +870,7 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `status`.")) } + query_params["status"] <- `status` local_var_url_path <- "/pet/findByStatus" @@ -981,6 +985,7 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `tags`.")) } + query_params["tags"] <- `tags` local_var_url_path <- "/pet/findByTags" @@ -1095,6 +1100,7 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `pet_id`.")) } + local_var_url_path <- "/pet/{petId}" if (!missing(`pet_id`)) { local_var_url_path <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) @@ -1217,6 +1223,7 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `pet_id`.")) } + local_var_url_path <- "/pet/{petId}?streaming" if (!missing(`pet_id`)) { local_var_url_path <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) @@ -1344,6 +1351,7 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `header_test_int`.")) } + header_params["header_test_int"] <- `header_test_int` local_var_url_path <- "/pet_header_test" @@ -1463,6 +1471,7 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `pet`.")) } + if (!missing(`pet`)) { local_var_body <- `pet`$toJSONString() } else { @@ -1583,6 +1592,9 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `pet_id`.")) } + + + form_params["name"] <- `name` form_params["status"] <- `status` local_var_url_path <- "/pet/{petId}" @@ -1692,6 +1704,9 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `pet_id`.")) } + + + form_params["additionalMetadata"] <- `additional_metadata` file_params["file"] <- curl::form_file(`file`) local_var_url_path <- "/pet/{petId}/uploadImage" diff --git a/samples/client/petstore/R-httr2/R/store_api.R b/samples/client/petstore/R-httr2/R/store_api.R index f244be66fb3..42d301a3b2d 100644 --- a/samples/client/petstore/R-httr2/R/store_api.R +++ b/samples/client/petstore/R-httr2/R/store_api.R @@ -284,6 +284,7 @@ StoreApi <- R6::R6Class( reason = "Missing required parameter `order_id`.")) } + local_var_url_path <- "/store/order/{orderId}" if (!missing(`order_id`)) { local_var_url_path <- gsub(paste0("\\{", "orderId", "\\}"), URLencode(as.character(`order_id`), reserved = TRUE), local_var_url_path) @@ -486,6 +487,19 @@ StoreApi <- R6::R6Class( reason = "Missing required parameter `order_id`.")) } + if (`order_id` > 5) { + rlang::abort(message = "Invalid value for `order_id` when calling StoreApi$get_order_by_id, must be smaller than or equal to 5.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "Invalid value for `order_id` when calling StoreApi$get_order_by_id, must be smaller than or equal to 5.")) + } + if (`order_id` < 1) { + rlang::abort(message = "Invalid value for `order_id` when calling StoreApi$get_order_by_id, must be bigger than or equal to 1.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "Invalid value for `order_id` when calling StoreApi$get_order_by_id, must be bigger than or equal to 1.")) + } + local_var_url_path <- "/store/order/{orderId}" if (!missing(`order_id`)) { local_var_url_path <- gsub(paste0("\\{", "orderId", "\\}"), URLencode(as.character(`order_id`), reserved = TRUE), local_var_url_path) @@ -598,6 +612,7 @@ StoreApi <- R6::R6Class( reason = "Missing required parameter `order`.")) } + if (!missing(`order`)) { local_var_body <- `order`$toJSONString() } else { diff --git a/samples/client/petstore/R-httr2/R/user_api.R b/samples/client/petstore/R-httr2/R/user_api.R index 9d69e9009ce..8a4bf8a28f8 100644 --- a/samples/client/petstore/R-httr2/R/user_api.R +++ b/samples/client/petstore/R-httr2/R/user_api.R @@ -470,6 +470,7 @@ UserApi <- R6::R6Class( reason = "Missing required parameter `user`.")) } + if (!missing(`user`)) { local_var_body <- `user`$toJSONString() } else { @@ -573,6 +574,7 @@ UserApi <- R6::R6Class( reason = "Missing required parameter `user`.")) } + if (!missing(`user`)) { body.items <- paste(unlist(lapply(`user`, function(param) { param$toJSONString() @@ -679,6 +681,7 @@ UserApi <- R6::R6Class( reason = "Missing required parameter `user`.")) } + if (!missing(`user`)) { body.items <- paste(unlist(lapply(`user`, function(param) { param$toJSONString() @@ -785,6 +788,7 @@ UserApi <- R6::R6Class( reason = "Missing required parameter `username`.")) } + local_var_url_path <- "/user/{username}" if (!missing(`username`)) { local_var_url_path <- gsub(paste0("\\{", "username", "\\}"), URLencode(as.character(`username`), reserved = TRUE), local_var_url_path) @@ -888,6 +892,7 @@ UserApi <- R6::R6Class( reason = "Missing required parameter `username`.")) } + local_var_url_path <- "/user/{username}" if (!missing(`username`)) { local_var_url_path <- gsub(paste0("\\{", "username", "\\}"), URLencode(as.character(`username`), reserved = TRUE), local_var_url_path) @@ -1009,6 +1014,14 @@ UserApi <- R6::R6Class( reason = "Missing required parameter `password`.")) } + if (!str_detect(`username`, "/^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$/")) { + rlang::abort(message = "Invalid value for `username` when calling UserApi$login_user, must conform to the pattern /^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$/.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "Invalid value for `username` when calling UserApi$login_user, must conform to the pattern /^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$/.")) + } + + query_params["username"] <- `username` query_params["password"] <- `password` @@ -1216,6 +1229,8 @@ UserApi <- R6::R6Class( reason = "Missing required parameter `user`.")) } + + if (!missing(`user`)) { local_var_body <- `user`$toJSONString() } else { diff --git a/samples/client/petstore/R/R/fake_api.R b/samples/client/petstore/R/R/fake_api.R index 52b3987f108..e35d774b06a 100644 --- a/samples/client/petstore/R/R/fake_api.R +++ b/samples/client/petstore/R/R/fake_api.R @@ -136,6 +136,8 @@ FakeApi <- R6::R6Class( reason = "Missing required parameter `dummy`.")) } + + header_params["dummy"] <- `dummy` header_params["data_file"] <- `var_data_file` diff --git a/samples/client/petstore/R/R/pet_api.R b/samples/client/petstore/R/R/pet_api.R index ecb93b4fe67..3743f84c2d9 100644 --- a/samples/client/petstore/R/R/pet_api.R +++ b/samples/client/petstore/R/R/pet_api.R @@ -640,6 +640,7 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `pet`.")) } + if (!missing(`pet`)) { local_var_body <- `pet`$toJSONString() } else { @@ -762,6 +763,8 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `pet_id`.")) } + + header_params["api_key"] <- `api_key` local_var_url_path <- "/pet/{petId}" @@ -867,6 +870,7 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `status`.")) } + query_params["status"] <- `status` local_var_url_path <- "/pet/findByStatus" @@ -981,6 +985,7 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `tags`.")) } + query_params["tags"] <- `tags` local_var_url_path <- "/pet/findByTags" @@ -1095,6 +1100,7 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `pet_id`.")) } + local_var_url_path <- "/pet/{petId}" if (!missing(`pet_id`)) { local_var_url_path <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) @@ -1217,6 +1223,7 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `pet_id`.")) } + local_var_url_path <- "/pet/{petId}?streaming" if (!missing(`pet_id`)) { local_var_url_path <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) @@ -1344,6 +1351,7 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `header_test_int`.")) } + header_params["header_test_int"] <- `header_test_int` local_var_url_path <- "/pet_header_test" @@ -1463,6 +1471,7 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `pet`.")) } + if (!missing(`pet`)) { local_var_body <- `pet`$toJSONString() } else { @@ -1583,6 +1592,9 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `pet_id`.")) } + + + form_params["name"] <- `name` form_params["status"] <- `status` local_var_url_path <- "/pet/{petId}" @@ -1692,6 +1704,9 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `pet_id`.")) } + + + form_params["additionalMetadata"] <- `additional_metadata` file_params["file"] <- httr::upload_file(`file`) local_var_url_path <- "/pet/{petId}/uploadImage" diff --git a/samples/client/petstore/R/R/store_api.R b/samples/client/petstore/R/R/store_api.R index 101a4118b22..a93dd2a5062 100644 --- a/samples/client/petstore/R/R/store_api.R +++ b/samples/client/petstore/R/R/store_api.R @@ -284,6 +284,7 @@ StoreApi <- R6::R6Class( reason = "Missing required parameter `order_id`.")) } + local_var_url_path <- "/store/order/{orderId}" if (!missing(`order_id`)) { local_var_url_path <- gsub(paste0("\\{", "orderId", "\\}"), URLencode(as.character(`order_id`), reserved = TRUE), local_var_url_path) @@ -486,6 +487,19 @@ StoreApi <- R6::R6Class( reason = "Missing required parameter `order_id`.")) } + if (`order_id` > 5) { + rlang::abort(message = "Invalid value for `order_id` when calling StoreApi$GetOrderById, must be smaller than or equal to 5.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "Invalid value for `order_id` when calling StoreApi$GetOrderById, must be smaller than or equal to 5.")) + } + if (`order_id` < 1) { + rlang::abort(message = "Invalid value for `order_id` when calling StoreApi$GetOrderById, must be bigger than or equal to 1.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "Invalid value for `order_id` when calling StoreApi$GetOrderById, must be bigger than or equal to 1.")) + } + local_var_url_path <- "/store/order/{orderId}" if (!missing(`order_id`)) { local_var_url_path <- gsub(paste0("\\{", "orderId", "\\}"), URLencode(as.character(`order_id`), reserved = TRUE), local_var_url_path) @@ -598,6 +612,7 @@ StoreApi <- R6::R6Class( reason = "Missing required parameter `order`.")) } + if (!missing(`order`)) { local_var_body <- `order`$toJSONString() } else { diff --git a/samples/client/petstore/R/R/user_api.R b/samples/client/petstore/R/R/user_api.R index 3dc9b914ff6..ce6b4444d4c 100644 --- a/samples/client/petstore/R/R/user_api.R +++ b/samples/client/petstore/R/R/user_api.R @@ -470,6 +470,7 @@ UserApi <- R6::R6Class( reason = "Missing required parameter `user`.")) } + if (!missing(`user`)) { local_var_body <- `user`$toJSONString() } else { @@ -573,6 +574,7 @@ UserApi <- R6::R6Class( reason = "Missing required parameter `user`.")) } + if (!missing(`user`)) { body.items <- paste(unlist(lapply(`user`, function(param) { param$toJSONString() @@ -679,6 +681,7 @@ UserApi <- R6::R6Class( reason = "Missing required parameter `user`.")) } + if (!missing(`user`)) { body.items <- paste(unlist(lapply(`user`, function(param) { param$toJSONString() @@ -785,6 +788,7 @@ UserApi <- R6::R6Class( reason = "Missing required parameter `username`.")) } + local_var_url_path <- "/user/{username}" if (!missing(`username`)) { local_var_url_path <- gsub(paste0("\\{", "username", "\\}"), URLencode(as.character(`username`), reserved = TRUE), local_var_url_path) @@ -888,6 +892,7 @@ UserApi <- R6::R6Class( reason = "Missing required parameter `username`.")) } + local_var_url_path <- "/user/{username}" if (!missing(`username`)) { local_var_url_path <- gsub(paste0("\\{", "username", "\\}"), URLencode(as.character(`username`), reserved = TRUE), local_var_url_path) @@ -1009,6 +1014,14 @@ UserApi <- R6::R6Class( reason = "Missing required parameter `password`.")) } + if (!str_detect(`username`, "/^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$/")) { + rlang::abort(message = "Invalid value for `username` when calling UserApi$LoginUser, must conform to the pattern /^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$/.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "Invalid value for `username` when calling UserApi$LoginUser, must conform to the pattern /^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$/.")) + } + + query_params["username"] <- `username` query_params["password"] <- `password` @@ -1216,6 +1229,8 @@ UserApi <- R6::R6Class( reason = "Missing required parameter `user`.")) } + + if (!missing(`user`)) { local_var_body <- `user`$toJSONString() } else {