From 517816d72b200494236d17785e133cba94346263 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 17 Sep 2022 22:35:00 +0800 Subject: [PATCH] [R] Add array support to path parameters (#13450) * add array support to path parameters (r client) * update samples --- .../src/main/resources/r/api.mustache | 9 +- .../src/test/resources/3_0/r/petstore.yaml | 19 +++ .../petstore/R-httr2-wrapper/R/fake_api.R | 144 ++++++++++++++++++ .../petstore/R-httr2-wrapper/R/pet_api.R | 10 +- .../petstore/R-httr2-wrapper/R/store_api.R | 4 +- .../petstore/R-httr2-wrapper/R/user_api.R | 6 +- .../client/petstore/R-httr2-wrapper/README.md | 1 + .../petstore/R-httr2-wrapper/docs/FakeApi.md | 56 +++++++ .../tests/testthat/test_petstore.R | 8 + samples/client/petstore/R-httr2/R/fake_api.R | 144 ++++++++++++++++++ samples/client/petstore/R-httr2/R/pet_api.R | 10 +- samples/client/petstore/R-httr2/R/store_api.R | 4 +- samples/client/petstore/R-httr2/R/user_api.R | 6 +- samples/client/petstore/R-httr2/README.md | 1 + .../client/petstore/R-httr2/docs/FakeApi.md | 56 +++++++ samples/client/petstore/R/R/fake_api.R | 144 ++++++++++++++++++ samples/client/petstore/R/R/pet_api.R | 10 +- samples/client/petstore/R/R/store_api.R | 4 +- samples/client/petstore/R/R/user_api.R | 6 +- samples/client/petstore/R/README.md | 1 + samples/client/petstore/R/docs/FakeApi.md | 56 +++++++ 21 files changed, 668 insertions(+), 31 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index 155e9c3f67f..c9cd5b04b65 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -542,7 +542,14 @@ {{#hasPathParams}} {{#pathParams}} if (!missing(`{{paramName}}`)) { - local_var_url_path <- gsub(paste0("\\{", "{{baseName}}", "\\}"), URLencode(as.character(`{{paramName}}`), reserved = TRUE), local_var_url_path) + {{=< >=}} + <#isArray> + local_var_url_path <- gsub("\\{\\}", paste(URLencode(as.character(``), reserved = TRUE), collapse= ",", sep=""), local_var_url_path) + + <^isArray> + local_var_url_path <- gsub("\\{\\}", URLencode(as.character(``), reserved = TRUE), local_var_url_path) + + <={{ }}=> } {{/pathParams}} 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 755d52e9cec..98b3b26537d 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 @@ -629,6 +629,25 @@ paths: description: User not found security: - api_key: [] + /fake/path_array/{path_array}/testing: + get: + tags: + - fake + summary: test array parameter in path + description: '' + operationId: fake_path_array + parameters: + - name: path_array + in: path + description: dummy path parameter + required: true + schema: + type: array + items: + type: string + responses: + '200': + description: successful operation /fake/regular_expression: get: tags: 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 ded25606ad3..8b271a14551 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/fake_api.R +++ b/samples/client/petstore/R-httr2-wrapper/R/fake_api.R @@ -32,6 +32,23 @@ #' } #' } #' +#' \strong{ fake_path_array } \emph{ test array parameter in path } +#' +#' +#' \itemize{ +#' \item \emph{ @param } path_array list( character ) +#' +#' \item On encountering errors, an error of subclass ApiException will be thrown. +#' +#' \item status code : 200 | successful operation +#' +#' +#' \item response headers : +#' +#' \tabular{ll}{ +#' } +#' } +#' #' \strong{ fake_regular_expression } \emph{ test regular expression to ensure no exception } #' #' @@ -106,6 +123,31 @@ #' #' #' +#' #################### fake_path_array #################### +#' +#' library(petstore) +#' var_path_array <- ["path_array_example"] # array[character] | dummy path parameter +#' +#' #test array parameter in path +#' api_instance <- petstore_api$new() +#' +#' result <- tryCatch( +#' +#' api_instance$fake_api$fake_path_array(var_path_array), +#' ApiException = function(ex) ex +#' ) +#' # In case of error, print the error object +#' if (!is.null(result$ApiException)) { +#' print("Exception occurs when calling `fake_path_array`:") +#' dput(result$ApiException$toString()) +#' +#' # error object +#' dput(result$ApiException$error_object$toJSONString()) +#' +#' }#' +#' # This endpoint doesn't return data +#' +#' #' #################### fake_regular_expression #################### #' #' library(petstore) @@ -300,6 +342,108 @@ FakeApi <- R6::R6Class( ApiException = ApiException$new(http_response = local_var_resp)) } }, + #' test array parameter in path + #' + #' @description + #' test array parameter in path + #' + #' @param path_array 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, ...) + 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) { + local_var_response + } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { + local_var_response + } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { + local_var_response + } + }, + #' test array parameter in path + #' + #' @description + #' test array parameter in path + #' + #' @param path_array 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, ...) { + args <- list(...) + query_params <- list() + header_params <- c() + form_params <- list() + file_params <- list() + local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE + + if (missing(`path_array`)) { + rlang::abort(message = "Missing required parameter `path_array`.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "Missing required parameter `path_array`.")) + } + + + 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) + } + + + # The Accept request HTTP header + local_var_accepts <- list() + + # The Content-Type representation header + local_var_content_types <- list() + + local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path), + method = "GET", + query_params = query_params, + header_params = header_params, + form_params = form_params, + file_params = file_params, + accepts = local_var_accepts, + content_types = local_var_content_types, + body = local_var_body, + is_oauth = is_oauth, + oauth_scopes = oauth_scopes, + ...) + + if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { + local_var_resp$content <- NULL + local_var_resp + } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + local_var_error_msg <- local_var_resp$response + if (local_var_error_msg == "") { + local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") + } + rlang::abort(message = local_var_error_msg, + .subclass = "ApiException", + ApiException = ApiException$new(http_response = local_var_resp)) + } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { + local_var_error_msg <- local_var_resp$response + if (local_var_error_msg == "") { + local_var_error_msg <- "Api client exception encountered." + } + rlang::abort(message = local_var_error_msg, + .subclass = "ApiException", + ApiException = ApiException$new(http_response = local_var_resp)) + } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { + local_var_error_msg <- local_var_resp$response + if (local_var_error_msg == "") { + local_var_error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, + .subclass = "ApiException", + ApiException = ApiException$new(http_response = local_var_resp)) + } + }, #' test regular expression to ensure no exception #' #' @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 9308019bb17..d334f2a4e42 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/pet_api.R +++ b/samples/client/petstore/R-httr2-wrapper/R/pet_api.R @@ -836,7 +836,7 @@ PetApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{petId\\}", URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) } # OAuth-related settings @@ -1187,7 +1187,7 @@ PetApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{petId\\}", URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) } # Bearer token @@ -1314,7 +1314,7 @@ PetApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{petId\\}", URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) } # API key authentication @@ -1698,7 +1698,7 @@ PetApi <- R6::R6Class( form_params["status"] <- `status` 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) + local_var_url_path <- gsub("\\{petId\\}", URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) } @@ -1810,7 +1810,7 @@ PetApi <- R6::R6Class( file_params["file"] <- curl::form_file(`file`) local_var_url_path <- "/pet/{petId}/uploadImage" if (!missing(`pet_id`)) { - local_var_url_path <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) + local_var_url_path <- gsub("\\{petId\\}", URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) } # OAuth-related settings 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 679b1581ba2..568bb1d2f4d 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/store_api.R +++ b/samples/client/petstore/R-httr2-wrapper/R/store_api.R @@ -314,7 +314,7 @@ StoreApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{orderId\\}", URLencode(as.character(`order_id`), reserved = TRUE), local_var_url_path) } @@ -537,7 +537,7 @@ StoreApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{orderId\\}", URLencode(as.character(`order_id`), reserved = TRUE), local_var_url_path) } 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 55083d2ab24..db3a8c67082 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/user_api.R +++ b/samples/client/petstore/R-httr2-wrapper/R/user_api.R @@ -832,7 +832,7 @@ UserApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{username\\}", URLencode(as.character(`username`), reserved = TRUE), local_var_url_path) } # API key authentication @@ -940,7 +940,7 @@ UserApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{username\\}", URLencode(as.character(`username`), reserved = TRUE), local_var_url_path) } @@ -1296,7 +1296,7 @@ UserApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{username\\}", URLencode(as.character(`username`), reserved = TRUE), local_var_url_path) } # API key authentication diff --git a/samples/client/petstore/R-httr2-wrapper/README.md b/samples/client/petstore/R-httr2-wrapper/README.md index ba69157a6c7..8a8c1134e37 100644 --- a/samples/client/petstore/R-httr2-wrapper/README.md +++ b/samples/client/petstore/R-httr2-wrapper/README.md @@ -62,6 +62,7 @@ All URIs are relative to *http://petstore.swagger.io/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- *FakeApi* | [**fake_data_file**](docs/FakeApi.md#fake_data_file) | **GET** /fake/data_file | test data_file to ensure it's escaped correctly +*FakeApi* | [**fake_path_array**](docs/FakeApi.md#fake_path_array) | **GET** /fake/path_array/{path_array}/testing | test array parameter in path *FakeApi* | [**fake_regular_expression**](docs/FakeApi.md#fake_regular_expression) | **GET** /fake/regular_expression | test regular expression to ensure no exception *FakeApi* | [**fake_set_query**](docs/FakeApi.md#fake_set_query) | **GET** /fake/set_query_parameter | test set query parameter *PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **POST** /pet | Add a new pet to the store diff --git a/samples/client/petstore/R-httr2-wrapper/docs/FakeApi.md b/samples/client/petstore/R-httr2-wrapper/docs/FakeApi.md index a5a5cae74c1..8ffcd5a9893 100644 --- a/samples/client/petstore/R-httr2-wrapper/docs/FakeApi.md +++ b/samples/client/petstore/R-httr2-wrapper/docs/FakeApi.md @@ -5,6 +5,7 @@ All URIs are relative to *http://petstore.swagger.io/v2* Method | HTTP request | Description ------------- | ------------- | ------------- [**fake_data_file**](FakeApi.md#fake_data_file) | **GET** /fake/data_file | test data_file to ensure it's escaped correctly +[**fake_path_array**](FakeApi.md#fake_path_array) | **GET** /fake/path_array/{path_array}/testing | test array parameter in path [**fake_regular_expression**](FakeApi.md#fake_regular_expression) | **GET** /fake/regular_expression | test regular expression to ensure no exception [**fake_set_query**](FakeApi.md#fake_set_query) | **GET** /fake/set_query_parameter | test set query parameter @@ -72,6 +73,61 @@ No authorization required |-------------|-------------|------------------| | **200** | successful operation | - | +# **fake_path_array** +> fake_path_array(path_array) + +test array parameter in path + + + +### Example +```R +library(petstore) + +# test array parameter in path +# +# prepare function argument(s) +var_path_array <- list("inner_example") # array[character] | dummy path parameter + +api_instance <- petstore_api$new() +result <- tryCatch( + api_instance$fake_api$fake_path_array(var_path_array), + ApiException = function(ex) ex + ) +# In case of error, print the error object +if (!is.null(result$ApiException)) { + print("Exception occurs when calling `fake_path_array`:") + dput(result$ApiException$toString()) + # error object + dput(result$ApiException$error_object$toJSONString()) +} +# This endpoint doesn't return data +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **path_array** | list( **character** )| dummy path parameter | + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: Not defined + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + # **fake_regular_expression** > fake_regular_expression(reg_exp_test) 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 350f90a73ab..84ee9a2a682 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 @@ -234,6 +234,14 @@ test_that("GetPetById with data_file", { expect_equal(response$name, "name_test") }) +test_that("array test in path parameters", { + fake_api <- FakeApi$new() + # array input for path parameter + #array_dummy <- list(1, 2, 2, 3) + array_dummy <- list("hello world", "1&2") + expect_error(fake_api$fake_path_array(array_dummy), "") +}) + test_that("set validation test", { fake_api <- FakeApi$new() # array input invalid (not unique) diff --git a/samples/client/petstore/R-httr2/R/fake_api.R b/samples/client/petstore/R-httr2/R/fake_api.R index 013faaaec2b..5826b38abda 100644 --- a/samples/client/petstore/R-httr2/R/fake_api.R +++ b/samples/client/petstore/R-httr2/R/fake_api.R @@ -32,6 +32,23 @@ #' } #' } #' +#' \strong{ fake_path_array } \emph{ test array parameter in path } +#' +#' +#' \itemize{ +#' \item \emph{ @param } path_array list( character ) +#' +#' \item On encountering errors, an error of subclass ApiException will be thrown. +#' +#' \item status code : 200 | successful operation +#' +#' +#' \item response headers : +#' +#' \tabular{ll}{ +#' } +#' } +#' #' \strong{ fake_regular_expression } \emph{ test regular expression to ensure no exception } #' #' @@ -106,6 +123,31 @@ #' #' #' +#' #################### fake_path_array #################### +#' +#' library(petstore) +#' var_path_array <- ["path_array_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), +#' ApiException = function(ex) ex +#' ) +#' # In case of error, print the error object +#' if (!is.null(result$ApiException)) { +#' print("Exception occurs when calling `fake_path_array`:") +#' dput(result$ApiException$toString()) +#' +#' # error object +#' dput(result$ApiException$error_object$toJSONString()) +#' +#' }#' +#' # This endpoint doesn't return data +#' +#' #' #################### fake_regular_expression #################### #' #' library(petstore) @@ -300,6 +342,108 @@ FakeApi <- R6::R6Class( ApiException = ApiException$new(http_response = local_var_resp)) } }, + #' test array parameter in path + #' + #' @description + #' test array parameter in path + #' + #' @param path_array 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, ...) + 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) { + local_var_response + } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { + local_var_response + } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { + local_var_response + } + }, + #' test array parameter in path + #' + #' @description + #' test array parameter in path + #' + #' @param path_array 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, ...) { + args <- list(...) + query_params <- list() + header_params <- c() + form_params <- list() + file_params <- list() + local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE + + if (missing(`path_array`)) { + rlang::abort(message = "Missing required parameter `path_array`.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "Missing required parameter `path_array`.")) + } + + + 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) + } + + + # The Accept request HTTP header + local_var_accepts <- list() + + # The Content-Type representation header + local_var_content_types <- list() + + local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path), + method = "GET", + query_params = query_params, + header_params = header_params, + form_params = form_params, + file_params = file_params, + accepts = local_var_accepts, + content_types = local_var_content_types, + body = local_var_body, + is_oauth = is_oauth, + oauth_scopes = oauth_scopes, + ...) + + if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { + local_var_resp$content <- NULL + local_var_resp + } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + local_var_error_msg <- local_var_resp$response + if (local_var_error_msg == "") { + local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") + } + rlang::abort(message = local_var_error_msg, + .subclass = "ApiException", + ApiException = ApiException$new(http_response = local_var_resp)) + } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { + local_var_error_msg <- local_var_resp$response + if (local_var_error_msg == "") { + local_var_error_msg <- "Api client exception encountered." + } + rlang::abort(message = local_var_error_msg, + .subclass = "ApiException", + ApiException = ApiException$new(http_response = local_var_resp)) + } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { + local_var_error_msg <- local_var_resp$response + if (local_var_error_msg == "") { + local_var_error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, + .subclass = "ApiException", + ApiException = ApiException$new(http_response = local_var_resp)) + } + }, #' test regular expression to ensure no exception #' #' @description diff --git a/samples/client/petstore/R-httr2/R/pet_api.R b/samples/client/petstore/R-httr2/R/pet_api.R index c040ca153e7..3531b92eda8 100644 --- a/samples/client/petstore/R-httr2/R/pet_api.R +++ b/samples/client/petstore/R-httr2/R/pet_api.R @@ -836,7 +836,7 @@ PetApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{petId\\}", URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) } # OAuth-related settings @@ -1187,7 +1187,7 @@ PetApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{petId\\}", URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) } # Bearer token @@ -1314,7 +1314,7 @@ PetApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{petId\\}", URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) } # API key authentication @@ -1698,7 +1698,7 @@ PetApi <- R6::R6Class( form_params["status"] <- `status` 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) + local_var_url_path <- gsub("\\{petId\\}", URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) } @@ -1810,7 +1810,7 @@ PetApi <- R6::R6Class( file_params["file"] <- curl::form_file(`file`) local_var_url_path <- "/pet/{petId}/uploadImage" if (!missing(`pet_id`)) { - local_var_url_path <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) + local_var_url_path <- gsub("\\{petId\\}", URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) } # OAuth-related settings diff --git a/samples/client/petstore/R-httr2/R/store_api.R b/samples/client/petstore/R-httr2/R/store_api.R index 099b7ec6a1d..ea758118e0b 100644 --- a/samples/client/petstore/R-httr2/R/store_api.R +++ b/samples/client/petstore/R-httr2/R/store_api.R @@ -314,7 +314,7 @@ StoreApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{orderId\\}", URLencode(as.character(`order_id`), reserved = TRUE), local_var_url_path) } @@ -537,7 +537,7 @@ StoreApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{orderId\\}", URLencode(as.character(`order_id`), reserved = TRUE), local_var_url_path) } diff --git a/samples/client/petstore/R-httr2/R/user_api.R b/samples/client/petstore/R-httr2/R/user_api.R index 0d16d8ea51b..463595202f3 100644 --- a/samples/client/petstore/R-httr2/R/user_api.R +++ b/samples/client/petstore/R-httr2/R/user_api.R @@ -832,7 +832,7 @@ UserApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{username\\}", URLencode(as.character(`username`), reserved = TRUE), local_var_url_path) } # API key authentication @@ -940,7 +940,7 @@ UserApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{username\\}", URLencode(as.character(`username`), reserved = TRUE), local_var_url_path) } @@ -1296,7 +1296,7 @@ UserApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{username\\}", URLencode(as.character(`username`), reserved = TRUE), local_var_url_path) } # API key authentication diff --git a/samples/client/petstore/R-httr2/README.md b/samples/client/petstore/R-httr2/README.md index ba69157a6c7..8a8c1134e37 100644 --- a/samples/client/petstore/R-httr2/README.md +++ b/samples/client/petstore/R-httr2/README.md @@ -62,6 +62,7 @@ All URIs are relative to *http://petstore.swagger.io/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- *FakeApi* | [**fake_data_file**](docs/FakeApi.md#fake_data_file) | **GET** /fake/data_file | test data_file to ensure it's escaped correctly +*FakeApi* | [**fake_path_array**](docs/FakeApi.md#fake_path_array) | **GET** /fake/path_array/{path_array}/testing | test array parameter in path *FakeApi* | [**fake_regular_expression**](docs/FakeApi.md#fake_regular_expression) | **GET** /fake/regular_expression | test regular expression to ensure no exception *FakeApi* | [**fake_set_query**](docs/FakeApi.md#fake_set_query) | **GET** /fake/set_query_parameter | test set query parameter *PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **POST** /pet | Add a new pet to the store diff --git a/samples/client/petstore/R-httr2/docs/FakeApi.md b/samples/client/petstore/R-httr2/docs/FakeApi.md index 9ed02006026..ea11291e3cb 100644 --- a/samples/client/petstore/R-httr2/docs/FakeApi.md +++ b/samples/client/petstore/R-httr2/docs/FakeApi.md @@ -5,6 +5,7 @@ All URIs are relative to *http://petstore.swagger.io/v2* Method | HTTP request | Description ------------- | ------------- | ------------- [**fake_data_file**](FakeApi.md#fake_data_file) | **GET** /fake/data_file | test data_file to ensure it's escaped correctly +[**fake_path_array**](FakeApi.md#fake_path_array) | **GET** /fake/path_array/{path_array}/testing | test array parameter in path [**fake_regular_expression**](FakeApi.md#fake_regular_expression) | **GET** /fake/regular_expression | test regular expression to ensure no exception [**fake_set_query**](FakeApi.md#fake_set_query) | **GET** /fake/set_query_parameter | test set query parameter @@ -72,6 +73,61 @@ No authorization required |-------------|-------------|------------------| | **200** | successful operation | - | +# **fake_path_array** +> fake_path_array(path_array) + +test array parameter in path + + + +### Example +```R +library(petstore) + +# test array parameter in path +# +# prepare function argument(s) +var_path_array <- list("inner_example") # array[character] | dummy path parameter + +api_instance <- FakeApi$new() +result <- tryCatch( + api_instance$fake_path_array(var_path_array), + ApiException = function(ex) ex + ) +# In case of error, print the error object +if (!is.null(result$ApiException)) { + print("Exception occurs when calling `fake_path_array`:") + dput(result$ApiException$toString()) + # error object + dput(result$ApiException$error_object$toJSONString()) +} +# This endpoint doesn't return data +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **path_array** | list( **character** )| dummy path parameter | + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: Not defined + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + # **fake_regular_expression** > fake_regular_expression(reg_exp_test) diff --git a/samples/client/petstore/R/R/fake_api.R b/samples/client/petstore/R/R/fake_api.R index d30f7272449..edfd3086513 100644 --- a/samples/client/petstore/R/R/fake_api.R +++ b/samples/client/petstore/R/R/fake_api.R @@ -32,6 +32,23 @@ #' } #' } #' +#' \strong{ FakePathArray } \emph{ test array parameter in path } +#' +#' +#' \itemize{ +#' \item \emph{ @param } path_array list( character ) +#' +#' \item On encountering errors, an error of subclass ApiException will be thrown. +#' +#' \item status code : 200 | successful operation +#' +#' +#' \item response headers : +#' +#' \tabular{ll}{ +#' } +#' } +#' #' \strong{ FakeRegularExpression } \emph{ test regular expression to ensure no exception } #' #' @@ -106,6 +123,31 @@ #' #' #' +#' #################### FakePathArray #################### +#' +#' library(petstore) +#' var_path_array <- ["path_array_example"] # array[character] | dummy path parameter +#' +#' #test array parameter in path +#' api_instance <- FakeApi$new() +#' +#' result <- tryCatch( +#' +#' api_instance$FakePathArray(var_path_array), +#' ApiException = function(ex) ex +#' ) +#' # In case of error, print the error object +#' if (!is.null(result$ApiException)) { +#' print("Exception occurs when calling `FakePathArray`:") +#' dput(result$ApiException$toString()) +#' +#' # error object +#' dput(result$ApiException$error_object$toJSONString()) +#' +#' }#' +#' # This endpoint doesn't return data +#' +#' #' #################### FakeRegularExpression #################### #' #' library(petstore) @@ -300,6 +342,108 @@ FakeApi <- R6::R6Class( ApiException = ApiException$new(http_response = local_var_resp)) } }, + #' test array parameter in path + #' + #' @description + #' test array parameter in path + #' + #' @param path_array dummy path parameter + #' @param ... Other optional arguments + #' @return void + #' @export + FakePathArray = function(path_array, ...) { + local_var_response <- self$FakePathArrayWithHttpInfo(path_array, ...) + 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) { + local_var_response + } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { + local_var_response + } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { + local_var_response + } + }, + #' test array parameter in path + #' + #' @description + #' test array parameter in path + #' + #' @param path_array dummy path parameter + #' @param ... Other optional arguments + #' @return API response (void) with additional information such as HTTP status code, headers + #' @export + FakePathArrayWithHttpInfo = function(path_array, ...) { + args <- list(...) + query_params <- list() + header_params <- c() + form_params <- list() + file_params <- list() + local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE + + if (missing(`path_array`)) { + rlang::abort(message = "Missing required parameter `path_array`.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "Missing required parameter `path_array`.")) + } + + + 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) + } + + + # The Accept request HTTP header + local_var_accepts <- list() + + # The Content-Type representation header + local_var_content_types <- list() + + local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path), + method = "GET", + query_params = query_params, + header_params = header_params, + form_params = form_params, + file_params = file_params, + accepts = local_var_accepts, + content_types = local_var_content_types, + body = local_var_body, + is_oauth = is_oauth, + oauth_scopes = oauth_scopes, + ...) + + if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { + local_var_resp$content <- NULL + local_var_resp + } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + local_var_error_msg <- local_var_resp$response + if (local_var_error_msg == "") { + local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") + } + rlang::abort(message = local_var_error_msg, + .subclass = "ApiException", + ApiException = ApiException$new(http_response = local_var_resp)) + } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { + local_var_error_msg <- local_var_resp$response + if (local_var_error_msg == "") { + local_var_error_msg <- "Api client exception encountered." + } + rlang::abort(message = local_var_error_msg, + .subclass = "ApiException", + ApiException = ApiException$new(http_response = local_var_resp)) + } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { + local_var_error_msg <- local_var_resp$response + if (local_var_error_msg == "") { + local_var_error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, + .subclass = "ApiException", + ApiException = ApiException$new(http_response = local_var_resp)) + } + }, #' test regular expression to ensure no exception #' #' @description diff --git a/samples/client/petstore/R/R/pet_api.R b/samples/client/petstore/R/R/pet_api.R index c3d7f8f1d38..260d14f81f8 100644 --- a/samples/client/petstore/R/R/pet_api.R +++ b/samples/client/petstore/R/R/pet_api.R @@ -836,7 +836,7 @@ PetApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{petId\\}", URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) } # OAuth-related settings @@ -1187,7 +1187,7 @@ PetApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{petId\\}", URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) } # Bearer token @@ -1314,7 +1314,7 @@ PetApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{petId\\}", URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) } # API key authentication @@ -1698,7 +1698,7 @@ PetApi <- R6::R6Class( form_params["status"] <- `status` 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) + local_var_url_path <- gsub("\\{petId\\}", URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) } @@ -1810,7 +1810,7 @@ PetApi <- R6::R6Class( file_params["file"] <- httr::upload_file(`file`) local_var_url_path <- "/pet/{petId}/uploadImage" if (!missing(`pet_id`)) { - local_var_url_path <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) + local_var_url_path <- gsub("\\{petId\\}", URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) } # OAuth-related settings diff --git a/samples/client/petstore/R/R/store_api.R b/samples/client/petstore/R/R/store_api.R index e90ba71de06..5ac8408eab2 100644 --- a/samples/client/petstore/R/R/store_api.R +++ b/samples/client/petstore/R/R/store_api.R @@ -314,7 +314,7 @@ StoreApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{orderId\\}", URLencode(as.character(`order_id`), reserved = TRUE), local_var_url_path) } @@ -537,7 +537,7 @@ StoreApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{orderId\\}", URLencode(as.character(`order_id`), reserved = TRUE), local_var_url_path) } diff --git a/samples/client/petstore/R/R/user_api.R b/samples/client/petstore/R/R/user_api.R index 28fb0ee46c4..b6c17fb4b03 100644 --- a/samples/client/petstore/R/R/user_api.R +++ b/samples/client/petstore/R/R/user_api.R @@ -832,7 +832,7 @@ UserApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{username\\}", URLencode(as.character(`username`), reserved = TRUE), local_var_url_path) } # API key authentication @@ -940,7 +940,7 @@ UserApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{username\\}", URLencode(as.character(`username`), reserved = TRUE), local_var_url_path) } @@ -1296,7 +1296,7 @@ UserApi <- R6::R6Class( 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) + local_var_url_path <- gsub("\\{username\\}", URLencode(as.character(`username`), reserved = TRUE), local_var_url_path) } # API key authentication diff --git a/samples/client/petstore/R/README.md b/samples/client/petstore/R/README.md index c71444bcf01..dedaab7b742 100644 --- a/samples/client/petstore/R/README.md +++ b/samples/client/petstore/R/README.md @@ -62,6 +62,7 @@ All URIs are relative to *http://petstore.swagger.io/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- *FakeApi* | [**FakeDataFile**](docs/FakeApi.md#FakeDataFile) | **GET** /fake/data_file | test data_file to ensure it's escaped correctly +*FakeApi* | [**FakePathArray**](docs/FakeApi.md#FakePathArray) | **GET** /fake/path_array/{path_array}/testing | test array parameter in path *FakeApi* | [**FakeRegularExpression**](docs/FakeApi.md#FakeRegularExpression) | **GET** /fake/regular_expression | test regular expression to ensure no exception *FakeApi* | [**FakeSetQuery**](docs/FakeApi.md#FakeSetQuery) | **GET** /fake/set_query_parameter | test set query parameter *PetApi* | [**AddPet**](docs/PetApi.md#AddPet) | **POST** /pet | Add a new pet to the store diff --git a/samples/client/petstore/R/docs/FakeApi.md b/samples/client/petstore/R/docs/FakeApi.md index 1d56f96dcc3..f77e43a189b 100644 --- a/samples/client/petstore/R/docs/FakeApi.md +++ b/samples/client/petstore/R/docs/FakeApi.md @@ -5,6 +5,7 @@ All URIs are relative to *http://petstore.swagger.io/v2* Method | HTTP request | Description ------------- | ------------- | ------------- [**FakeDataFile**](FakeApi.md#FakeDataFile) | **GET** /fake/data_file | test data_file to ensure it's escaped correctly +[**FakePathArray**](FakeApi.md#FakePathArray) | **GET** /fake/path_array/{path_array}/testing | test array parameter in path [**FakeRegularExpression**](FakeApi.md#FakeRegularExpression) | **GET** /fake/regular_expression | test regular expression to ensure no exception [**FakeSetQuery**](FakeApi.md#FakeSetQuery) | **GET** /fake/set_query_parameter | test set query parameter @@ -72,6 +73,61 @@ No authorization required |-------------|-------------|------------------| | **200** | successful operation | - | +# **FakePathArray** +> FakePathArray(path_array) + +test array parameter in path + + + +### Example +```R +library(petstore) + +# test array parameter in path +# +# prepare function argument(s) +var_path_array <- list("inner_example") # array[character] | dummy path parameter + +api_instance <- FakeApi$new() +result <- tryCatch( + api_instance$FakePathArray(var_path_array), + ApiException = function(ex) ex + ) +# In case of error, print the error object +if (!is.null(result$ApiException)) { + print("Exception occurs when calling `FakePathArray`:") + dput(result$ApiException$toString()) + # error object + dput(result$ApiException$error_object$toJSONString()) +} +# This endpoint doesn't return data +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **path_array** | list( **character** )| dummy path parameter | + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: Not defined + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + # **FakeRegularExpression** > FakeRegularExpression(reg_exp_test)