|
13 | 13 | #' |
14 | 14 | #' @section Methods: |
15 | 15 | #' \describe{ |
| 16 | +#' \strong{ add_pet_optional } \emph{ Add a new pet to the store (optional body) } |
| 17 | +#' |
| 18 | +#' |
| 19 | +#' \itemize{ |
| 20 | +#' \item \emph{ @param } pet \link{Pet} |
| 21 | +#' \item \emph{ @returnType } \link{Pet} \cr |
| 22 | +#' |
| 23 | +#' \item On encountering errors, an error of subclass ApiException will be thrown. |
| 24 | +#' |
| 25 | +#' \item status code : 200 | successful operation |
| 26 | +#' |
| 27 | +#' \item return type : Pet |
| 28 | +#' \item response headers : |
| 29 | +#' |
| 30 | +#' \tabular{ll}{ |
| 31 | +#' } |
| 32 | +#' \item status code : 405 | Invalid input |
| 33 | +#' |
| 34 | +#' |
| 35 | +#' \item response headers : |
| 36 | +#' |
| 37 | +#' \tabular{ll}{ |
| 38 | +#' } |
| 39 | +#' } |
| 40 | +#' |
16 | 41 | #' \strong{ fake_data_file } \emph{ test data_file to ensure it's escaped correctly } |
17 | 42 | #' |
18 | 43 | #' |
|
89 | 114 | #' |
90 | 115 | #' @examples |
91 | 116 | #' \dontrun{ |
| 117 | +#' #################### add_pet_optional #################### |
| 118 | +#' |
| 119 | +#' library(petstore) |
| 120 | +#' var_pet <- Pet$new() # Pet | Pet object that needs to be added to the store |
| 121 | +#' |
| 122 | +#' #Add a new pet to the store (optional body) |
| 123 | +#' api_instance <- petstore_api$new() |
| 124 | +#' |
| 125 | +#' # Configure HTTP basic authorization: http_auth |
| 126 | +#' api_instance$api_client$username <- Sys.getenv("USERNAME") |
| 127 | +#' api_instance$api_client$password <- Sys.getenv("PASSWORD") |
| 128 | +#' |
| 129 | +#' result <- tryCatch( |
| 130 | +#' |
| 131 | +#' # to save the result into a file, simply add the optional `data_file` parameter, e.g. |
| 132 | +#' # api_instance$fake_api$add_pet_optional(pet = var_pet, data_file = "result.txt"), |
| 133 | +#' |
| 134 | +#' |
| 135 | +#' api_instance$fake_api$add_pet_optional(pet = var_pet), |
| 136 | +#' ApiException = function(ex) ex |
| 137 | +#' ) |
| 138 | +#' # In case of error, print the error object |
| 139 | +#' if (!is.null(result$ApiException)) { |
| 140 | +#' print("Exception occurs when calling `add_pet_optional`:") |
| 141 | +#' dput(result$ApiException$toString()) |
| 142 | +#' |
| 143 | +#' # error object |
| 144 | +#' dput(result$ApiException$error_object$toJSONString()) |
| 145 | +#' |
| 146 | +#' } else { |
| 147 | +#' # deserialized response object |
| 148 | +#' print("The response is ...") |
| 149 | +#' dput(result$toString()) |
| 150 | +#' } |
| 151 | +#' |
| 152 | +#' |
| 153 | +#' |
92 | 154 | #' #################### fake_data_file #################### |
93 | 155 | #' |
94 | 156 | #' library(petstore) |
@@ -222,6 +284,122 @@ FakeApi <- R6::R6Class( |
222 | 284 | self$api_client <- ApiClient$new() |
223 | 285 | } |
224 | 286 | }, |
| 287 | + #' Add a new pet to the store (optional body) |
| 288 | + #' |
| 289 | + #' @description |
| 290 | + #' Add a new pet to the store (optional body) |
| 291 | + #' |
| 292 | + #' @param pet (optional) Pet object that needs to be added to the store |
| 293 | + #' @param data_file (optional) name of the data file to save the result |
| 294 | + #' @param ... Other optional arguments |
| 295 | + #' @return Pet |
| 296 | + #' @export |
| 297 | + add_pet_optional = function(pet = NULL, data_file = NULL, ...) { |
| 298 | + local_var_response <- self$add_pet_optional_with_http_info(pet, data_file = data_file, ...) |
| 299 | + if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { |
| 300 | + local_var_response$content |
| 301 | + } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { |
| 302 | + local_var_response |
| 303 | + } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { |
| 304 | + local_var_response |
| 305 | + } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { |
| 306 | + local_var_response |
| 307 | + } |
| 308 | + }, |
| 309 | + #' Add a new pet to the store (optional body) |
| 310 | + #' |
| 311 | + #' @description |
| 312 | + #' Add a new pet to the store (optional body) |
| 313 | + #' |
| 314 | + #' @param pet (optional) Pet object that needs to be added to the store |
| 315 | + #' @param data_file (optional) name of the data file to save the result |
| 316 | + #' @param ... Other optional arguments |
| 317 | + #' @return API response (Pet) with additional information such as HTTP status code, headers |
| 318 | + #' @export |
| 319 | + add_pet_optional_with_http_info = function(pet = NULL, data_file = NULL, ...) { |
| 320 | + args <- list(...) |
| 321 | + query_params <- list() |
| 322 | + header_params <- c() |
| 323 | + form_params <- list() |
| 324 | + file_params <- list() |
| 325 | + local_var_body <- NULL |
| 326 | + oauth_scopes <- NULL |
| 327 | + is_oauth <- FALSE |
| 328 | + |
| 329 | + |
| 330 | + if (!is.null(`pet`)) { |
| 331 | + local_var_body <- `pet`$toJSONString() |
| 332 | + } else { |
| 333 | + body <- NULL |
| 334 | + } |
| 335 | + |
| 336 | + local_var_url_path <- "/fake/test_optional_body_parameter" |
| 337 | + # HTTP basic auth |
| 338 | + if (!is.null(self$api_client$username) || !is.null(self$api_client$password)) { |
| 339 | + header_params["Authorization"] <- paste("Basic", base64enc::base64encode(charToRaw(paste(self$api_client$username, self$api_client$password, sep = ":")))) |
| 340 | + } |
| 341 | + |
| 342 | + # The Accept request HTTP header |
| 343 | + local_var_accepts <- list("application/xml", "application/json") |
| 344 | + |
| 345 | + # The Content-Type representation header |
| 346 | + local_var_content_types <- list("application/json", "application/xml", "multipart/related") |
| 347 | + |
| 348 | + local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path), |
| 349 | + method = "POST", |
| 350 | + query_params = query_params, |
| 351 | + header_params = header_params, |
| 352 | + form_params = form_params, |
| 353 | + file_params = file_params, |
| 354 | + accepts = local_var_accepts, |
| 355 | + content_types = local_var_content_types, |
| 356 | + body = local_var_body, |
| 357 | + is_oauth = is_oauth, |
| 358 | + oauth_scopes = oauth_scopes, |
| 359 | + ...) |
| 360 | + |
| 361 | + if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { |
| 362 | + # save response in a file |
| 363 | + if (!is.null(data_file)) { |
| 364 | + write(local_var_resp$response, data_file) |
| 365 | + } |
| 366 | + |
| 367 | + deserialized_resp_obj <- tryCatch( |
| 368 | + self$api_client$deserialize(local_var_resp$response, "Pet", loadNamespace("petstore")), |
| 369 | + error = function(e) { |
| 370 | + rlang::abort(message = "Failed to deserialize response", |
| 371 | + .subclass = "ApiException", |
| 372 | + ApiException = ApiException$new(http_response = local_var_resp)) |
| 373 | + } |
| 374 | + ) |
| 375 | + local_var_resp$content <- deserialized_resp_obj |
| 376 | + local_var_resp |
| 377 | + } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { |
| 378 | + local_var_error_msg <- local_var_resp$response |
| 379 | + if (local_var_error_msg == "") { |
| 380 | + local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") |
| 381 | + } |
| 382 | + rlang::abort(message = local_var_error_msg, |
| 383 | + .subclass = "ApiException", |
| 384 | + ApiException = ApiException$new(http_response = local_var_resp)) |
| 385 | + } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { |
| 386 | + local_var_error_msg <- local_var_resp$response |
| 387 | + if (local_var_error_msg == "") { |
| 388 | + local_var_error_msg <- "Api client exception encountered." |
| 389 | + } |
| 390 | + rlang::abort(message = local_var_error_msg, |
| 391 | + .subclass = "ApiException", |
| 392 | + ApiException = ApiException$new(http_response = local_var_resp)) |
| 393 | + } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { |
| 394 | + local_var_error_msg <- local_var_resp$response |
| 395 | + if (local_var_error_msg == "") { |
| 396 | + local_var_error_msg <- "Api server exception encountered." |
| 397 | + } |
| 398 | + rlang::abort(message = error_msg, |
| 399 | + .subclass = "ApiException", |
| 400 | + ApiException = ApiException$new(http_response = local_var_resp)) |
| 401 | + } |
| 402 | + }, |
225 | 403 | #' test data_file to ensure it's escaped correctly |
226 | 404 | #' |
227 | 405 | #' @description |
|
0 commit comments