#' OpenAPI Petstore
#'
#' This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#'
#' The version of the OpenAPI document: 1.0.0
#' Generated by: https://openapi-generator.tech
#'
#' @docType class
#' @title Pet operations
#' @description PetApi
#' @format An \code{R6Class} generator object
#' @field api_client Handles the client-server communication.
#'
#' @section Methods:
#' \describe{
#' \strong{ AddPet } \emph{ Add a new pet to the store }
#' 
#'
#' \itemize{
#' \item \emph{ @param } pet \link{Pet}
#' \item \emph{ @returnType } \link{Pet} \cr
#'
#' \item On encountering errors, an error of subclass ApiException will be thrown.
#'
#' \item status code : 200 | successful operation
#'
#' \item return type : Pet
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 405 | Invalid input
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ DeletePet } \emph{ Deletes a pet }
#' 
#'
#' \itemize{
#' \item \emph{ @param } pet_id integer
#' \item \emph{ @param } api_key character
#'
#' \item On encountering errors, an error of subclass ApiException will be thrown.
#'
#' \item status code : 400 | Invalid pet value
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ FindPetsByStatus } \emph{ Finds Pets by status }
#' Multiple status values can be provided with comma separated strings
#'
#' \itemize{
#' \item \emph{ @param } status Enum < [available, pending, sold] >
#' \item \emph{ @returnType } list( \link{Pet} ) \cr
#'
#' \item On encountering errors, an error of subclass ApiException will be thrown.
#'
#' \item status code : 200 | successful operation
#'
#' \item return type : array[Pet]
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 400 | Invalid status value
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ FindPetsByTags } \emph{ Finds Pets by tags }
#' Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
#'
#' \itemize{
#' \item \emph{ @param } tags list( character )
#' \item \emph{ @returnType } list( \link{Pet} ) \cr
#'
#' \item On encountering errors, an error of subclass ApiException will be thrown.
#'
#' \item status code : 200 | successful operation
#'
#' \item return type : array[Pet]
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 400 | Invalid tag value
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ GetPetById } \emph{ Find pet by ID }
#' Returns a single pet
#'
#' \itemize{
#' \item \emph{ @param } pet_id integer
#' \item \emph{ @returnType } \link{Pet} \cr
#'
#' \item On encountering errors, an error of subclass ApiException will be thrown.
#'
#' \item status code : 200 | successful operation
#'
#' \item return type : Pet
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 400 | Invalid ID supplied
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 404 | Pet not found
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ GetPetByIdStreaming } \emph{ Find pet by ID (streaming) }
#' Returns a single pet
#'
#' \itemize{
#' \item \emph{ @param } pet_id integer
#' \item \emph{ @returnType } \link{Pet} \cr
#'
#' \item On encountering errors, an error of subclass ApiException will be thrown.
#'
#' \item status code : 200 | successful operation
#'
#' \item return type : Pet
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 400 | Invalid ID supplied
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 404 | Pet not found
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ TestHeader } \emph{ Header test }
#' Header test
#'
#' \itemize{
#' \item \emph{ @param } header_test_int integer
#' \item \emph{ @returnType } \link{Pet} \cr
#'
#' \item On encountering errors, an error of subclass ApiException will be thrown.
#'
#' \item status code : 200 | successful operation
#'
#' \item return type : Pet
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 400 | Invalid ID supplied
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 404 | Pet not found
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ UpdatePet } \emph{ Update an existing pet }
#' 
#'
#' \itemize{
#' \item \emph{ @param } pet \link{Pet}
#' \item \emph{ @returnType } \link{Pet} \cr
#'
#' \item On encountering errors, an error of subclass ApiException will be thrown.
#'
#' \item status code : 200 | successful operation
#'
#' \item return type : Pet
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 400 | Invalid ID supplied
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 404 | Pet not found
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 405 | Validation exception
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ UpdatePetWithForm } \emph{ Updates a pet in the store with form data }
#' 
#'
#' \itemize{
#' \item \emph{ @param } pet_id integer
#' \item \emph{ @param } name character
#' \item \emph{ @param } status character
#'
#' \item On encountering errors, an error of subclass ApiException will be thrown.
#'
#' \item status code : 405 | Invalid input
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ UploadFile } \emph{ uploads an image }
#' 
#'
#' \itemize{
#' \item \emph{ @param } pet_id integer
#' \item \emph{ @param } additional_metadata character
#' \item \emph{ @param } file data.frame
#' \item \emph{ @returnType } \link{ModelApiResponse} \cr
#'
#' \item On encountering errors, an error of subclass ApiException will be thrown.
#'
#' \item status code : 200 | successful operation
#'
#' \item return type : ModelApiResponse
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' }
#'
#'
#' @examples
#' \dontrun{
#' ####################  AddPet  ####################
#'
#' library(petstore)
#' var_pet <- Pet$new("name_example", c("photoUrls_example"), 123, Category$new(123, "name_example"), c(Tag$new(123, "name_example")), "available") # Pet | Pet object that needs to be added to the store
#'
#' #Add a new pet to the store
#' api_instance <- PetApi$new()
#'
#' # Configure HTTP basic authorization: http_auth
#' api_instance$api_client$username <- Sys.getenv("USERNAME")
#' api_instance$api_client$password <- Sys.getenv("PASSWORD")
#'
#' result <- tryCatch(
#'              
#'              # to save the result into a file, simply add the optional `data_file` parameter, e.g.
#'              # api_instance$AddPet(var_pet, data_file = "result.txt"),
#'              
#'              
#'              api_instance$AddPet(var_pet),
#'              ApiException = function(ex) ex
#'           )
#' # In case of error, print the error object
#' if (!is.null(result$ApiException)) {
#'   print("Exception occurs when calling `AddPet`:")
#'   dput(result$ApiException$toString())
#'   
#'   # error object
#'   dput(result$ApiException$error_object$toJSONString())
#'   
#' } else {
#'   # deserialized response object
#'   print("The response is ...")
#'   dput(result$toString())
#' }
#'
#'
#'
#' ####################  DeletePet  ####################
#'
#' library(petstore)
#' var_pet_id <- 56 # integer | Pet id to delete
#' var_api_key <- "api_key_example" # character |  (Optional)
#'
#' #Deletes a pet
#' api_instance <- PetApi$new()
#'
#' # Configure OAuth2 access token for authorization: petstore_auth
#' api_instance$api_client$access_token <- Sys.getenv("ACCESS_TOKEN")
#'
#' result <- tryCatch(
#'              
#'              api_instance$DeletePet(var_pet_id, api_key = var_api_key),
#'              ApiException = function(ex) ex
#'           )
#' # In case of error, print the error object
#' if (!is.null(result$ApiException)) {
#'   print("Exception occurs when calling `DeletePet`:")
#'   dput(result$ApiException$toString())
#'   
#'   # error object
#'   dput(result$ApiException$error_object$toJSONString())
#'   
#' }#'
#' # This endpoint doesn't return data
#'
#'
#' ####################  FindPetsByStatus  ####################
#'
#' library(petstore)
#' var_status <- c("available") # array[character] | Status values that need to be considered for filter
#'
#' #Finds Pets by status
#' api_instance <- PetApi$new()
#'
#' # Configure OAuth2 access token for authorization: petstore_auth
#' api_instance$api_client$access_token <- Sys.getenv("ACCESS_TOKEN")
#'
#' result <- tryCatch(
#'              
#'              # to save the result into a file, simply add the optional `data_file` parameter, e.g.
#'              # api_instance$FindPetsByStatus(var_status, data_file = "result.txt"),
#'              
#'              
#'              api_instance$FindPetsByStatus(var_status),
#'              ApiException = function(ex) ex
#'           )
#' # In case of error, print the error object
#' if (!is.null(result$ApiException)) {
#'   print("Exception occurs when calling `FindPetsByStatus`:")
#'   dput(result$ApiException$toString())
#'   
#'   # error object
#'   dput(result$ApiException$error_object$toJSONString())
#'   
#' } else {
#'   # deserialized response object
#'   print("The response is ...")
#'   dput(result$toString())
#' }
#'
#'
#'
#' ####################  FindPetsByTags  ####################
#'
#' library(petstore)
#' var_tags <- c("inner_example") # array[character] | Tags to filter by
#'
#' #Finds Pets by tags
#' api_instance <- PetApi$new()
#'
#' result <- tryCatch(
#'              
#'              # to save the result into a file, simply add the optional `data_file` parameter, e.g.
#'              # api_instance$FindPetsByTags(var_tags, data_file = "result.txt"),
#'              
#'              
#'              api_instance$FindPetsByTags(var_tags),
#'              ApiException = function(ex) ex
#'           )
#' # In case of error, print the error object
#' if (!is.null(result$ApiException)) {
#'   print("Exception occurs when calling `FindPetsByTags`:")
#'   dput(result$ApiException$toString())
#'   
#'   # error object
#'   dput(result$ApiException$error_object$toJSONString())
#'   
#' } else {
#'   # deserialized response object
#'   print("The response is ...")
#'   dput(result$toString())
#' }
#'
#'
#'
#' ####################  GetPetById  ####################
#'
#' library(petstore)
#' var_pet_id <- 56 # integer | ID of pet to return
#'
#' #Find pet by ID
#' api_instance <- PetApi$new()
#'
#' # Configure HTTP bearer authorization: BearerToken
#' api_instance$api_client$bearer_token <- Sys.getenv("BEARER_TOKEN")
#'
#' result <- tryCatch(
#'              
#'              # to save the result into a file, simply add the optional `data_file` parameter, e.g.
#'              # api_instance$GetPetById(var_pet_id, data_file = "result.txt"),
#'              
#'              
#'              api_instance$GetPetById(var_pet_id),
#'              ApiException = function(ex) ex
#'           )
#' # In case of error, print the error object
#' if (!is.null(result$ApiException)) {
#'   print("Exception occurs when calling `GetPetById`:")
#'   dput(result$ApiException$toString())
#'   
#'   # error object
#'   dput(result$ApiException$error_object$toJSONString())
#'   
#' } else {
#'   # deserialized response object
#'   print("The response is ...")
#'   dput(result$toString())
#' }
#'
#'
#'
#' ####################  GetPetByIdStreaming  ####################
#'
#' library(petstore)
#' var_pet_id <- 56 # integer | ID of pet to return
#'
#' #Find pet by ID (streaming)
#' api_instance <- PetApi$new()
#'
#' # Configure API key authorization: api_key
#' api_instance$api_client$api_keys["api_key"] <- Sys.getenv("API_KEY")
#'
#' result <- tryCatch(
#'              
#'              # to save the result into a file, simply add the optional `data_file` parameter, e.g.
#'              # api_instance$GetPetByIdStreaming(var_pet_id, data_file = "result.txt"),
#'              
#'              # this endpoint supports data streaming via a callback function using the optional `stream_callback` parameter, e.g.
#'              # api_instance$GetPetByIdStreaming(var_pet_id, stream_callback = function(x){ print(length(x)) }),
#'              
#'              
#'              api_instance$GetPetByIdStreaming(var_pet_id),
#'              ApiException = function(ex) ex
#'           )
#' # In case of error, print the error object
#' if (!is.null(result$ApiException)) {
#'   print("Exception occurs when calling `GetPetByIdStreaming`:")
#'   dput(result$ApiException$toString())
#'   
#'   # error object
#'   dput(result$ApiException$error_object$toJSONString())
#'   
#' } else {
#'   # deserialized response object
#'   print("The response is ...")
#'   dput(result$toString())
#' }
#'
#'
#'
#' ####################  TestHeader  ####################
#'
#' library(petstore)
#' var_header_test_int <- 56 # integer | header test int
#'
#' #Header test
#' api_instance <- PetApi$new()
#'
#' # Configure API key authorization: api_key
#' api_instance$api_client$api_keys["api_key"] <- Sys.getenv("API_KEY")
#'
#' result <- tryCatch(
#'              
#'              # to save the result into a file, simply add the optional `data_file` parameter, e.g.
#'              # api_instance$TestHeader(var_header_test_int, data_file = "result.txt"),
#'              
#'              # this endpoint supports data streaming via a callback function using the optional `stream_callback` parameter, e.g.
#'              # api_instance$TestHeader(var_header_test_int, stream_callback = function(x){ print(length(x)) }),
#'              
#'              
#'              api_instance$TestHeader(var_header_test_int),
#'              ApiException = function(ex) ex
#'           )
#' # In case of error, print the error object
#' if (!is.null(result$ApiException)) {
#'   print("Exception occurs when calling `TestHeader`:")
#'   dput(result$ApiException$toString())
#'   
#'   # error object
#'   dput(result$ApiException$error_object$toJSONString())
#'   
#' } else {
#'   # deserialized response object
#'   print("The response is ...")
#'   dput(result$toString())
#' }
#'
#'
#'
#' ####################  UpdatePet  ####################
#'
#' library(petstore)
#' var_pet <- Pet$new("name_example", c("photoUrls_example"), 123, Category$new(123, "name_example"), c(Tag$new(123, "name_example")), "available") # Pet | Pet object that needs to be added to the store
#'
#' #Update an existing pet
#' api_instance <- PetApi$new()
#'
#' # Configure OAuth2 access token for authorization: petstore_auth
#' api_instance$api_client$access_token <- Sys.getenv("ACCESS_TOKEN")
#'
#' result <- tryCatch(
#'              
#'              # to save the result into a file, simply add the optional `data_file` parameter, e.g.
#'              # api_instance$UpdatePet(var_pet, data_file = "result.txt"),
#'              
#'              
#'              api_instance$UpdatePet(var_pet),
#'              ApiException = function(ex) ex
#'           )
#' # In case of error, print the error object
#' if (!is.null(result$ApiException)) {
#'   print("Exception occurs when calling `UpdatePet`:")
#'   dput(result$ApiException$toString())
#'   
#'   # error object
#'   dput(result$ApiException$error_object$toJSONString())
#'   
#' } else {
#'   # deserialized response object
#'   print("The response is ...")
#'   dput(result$toString())
#' }
#'
#'
#'
#' ####################  UpdatePetWithForm  ####################
#'
#' library(petstore)
#' var_pet_id <- 56 # integer | ID of pet that needs to be updated
#' var_name <- "name_example" # character | Updated name of the pet (Optional)
#' var_status <- "status_example" # character | Updated status of the pet (Optional)
#'
#' #Updates a pet in the store with form data
#' api_instance <- PetApi$new()
#'
#' result <- tryCatch(
#'              
#'              api_instance$UpdatePetWithForm(var_pet_id, name = var_name, status = var_status),
#'              ApiException = function(ex) ex
#'           )
#' # In case of error, print the error object
#' if (!is.null(result$ApiException)) {
#'   print("Exception occurs when calling `UpdatePetWithForm`:")
#'   dput(result$ApiException$toString())
#'   
#'   # error object
#'   dput(result$ApiException$error_object$toJSONString())
#'   
#' }#'
#' # This endpoint doesn't return data
#'
#'
#' ####################  UploadFile  ####################
#'
#' library(petstore)
#' var_pet_id <- 56 # integer | ID of pet to update
#' var_additional_metadata <- "additional_metadata_example" # character | Additional data to pass to server (Optional)
#' var_file <- File.new('/path/to/file') # data.frame | file to upload (Optional)
#'
#' #uploads an image
#' api_instance <- PetApi$new()
#'
#' # Configure OAuth2 access token for authorization: petstore_auth
#' api_instance$api_client$access_token <- Sys.getenv("ACCESS_TOKEN")
#'
#' result <- tryCatch(
#'              
#'              # to save the result into a file, simply add the optional `data_file` parameter, e.g.
#'              # api_instance$UploadFile(var_pet_id, additional_metadata = var_additional_metadata, file = var_file, data_file = "result.txt"),
#'              
#'              
#'              api_instance$UploadFile(var_pet_id, additional_metadata = var_additional_metadata, file = var_file),
#'              ApiException = function(ex) ex
#'           )
#' # In case of error, print the error object
#' if (!is.null(result$ApiException)) {
#'   print("Exception occurs when calling `UploadFile`:")
#'   dput(result$ApiException$toString())
#'   
#'   # error object
#'   dput(result$ApiException$error_object$toJSONString())
#'   
#' } else {
#'   # deserialized response object
#'   print("The response is ...")
#'   dput(result$toString())
#' }
#'
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom base64enc base64encode
#' @importFrom rlang abort
#' @export
PetApi <- R6::R6Class(
  "PetApi",
  public = list(
    api_client = NULL,
    #' Initialize a new PetApi.
    #'
    #' @description
    #' Initialize a new PetApi.
    #'
    #' @param api_client An instance of API client.
    #' @export
    initialize = function(api_client) {
      if (!missing(api_client)) {
        self$api_client <- api_client
      } else {
        self$api_client <- ApiClient$new()
      }
    },
    #' Add a new pet to the store
    #'
    #' @description
    #' Add a new pet to the store
    #'
    #' @param pet Pet object that needs to be added to the store
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #' @return Pet
    #' @export
    AddPet = function(pet, data_file = NULL, ...) {
      local_var_response <- self$AddPetWithHttpInfo(pet, data_file = data_file, ...)
      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
      }
    },
    #' Add a new pet to the store
    #'
    #' @description
    #' Add a new pet to the store
    #'
    #' @param pet Pet object that needs to be added to the store
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #' @return API response (Pet) with additional information such as HTTP status code, headers
    #' @export
    AddPetWithHttpInfo = function(pet, data_file = NULL, ...) {
      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(`pet`)) {
        rlang::abort(message = "Missing required parameter `pet`.",
                     .subclass = "ApiException",
                     ApiException = ApiException$new(status = 0,
                                                     reason = "Missing required parameter `pet`."))
      }


      if (!is.null(`pet`)) {
        local_var_body <- `pet`$toJSONString()
      } else {
        body <- NULL
      }

      local_var_url_path <- "/pet"
      # HTTP basic auth
      if (!is.null(self$api_client$username) || !is.null(self$api_client$password)) {
        header_params["Authorization"] <- paste("Basic", base64enc::base64encode(charToRaw(paste(self$api_client$username, self$api_client$password, sep = ":"))))
      }

      # The Accept request HTTP header
      local_var_accepts <- list("application/xml", "application/json")

      # The Content-Type representation header
      local_var_content_types <- list("application/json", "application/xml", "multipart/related")

      local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path),
                                 method = "POST",
                                 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) {
        # save response in a file
        if (!is.null(data_file)) {
          write(local_var_resp$response, data_file)
        }

        deserialized_resp_obj <- tryCatch(
          self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")),
          error = function(e) {
            rlang::abort(message = "Failed to deserialize response",
                         .subclass = "ApiException",
                         ApiException = ApiException$new(http_response = local_var_resp))
          }
        )
        local_var_resp$content <- deserialized_resp_obj
        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))
      }
    },
    #' Deletes a pet
    #'
    #' @description
    #' Deletes a pet
    #'
    #' @param pet_id Pet id to delete
    #' @param api_key (optional) No description
    #' @param ... Other optional arguments
    #' @return void
    #' @export
    DeletePet = function(pet_id, api_key = NULL, ...) {
      local_var_response <- self$DeletePetWithHttpInfo(pet_id, api_key, ...)
      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
      }
    },
    #' Deletes a pet
    #'
    #' @description
    #' Deletes a pet
    #'
    #' @param pet_id Pet id to delete
    #' @param api_key (optional) No description
    #' @param ... Other optional arguments
    #' @return API response (void) with additional information such as HTTP status code, headers
    #' @export
    DeletePetWithHttpInfo = function(pet_id, api_key = NULL, ...) {
      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(`pet_id`)) {
        rlang::abort(message = "Missing required parameter `pet_id`.",
                     .subclass = "ApiException",
                     ApiException = ApiException$new(status = 0,
                                                     reason = "Missing required parameter `pet_id`."))
      }



      header_params["api_key"] <- `api_key`

      local_var_url_path <- "/pet/{petId}"
      if (!missing(`pet_id`)) {
        local_var_url_path <- gsub("\\{petId\\}", URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path)
      }

      # OAuth-related settings
      is_oauth <- TRUE
      oauth_scopes <- "write:pets read:pets"

      # 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 = "DELETE",
                                 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))
      }
    },
    #' Finds Pets by status
    #'
    #' @description
    #' Finds Pets by status
    #'
    #' @param status Status values that need to be considered for filter
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #' @return array[Pet]
    #' @export
    FindPetsByStatus = function(status, data_file = NULL, ...) {
      local_var_response <- self$FindPetsByStatusWithHttpInfo(status, data_file = data_file, ...)
      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
      }
    },
    #' Finds Pets by status
    #'
    #' @description
    #' Finds Pets by status
    #'
    #' @param status Status values that need to be considered for filter
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #' @return API response (array[Pet]) with additional information such as HTTP status code, headers
    #' @export
    FindPetsByStatusWithHttpInfo = function(status, data_file = NULL, ...) {
      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(`status`)) {
        rlang::abort(message = "Missing required parameter `status`.",
                     .subclass = "ApiException",
                     ApiException = ApiException$new(status = 0,
                                                     reason = "Missing required parameter `status`."))
      }


      # explore
      for (query_item in `status`) {
        # validate enum values
        if (!(query_item %in% c("available", "pending", "sold"))) {
          rlang::abort(message = "Invalid value for `status` when calling PetApi$FindPetsByStatus. Must be [available, pending, sold].",
                       .subclass = "ApiException",
                       ApiException = ApiException$new(status = 0,
                                                       reason = "Invalid value for `status` when calling PetApi$FindPetsByStatus. Must be [available, pending, sold]."))
        }
        query_params[["status"]] <- c(query_params[["status"]], list(`status` = query_item))
      }

      local_var_url_path <- "/pet/findByStatus"
      # OAuth-related settings
      is_oauth <- TRUE
      oauth_scopes <- "read:pets"

      # The Accept request HTTP header
      local_var_accepts <- list("application/xml", "application/json")

      # 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) {
        # save response in a file
        if (!is.null(data_file)) {
          write(local_var_resp$response, data_file)
        }

        deserialized_resp_obj <- tryCatch(
          self$api_client$deserialize(local_var_resp$response_as_text(), "array[Pet]", loadNamespace("petstore")),
          error = function(e) {
            rlang::abort(message = "Failed to deserialize response",
                         .subclass = "ApiException",
                         ApiException = ApiException$new(http_response = local_var_resp))
          }
        )
        local_var_resp$content <- deserialized_resp_obj
        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))
      }
    },
    #' Finds Pets by tags
    #'
    #' @description
    #' Finds Pets by tags
    #'
    #' @param tags Tags to filter by
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #' @return array[Pet]
    #' @export
    FindPetsByTags = function(tags, data_file = NULL, ...) {
      local_var_response <- self$FindPetsByTagsWithHttpInfo(tags, data_file = data_file, ...)
      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
      }
    },
    #' Finds Pets by tags
    #'
    #' @description
    #' Finds Pets by tags
    #'
    #' @param tags Tags to filter by
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #' @return API response (array[Pet]) with additional information such as HTTP status code, headers
    #' @export
    FindPetsByTagsWithHttpInfo = function(tags, data_file = NULL, ...) {
      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(`tags`)) {
        rlang::abort(message = "Missing required parameter `tags`.",
                     .subclass = "ApiException",
                     ApiException = ApiException$new(status = 0,
                                                     reason = "Missing required parameter `tags`."))
      }


      # no explore
      query_params[["tags"]] <- I(paste(lapply(`tags`, URLencode, reserved = TRUE), collapse = ","))

      local_var_url_path <- "/pet/findByTags"

      # The Accept request HTTP header
      local_var_accepts <- list("application/xml", "application/json")

      # 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) {
        # save response in a file
        if (!is.null(data_file)) {
          write(local_var_resp$response, data_file)
        }

        deserialized_resp_obj <- tryCatch(
          self$api_client$deserialize(local_var_resp$response_as_text(), "array[Pet]", loadNamespace("petstore")),
          error = function(e) {
            rlang::abort(message = "Failed to deserialize response",
                         .subclass = "ApiException",
                         ApiException = ApiException$new(http_response = local_var_resp))
          }
        )
        local_var_resp$content <- deserialized_resp_obj
        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))
      }
    },
    #' Find pet by ID
    #'
    #' @description
    #' Find pet by ID
    #'
    #' @param pet_id ID of pet to return
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #' @return Pet
    #' @export
    GetPetById = function(pet_id, data_file = NULL, ...) {
      local_var_response <- self$GetPetByIdWithHttpInfo(pet_id, data_file = data_file, ...)
      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
      }
    },
    #' Find pet by ID
    #'
    #' @description
    #' Find pet by ID
    #'
    #' @param pet_id ID of pet to return
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #' @return API response (Pet) with additional information such as HTTP status code, headers
    #' @export
    GetPetByIdWithHttpInfo = function(pet_id, data_file = NULL, ...) {
      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(`pet_id`)) {
        rlang::abort(message = "Missing required parameter `pet_id`.",
                     .subclass = "ApiException",
                     ApiException = ApiException$new(status = 0,
                                                     reason = "Missing required parameter `pet_id`."))
      }


      local_var_url_path <- "/pet/{petId}"
      if (!missing(`pet_id`)) {
        local_var_url_path <- gsub("\\{petId\\}", URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path)
      }

      # Bearer token
      if (!is.null(self$api_client$bearer_token)) {
        header_params["Authorization"] <- paste("Bearer", self$api_client$bearer_token, sep = " ")
      }

      # The Accept request HTTP header
      local_var_accepts <- list("application/xml", "application/json")

      # 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) {
        # save response in a file
        if (!is.null(data_file)) {
          write(local_var_resp$response, data_file)
        }

        deserialized_resp_obj <- tryCatch(
          self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")),
          error = function(e) {
            rlang::abort(message = "Failed to deserialize response",
                         .subclass = "ApiException",
                         ApiException = ApiException$new(http_response = local_var_resp))
          }
        )
        local_var_resp$content <- deserialized_resp_obj
        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))
      }
    },
    #' Find pet by ID (streaming)
    #'
    #' @description
    #' Find pet by ID (streaming)
    #'
    #' @param pet_id ID of pet to return
    #' @param stream_callback (optional) callback function to process the data stream
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #' @return Pet
    #' @export
    GetPetByIdStreaming = function(pet_id, stream_callback = NULL, data_file = NULL, ...) {
      local_var_response <- self$GetPetByIdStreamingWithHttpInfo(pet_id, stream_callback = stream_callback, data_file = data_file, ...)
      if (typeof(stream_callback) == "closure") { # return void if streaming is enabled
        return(invisible(NULL))
      }

      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
      }
    },
    #' Find pet by ID (streaming)
    #'
    #' @description
    #' Find pet by ID (streaming)
    #'
    #' @param pet_id ID of pet to return
    #' @param stream_callback (optional) callback function to process the data stream
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #' @return API response (Pet) with additional information such as HTTP status code, headers
    #' @export
    GetPetByIdStreamingWithHttpInfo = function(pet_id, stream_callback = NULL, data_file = NULL, ...) {
      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(`pet_id`)) {
        rlang::abort(message = "Missing required parameter `pet_id`.",
                     .subclass = "ApiException",
                     ApiException = ApiException$new(status = 0,
                                                     reason = "Missing required parameter `pet_id`."))
      }


      local_var_url_path <- "/pet/{petId}?streaming"
      if (!missing(`pet_id`)) {
        local_var_url_path <- gsub("\\{petId\\}", URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path)
      }

      # API key authentication
      if ("api_key" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["api_key"]) > 0) {
        header_params["api_key"] <- paste(unlist(self$api_client$api_keys["api_key"]), collapse = "")
      }

      # The Accept request HTTP header
      local_var_accepts <- list("application/xml", "application/json")

      # 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,
                                 stream_callback = stream_callback,
                                 ...)

      if (typeof(stream_callback) == "closure") { # return void if streaming is enabled
        return(invisible(NULL))
      }

      if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) {
        # save response in a file
        if (!is.null(data_file)) {
          write(local_var_resp$response, data_file)
        }

        deserialized_resp_obj <- tryCatch(
          self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")),
          error = function(e) {
            rlang::abort(message = "Failed to deserialize response",
                         .subclass = "ApiException",
                         ApiException = ApiException$new(http_response = local_var_resp))
          }
        )
        local_var_resp$content <- deserialized_resp_obj
        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))
      }
    },
    #' Header test
    #'
    #' @description
    #' Header test
    #'
    #' @param header_test_int header test int
    #' @param stream_callback (optional) callback function to process the data stream
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #' @return Pet
    #' @export
    TestHeader = function(header_test_int, stream_callback = NULL, data_file = NULL, ...) {
      local_var_response <- self$TestHeaderWithHttpInfo(header_test_int, stream_callback = stream_callback, data_file = data_file, ...)
      if (typeof(stream_callback) == "closure") { # return void if streaming is enabled
        return(invisible(NULL))
      }

      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
      }
    },
    #' Header test
    #'
    #' @description
    #' Header test
    #'
    #' @param header_test_int header test int
    #' @param stream_callback (optional) callback function to process the data stream
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #' @return API response (Pet) with additional information such as HTTP status code, headers
    #' @export
    TestHeaderWithHttpInfo = function(header_test_int, stream_callback = NULL, data_file = NULL, ...) {
      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(`header_test_int`)) {
        rlang::abort(message = "Missing required parameter `header_test_int`.",
                     .subclass = "ApiException",
                     ApiException = ApiException$new(status = 0,
                                                     reason = "Missing required parameter `header_test_int`."))
      }


      header_params["header_test_int"] <- `header_test_int`

      local_var_url_path <- "/pet_header_test"
      # API key authentication
      if ("api_key" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["api_key"]) > 0) {
        header_params["api_key"] <- paste(unlist(self$api_client$api_keys["api_key"]), collapse = "")
      }

      # The Accept request HTTP header
      local_var_accepts <- list("application/xml", "application/json")

      # 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,
                                 stream_callback = stream_callback,
                                 ...)

      if (typeof(stream_callback) == "closure") { # return void if streaming is enabled
        return(invisible(NULL))
      }

      if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) {
        # save response in a file
        if (!is.null(data_file)) {
          write(local_var_resp$response, data_file)
        }

        deserialized_resp_obj <- tryCatch(
          self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")),
          error = function(e) {
            rlang::abort(message = "Failed to deserialize response",
                         .subclass = "ApiException",
                         ApiException = ApiException$new(http_response = local_var_resp))
          }
        )
        local_var_resp$content <- deserialized_resp_obj
        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))
      }
    },
    #' Update an existing pet
    #'
    #' @description
    #' Update an existing pet
    #'
    #' @param pet Pet object that needs to be added to the store
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #' @return Pet
    #' @export
    UpdatePet = function(pet, data_file = NULL, ...) {
      local_var_response <- self$UpdatePetWithHttpInfo(pet, data_file = data_file, ...)
      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
      }
    },
    #' Update an existing pet
    #'
    #' @description
    #' Update an existing pet
    #'
    #' @param pet Pet object that needs to be added to the store
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #' @return API response (Pet) with additional information such as HTTP status code, headers
    #' @export
    UpdatePetWithHttpInfo = function(pet, data_file = NULL, ...) {
      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(`pet`)) {
        rlang::abort(message = "Missing required parameter `pet`.",
                     .subclass = "ApiException",
                     ApiException = ApiException$new(status = 0,
                                                     reason = "Missing required parameter `pet`."))
      }


      if (!is.null(`pet`)) {
        local_var_body <- `pet`$toJSONString()
      } else {
        body <- NULL
      }

      local_var_url_path <- "/pet"
      # OAuth-related settings
      is_oauth <- TRUE
      oauth_scopes <- "write:pets read:pets"

      # The Accept request HTTP header
      local_var_accepts <- list("application/xml", "application/json")

      # The Content-Type representation header
      local_var_content_types <- list("application/json", "application/xml", "multipart/related")

      local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path),
                                 method = "PUT",
                                 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) {
        # save response in a file
        if (!is.null(data_file)) {
          write(local_var_resp$response, data_file)
        }

        deserialized_resp_obj <- tryCatch(
          self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")),
          error = function(e) {
            rlang::abort(message = "Failed to deserialize response",
                         .subclass = "ApiException",
                         ApiException = ApiException$new(http_response = local_var_resp))
          }
        )
        local_var_resp$content <- deserialized_resp_obj
        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))
      }
    },
    #' Updates a pet in the store with form data
    #'
    #' @description
    #' Updates a pet in the store with form data
    #'
    #' @param pet_id ID of pet that needs to be updated
    #' @param name (optional) Updated name of the pet
    #' @param status (optional) Updated status of the pet
    #' @param ... Other optional arguments
    #' @return void
    #' @export
    UpdatePetWithForm = function(pet_id, name = NULL, status = NULL, ...) {
      local_var_response <- self$UpdatePetWithFormWithHttpInfo(pet_id, name, status, ...)
      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
      }
    },
    #' Updates a pet in the store with form data
    #'
    #' @description
    #' Updates a pet in the store with form data
    #'
    #' @param pet_id ID of pet that needs to be updated
    #' @param name (optional) Updated name of the pet
    #' @param status (optional) Updated status of the pet
    #' @param ... Other optional arguments
    #' @return API response (void) with additional information such as HTTP status code, headers
    #' @export
    UpdatePetWithFormWithHttpInfo = function(pet_id, name = NULL, status = NULL, ...) {
      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(`pet_id`)) {
        rlang::abort(message = "Missing required parameter `pet_id`.",
                     .subclass = "ApiException",
                     ApiException = ApiException$new(status = 0,
                                                     reason = "Missing required parameter `pet_id`."))
      }




      form_params["name"] <- `name`
      form_params["status"] <- `status`
      local_var_url_path <- "/pet/{petId}"
      if (!missing(`pet_id`)) {
        local_var_url_path <- gsub("\\{petId\\}", URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path)
      }


      # The Accept request HTTP header
      local_var_accepts <- list()

      # The Content-Type representation header
      local_var_content_types <- list("application/x-www-form-urlencoded")

      local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path),
                                 method = "POST",
                                 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))
      }
    },
    #' uploads an image
    #'
    #' @description
    #' uploads an image
    #'
    #' @param pet_id ID of pet to update
    #' @param additional_metadata (optional) Additional data to pass to server
    #' @param file (optional) file to upload
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #' @return ModelApiResponse
    #' @export
    UploadFile = function(pet_id, additional_metadata = NULL, file = NULL, data_file = NULL, ...) {
      local_var_response <- self$UploadFileWithHttpInfo(pet_id, additional_metadata, file, data_file = data_file, ...)
      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
      }
    },
    #' uploads an image
    #'
    #' @description
    #' uploads an image
    #'
    #' @param pet_id ID of pet to update
    #' @param additional_metadata (optional) Additional data to pass to server
    #' @param file (optional) file to upload
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #' @return API response (ModelApiResponse) with additional information such as HTTP status code, headers
    #' @export
    UploadFileWithHttpInfo = function(pet_id, additional_metadata = NULL, file = NULL, data_file = NULL, ...) {
      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(`pet_id`)) {
        rlang::abort(message = "Missing required parameter `pet_id`.",
                     .subclass = "ApiException",
                     ApiException = ApiException$new(status = 0,
                                                     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"
      if (!missing(`pet_id`)) {
        local_var_url_path <- gsub("\\{petId\\}", URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path)
      }

      # OAuth-related settings
      is_oauth <- TRUE
      oauth_scopes <- "write:pets read:pets"

      # The Accept request HTTP header
      local_var_accepts <- list("application/json")

      # The Content-Type representation header
      local_var_content_types <- list("multipart/form-data")

      local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path),
                                 method = "POST",
                                 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) {
        # save response in a file
        if (!is.null(data_file)) {
          write(local_var_resp$response, data_file)
        }

        deserialized_resp_obj <- tryCatch(
          self$api_client$deserialize(local_var_resp$response_as_text(), "ModelApiResponse", loadNamespace("petstore")),
          error = function(e) {
            rlang::abort(message = "Failed to deserialize response",
                         .subclass = "ApiException",
                         ApiException = ApiException$new(http_response = local_var_resp))
          }
        )
        local_var_resp$content <- deserialized_resp_obj
        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))
      }
    }
  )
)
