From f287dde8754cd4fece52fea43842db4911149fe0 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sun, 7 Aug 2022 21:49:04 +0800 Subject: [PATCH] [R][httr2] better support for OAuth authoriziation flows (#13123) * better oauth support in r client * better comment * update samples * remove commented code * update samples * fix mustache tag --- .../codegen/languages/RClientCodegen.java | 1 - .../src/main/resources/r/README.mustache | 8 + .../src/main/resources/r/api.mustache | 24 ++- .../src/main/resources/r/api_client.mustache | 34 +++++ .../r/libraries/httr2/api_client.mustache | 109 +++++++++----- .../src/test/resources/3_0/r/petstore.yaml | 8 +- .../client/petstore/R-httr2/R/api_client.R | 95 +++++++----- samples/client/petstore/R-httr2/R/fake_api.R | 8 +- samples/client/petstore/R-httr2/R/pet_api.R | 142 ++++++++++++------ samples/client/petstore/R-httr2/R/store_api.R | 32 +++- samples/client/petstore/R-httr2/R/user_api.R | 64 ++++++-- .../client/petstore/R-httr2/docs/PetApi.md | 4 +- .../R-httr2/tests/testthat/test_petstore.R | 2 + samples/client/petstore/R/R/api_client.R | 22 +++ samples/client/petstore/R/R/fake_api.R | 8 +- samples/client/petstore/R/R/pet_api.R | 142 ++++++++++++------ samples/client/petstore/R/R/store_api.R | 32 +++- samples/client/petstore/R/R/user_api.R | 64 ++++++-- samples/client/petstore/R/docs/PetApi.md | 4 +- .../petstore/R/tests/testthat/test_petstore.R | 3 + 20 files changed, 580 insertions(+), 226 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java index 8952cb8ad57..50acd1c6d9e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java @@ -279,7 +279,6 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig { supportingFiles.add(new SupportingFile("Rbuildignore.mustache", "", ".Rbuildignore")); supportingFiles.add(new SupportingFile(".travis.yml", "", ".travis.yml")); supportingFiles.add(new SupportingFile("ApiResponse.mustache", File.separator + "R", "api_response.R")); - //supportingFiles.add(new SupportingFile("element.mustache", File.separator + "R", "Element.R")); supportingFiles.add(new SupportingFile("api_client.mustache", File.separator + "R", "api_client.R")); supportingFiles.add(new SupportingFile("NAMESPACE.mustache", "", "NAMESPACE")); supportingFiles.add(new SupportingFile("testthat.mustache", File.separator + "tests", "testthat.R")); diff --git a/modules/openapi-generator/src/main/resources/r/README.mustache b/modules/openapi-generator/src/main/resources/r/README.mustache index 40b284a54cc..3b06a18e515 100644 --- a/modules/openapi-generator/src/main/resources/r/README.mustache +++ b/modules/openapi-generator/src/main/resources/r/README.mustache @@ -105,7 +105,15 @@ Class | Method | HTTP request | Description {{#isOAuth}} - **Type**: OAuth - **Flow**: {{flow}} +{{#authorizationUrl}} - **Authorization URL**: {{authorizationUrl}} +{{/authorizationUrl}} +{{#tokenUrl}} +- **Token URL**: {{tokenUrl}} +{{/tokenUrl}} +{{#refreshUrl}} +- **Refresh URL**: {{refreshUrl}} +{{/refreshUrl}} - **Scopes**: {{^scopes}}N/A{{/scopes}} {{#scopes}} - {{scope}}: {{description}} {{/scopes}} diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index 1df5a69287c..377ffbca446 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -238,6 +238,8 @@ form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE {{#requiredParams}} if (missing(`{{paramName}}`)) { @@ -435,18 +437,28 @@ {{/isKeyInQuery}} {{/isApiKey}} {{#isOAuth}} - # OAuth token - if (!is.null(self$api_client$access_token)) { - header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ") + # OAuth-related settings + if (is.null(self$api_client$oauth_client_id) || is.null(self$api_client$oauth_secret)) { + {{#useDefaultExceptionHandling}} + stop("oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `{{{operationId}}}`.") + {{/useDefaultExceptionHandling}} + {{#useRlangExceptionHandling}} + rlang::abort(message = "oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `{{{operationId}}}`.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `{{{operationId}}}`.")) + {{/useRlangExceptionHandling}} } + is_oauth <- TRUE + oauth_scopes <- "{{#scopes}}{{scope}}{{^-last}} {{/-last}}{{/scopes}}" {{/isOAuth}} {{/authMethods}} # The Accept request HTTP header - local_var_accepts = list({{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}}) + local_var_accepts <- list({{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}}) # The Content-Type representation header - local_var_content_types = list({{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}}) + local_var_content_types <- list({{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}}) local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path), method = "{{httpMethod}}", @@ -457,6 +469,8 @@ accepts = local_var_accepts, content_types = local_var_content_types, body = local_var_body, + is_oauth = is_oauth, + oauth_scopes = oauth_scopes, {{#vendorExtensions.x-streaming}} stream_callback = stream_callback, {{/vendorExtensions.x-streaming}} diff --git a/modules/openapi-generator/src/main/resources/r/api_client.mustache b/modules/openapi-generator/src/main/resources/r/api_client.mustache index a1553f67e46..2e6e6b839d1 100644 --- a/modules/openapi-generator/src/main/resources/r/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/r/api_client.mustache @@ -21,7 +21,20 @@ #' @field username Username for HTTP basic authentication #' @field password Password for HTTP basic authentication #' @field api_keys API keys +{{#hasOAuthMethods}} #' @field access_token Access token +#' @field oauth_client_id OAuth client ID +#' @field oauth_secret OAuth secret +#' @field oauth_refresh_token OAuth refresh token +{{#authMethods}} +{{#isOAuth}} +#' @field oauth_flow_type OAuth flow type +#' @field oauth_authorization_url Authoriziation URL +#' @field oauth_token_url Token URL +#' @field oauth_pkce Boolean flag to enable PKCE +{{/isOAuth}} +{{/authMethods}} +{{/hasOAuthMethods}} #' @field bearer_token Bearer token #' @field timeout Default timeout in seconds #' @field retry_status_codes vector of status codes to retry @@ -46,8 +59,29 @@ ApiClient <- R6::R6Class( password = NULL, # API keys api_keys = NULL, + {{#hasOAuthMethods}} # Access token access_token = NULL, + # OAuth2 client ID + oauth_client_id = NULL, + # OAuth2 secret + oauth_secret = NULL, + # OAuth2 refresh token + oauth_refresh_token = NULL, + # OAuth2 + {{#authMethods}} + {{#isOAuth}} + # Flow type + oauth_flow_type = "{{flow}}", + # Authoriziation URL + oauth_authorization_url = "{{authorizationUrl}}", + # Token URL + oauth_token_url = "{{tokenUrl}}", + # Enable PKCE? + oauth_pkce = TRUE, + {{/isOAuth}} + {{/authMethods}} + {{/hasOAuthMethods}} # Bearer token bearer_token = NULL, # Time Out (seconds) diff --git a/modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache b/modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache index 1a76b56d198..ea138ef2b36 100644 --- a/modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache @@ -21,7 +21,20 @@ #' @field username Username for HTTP basic authentication #' @field password Password for HTTP basic authentication #' @field api_keys API keys +{{#hasOAuthMethods}} #' @field access_token Access token +#' @field oauth_client_id OAuth client ID +#' @field oauth_secret OAuth secret +#' @field oauth_refresh_token OAuth refresh token +{{#authMethods}} +{{#isOAuth}} +#' @field oauth_flow_type OAuth flow type +#' @field oauth_authorization_url Authoriziation URL +#' @field oauth_token_url Token URL +#' @field oauth_pkce Boolean flag to enable PKCE +{{/isOAuth}} +{{/authMethods}} +{{/hasOAuthMethods}} #' @field bearer_token Bearer token #' @field timeout Default timeout in seconds #' @field retry_status_codes vector of status codes to retry @@ -46,8 +59,29 @@ ApiClient <- R6::R6Class( password = NULL, # API keys api_keys = NULL, + {{#hasOAuthMethods}} # Access token access_token = NULL, + # OAuth2 client ID + oauth_client_id = NULL, + # OAuth2 secret + oauth_secret = NULL, + # OAuth2 refresh token + oauth_refresh_token = NULL, + # OAuth2 + {{#authMethods}} + {{#isOAuth}} + # Flow type + oauth_flow_type = "{{flow}}", + # Authoriziation URL + oauth_authorization_url = "{{authorizationUrl}}", + # Token URL + oauth_token_url = "{{tokenUrl}}", + # Enable PKCE? + oauth_pkce = TRUE, + {{/isOAuth}} + {{/authMethods}} + {{/hasOAuthMethods}} # Bearer token bearer_token = NULL, # Time Out (seconds) @@ -134,47 +168,33 @@ ApiClient <- R6::R6Class( #' @param query_params The query parameters. #' @param header_params The header parameters. #' @param form_params The form parameters. - #' @param file_params The form parameters to upload files + #' @param file_params The form parameters to upload files. #' @param accepts The HTTP accpet headers. #' @param content_types The HTTP content-type headers. #' @param body The HTTP request body. - #' @param stream_callback Callback function to process the data stream + #' @param is_oauth True if the endpoints required OAuth authentication. + #' @param oauth_scoeps OAuth scopes. + #' @param stream_callback Callback function to process the data stream. #' @param ... Other optional arguments. #' @return HTTP response #' @export - CallApi = function(url, method, query_params, header_params, form_params, file_params, - accepts, content_types, body, stream_callback = NULL, ...) { + CallApi = function(url, method, query_params, header_params, form_params, + file_params, accepts, content_types, body, + is_oauth = FALSE, oauth_scopes = NULL, stream_callback = NULL, ...) { - resp <- self$Execute(url, method, query_params, header_params, form_params, - file_params, accepts, content_types, - body, stream_callback = stream_callback, ...) - #status_code <- httr::status_code(resp) + # set the URL + req <- request(url) - #if (is.null(self$max_retry_attempts)) { - # self$req_retry(max_tries <- max_retry_attempts) - #} - - #if (!is.null(self$retry_status_codes)) { - - # for (i in 1 : self$max_retry_attempts) { - # if (status_code %in% self$retry_status_codes) { - # Sys.sleep((2 ^ i) + stats::runif(n = 1, min = 0, max = 1)) - # resp <- self$Execute(url, method, query_params, header_params, body, stream_callback = stream_callback, ...) - # status_code <- httr::status_code(resp) - # } else { - # break - # } - # } - #} - - resp + resp <- self$Execute(req, method, query_params, header_params, form_params, + file_params, accepts, content_types, body, is_oauth = is_oauth, + oauth_scopes = oauth_scopes, stream_callback = stream_callback, ...) }, #' Make an API call #' #' @description #' Make an API call #' - #' @param url URL. + #' @param req httr2 request. #' @param method HTTP method. #' @param query_params The query parameters. #' @param header_params The header parameters. @@ -183,14 +203,15 @@ ApiClient <- R6::R6Class( #' @param accepts The HTTP accpet headers. #' @param content_types The HTTP content-type headers. #' @param body The HTTP request body. - #' @param stream_callback Callback function to process data stream + #' @param is_oauth True if the endpoints required OAuth authentication. + #' @param oauth_scoeps OAuth scopes. + #' @param stream_callback Callback function to process data stream. #' @param ... Other optional arguments. #' @return HTTP response #' @export - Execute = function(url, method, query_params, header_params, form_params, file_params, - accepts, content_types, body, stream_callback = NULL, ...) { - # set the URL - req <- request(url) + Execute = function(req, method, query_params, header_params, form_params, + file_params, accepts, content_types, body, + is_oauth = FALSE, oauth_scopes = NULL, stream_callback = NULL, ...) { ## add headers req <- req %>% req_headers(!!!header_params) @@ -253,6 +274,21 @@ ApiClient <- R6::R6Class( # set HTTP verb req <- req %>% req_method(method) + {{#hasOAuthMethods}} + # use oauth authentication if the endpoint requires it + if (is_oauth) { + client <- oauth_client( + id = self$oauth_client_id, + secret = obfuscated(self$oauth_secret), + token_url = self$oauth_token_url, + name = "{{packageName}}-oauth" + ) + req <- req %>% req_oauth_auth_code(client, scope = oauth_scopes, + pkce = self$oauth_pkce, + auth_url = self$oauth_authoriziation_url) + } + + {{/hasOAuthMethods}} # stream data if (typeof(stream_callback) == "closure") { req %>% req_stream(stream_callback) @@ -286,12 +322,12 @@ ApiClient <- R6::R6Class( resp_obj <- jsonlite::fromJSON(raw_response) self$deserializeObj(resp_obj, return_type, pkg_env) }, - #' Deserialize the response from jsonlite object based on the given type + #' Deserialize the response from jsonlite object based on the given type. #' #' @description - #' Deserialize the response from jsonlite object based on the given type + #' Deserialize the response from jsonlite object based on the given type. #' by handling complex and nested types by iterating recursively - #' Example return_types will be like "array[integer]", "map(Pet)", "array[map(Tag)]", etc., + #' Example return_types will be like "array[integer]", "map(Pet)", "array[map(Tag)]", etc. #' #' @param obj Response object. #' @param return_type R return type. @@ -345,8 +381,7 @@ ApiClient <- R6::R6Class( } return_obj }, - #' Return a propery header (for accept or content-type). If JSON-related MIME is found, - #' return it. Otherwise, return the first one, if any. + #' Return a propery header (for accept or content-type). #' #' @description #' Return a propery header (for accept or content-type). If JSON-related MIME is found, 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 b97af0500aa..67b47ef5181 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 @@ -200,10 +200,10 @@ paths: responses: '405': description: Invalid input - security: - - petstore_auth: - - 'write:pets' - - 'read:pets' + #security: + # - petstore_auth: + # - 'write:pets' + # - 'read:pets' requestBody: content: application/x-www-form-urlencoded: diff --git a/samples/client/petstore/R-httr2/R/api_client.R b/samples/client/petstore/R-httr2/R/api_client.R index 11ae43bd931..64fdd510a3e 100644 --- a/samples/client/petstore/R-httr2/R/api_client.R +++ b/samples/client/petstore/R-httr2/R/api_client.R @@ -29,6 +29,13 @@ #' @field password Password for HTTP basic authentication #' @field api_keys API keys #' @field access_token Access token +#' @field oauth_client_id OAuth client ID +#' @field oauth_secret OAuth secret +#' @field oauth_refresh_token OAuth refresh token +#' @field oauth_flow_type OAuth flow type +#' @field oauth_authorization_url Authoriziation URL +#' @field oauth_token_url Token URL +#' @field oauth_pkce Boolean flag to enable PKCE #' @field bearer_token Bearer token #' @field timeout Default timeout in seconds #' @field retry_status_codes vector of status codes to retry @@ -53,6 +60,21 @@ ApiClient <- R6::R6Class( api_keys = NULL, # Access token access_token = NULL, + # OAuth2 client ID + oauth_client_id = NULL, + # OAuth2 secret + oauth_secret = NULL, + # OAuth2 refresh token + oauth_refresh_token = NULL, + # OAuth2 + # Flow type + oauth_flow_type = "implicit", + # Authoriziation URL + oauth_authorization_url = "http://petstore.swagger.io/api/oauth/dialog", + # Token URL + oauth_token_url = "", + # Enable PKCE? + oauth_pkce = TRUE, # Bearer token bearer_token = NULL, # Time Out (seconds) @@ -139,47 +161,33 @@ ApiClient <- R6::R6Class( #' @param query_params The query parameters. #' @param header_params The header parameters. #' @param form_params The form parameters. - #' @param file_params The form parameters to upload files + #' @param file_params The form parameters to upload files. #' @param accepts The HTTP accpet headers. #' @param content_types The HTTP content-type headers. #' @param body The HTTP request body. - #' @param stream_callback Callback function to process the data stream + #' @param is_oauth True if the endpoints required OAuth authentication. + #' @param oauth_scoeps OAuth scopes. + #' @param stream_callback Callback function to process the data stream. #' @param ... Other optional arguments. #' @return HTTP response #' @export - CallApi = function(url, method, query_params, header_params, form_params, file_params, - accepts, content_types, body, stream_callback = NULL, ...) { + CallApi = function(url, method, query_params, header_params, form_params, + file_params, accepts, content_types, body, + is_oauth = FALSE, oauth_scopes = NULL, stream_callback = NULL, ...) { - resp <- self$Execute(url, method, query_params, header_params, form_params, - file_params, accepts, content_types, - body, stream_callback = stream_callback, ...) - #status_code <- httr::status_code(resp) + # set the URL + req <- request(url) - #if (is.null(self$max_retry_attempts)) { - # self$req_retry(max_tries <- max_retry_attempts) - #} - - #if (!is.null(self$retry_status_codes)) { - - # for (i in 1 : self$max_retry_attempts) { - # if (status_code %in% self$retry_status_codes) { - # Sys.sleep((2 ^ i) + stats::runif(n = 1, min = 0, max = 1)) - # resp <- self$Execute(url, method, query_params, header_params, body, stream_callback = stream_callback, ...) - # status_code <- httr::status_code(resp) - # } else { - # break - # } - # } - #} - - resp + resp <- self$Execute(req, method, query_params, header_params, form_params, + file_params, accepts, content_types, body, is_oauth = is_oauth, + oauth_scopes = oauth_scopes, stream_callback = stream_callback, ...) }, #' Make an API call #' #' @description #' Make an API call #' - #' @param url URL. + #' @param req httr2 request. #' @param method HTTP method. #' @param query_params The query parameters. #' @param header_params The header parameters. @@ -188,14 +196,15 @@ ApiClient <- R6::R6Class( #' @param accepts The HTTP accpet headers. #' @param content_types The HTTP content-type headers. #' @param body The HTTP request body. - #' @param stream_callback Callback function to process data stream + #' @param is_oauth True if the endpoints required OAuth authentication. + #' @param oauth_scoeps OAuth scopes. + #' @param stream_callback Callback function to process data stream. #' @param ... Other optional arguments. #' @return HTTP response #' @export - Execute = function(url, method, query_params, header_params, form_params, file_params, - accepts, content_types, body, stream_callback = NULL, ...) { - # set the URL - req <- request(url) + Execute = function(req, method, query_params, header_params, form_params, + file_params, accepts, content_types, body, + is_oauth = FALSE, oauth_scopes = NULL, stream_callback = NULL, ...) { ## add headers req <- req %>% req_headers(!!!header_params) @@ -257,6 +266,19 @@ ApiClient <- R6::R6Class( # set HTTP verb req <- req %>% req_method(method) + # use oauth authentication if the endpoint requires it + if (is_oauth) { + client <- oauth_client( + id = self$oauth_client_id, + secret = obfuscated(self$oauth_secret), + token_url = self$oauth_token_url, + name = "petstore-oauth" + ) + req <- req %>% req_oauth_auth_code(client, scope = oauth_scopes, + pkce = self$oauth_pkce, + auth_url = self$oauth_authoriziation_url) + } + # stream data if (typeof(stream_callback) == "closure") { req %>% req_stream(stream_callback) @@ -290,12 +312,12 @@ ApiClient <- R6::R6Class( resp_obj <- jsonlite::fromJSON(raw_response) self$deserializeObj(resp_obj, return_type, pkg_env) }, - #' Deserialize the response from jsonlite object based on the given type + #' Deserialize the response from jsonlite object based on the given type. #' #' @description - #' Deserialize the response from jsonlite object based on the given type + #' Deserialize the response from jsonlite object based on the given type. #' by handling complex and nested types by iterating recursively - #' Example return_types will be like "array[integer]", "map(Pet)", "array[map(Tag)]", etc., + #' Example return_types will be like "array[integer]", "map(Pet)", "array[map(Tag)]", etc. #' #' @param obj Response object. #' @param return_type R return type. @@ -349,8 +371,7 @@ ApiClient <- R6::R6Class( } return_obj }, - #' Return a propery header (for accept or content-type). If JSON-related MIME is found, - #' return it. Otherwise, return the first one, if any. + #' Return a propery header (for accept or content-type). #' #' @description #' Return a propery header (for accept or content-type). If JSON-related MIME is found, diff --git a/samples/client/petstore/R-httr2/R/fake_api.R b/samples/client/petstore/R-httr2/R/fake_api.R index 29316cc62bb..ae384f97313 100644 --- a/samples/client/petstore/R-httr2/R/fake_api.R +++ b/samples/client/petstore/R-httr2/R/fake_api.R @@ -128,6 +128,8 @@ FakeApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE if (missing(`dummy`)) { rlang::abort(message = "Missing required parameter `dummy`.", @@ -145,10 +147,10 @@ FakeApi <- R6::R6Class( local_var_url_path <- "/fake/data_file" # The Accept request HTTP header - local_var_accepts = list("application/xml", "application/json") + local_var_accepts <- list("application/xml", "application/json") # The Content-Type representation header - local_var_content_types = list() + 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", @@ -159,6 +161,8 @@ FakeApi <- R6::R6Class( 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) { diff --git a/samples/client/petstore/R-httr2/R/pet_api.R b/samples/client/petstore/R-httr2/R/pet_api.R index 1cca443a90e..303fb961653 100644 --- a/samples/client/petstore/R-httr2/R/pet_api.R +++ b/samples/client/petstore/R-httr2/R/pet_api.R @@ -522,9 +522,6 @@ #' #Updates a pet in the store with form data #' api.instance <- PetApi$new() #' -#' # Configure OAuth2 access token for authorization: petstore_auth -#' api.instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN'; -#' #'result <- tryCatch( #' api.instance$update_pet_with_form(var.pet_id, name=var.name, status=var.status), #' ApiException = function(ex) ex @@ -632,6 +629,8 @@ PetApi <- R6::R6Class( 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`.", @@ -658,10 +657,10 @@ PetApi <- R6::R6Class( 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") + 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_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", @@ -672,6 +671,8 @@ PetApi <- R6::R6Class( 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) { @@ -755,6 +756,8 @@ PetApi <- R6::R6Class( 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`.", @@ -772,16 +775,21 @@ PetApi <- R6::R6Class( local_var_url_path <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) } - # OAuth token - if (!is.null(self$api_client$access_token)) { - header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ") + # OAuth-related settings + if (is.null(self$api_client$oauth_client_id) || is.null(self$api_client$oauth_secret)) { + rlang::abort(message = "oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `delete_pet`.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `delete_pet`.")) } + is_oauth <- TRUE + oauth_scopes <- "write:pets read:pets" # The Accept request HTTP header - local_var_accepts = list() + local_var_accepts <- list() # The Content-Type representation header - local_var_content_types = list() + 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", @@ -792,6 +800,8 @@ PetApi <- R6::R6Class( 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) { @@ -862,6 +872,8 @@ PetApi <- R6::R6Class( 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`.", @@ -874,16 +886,21 @@ PetApi <- R6::R6Class( query_params["status"] <- `status` local_var_url_path <- "/pet/findByStatus" - # OAuth token - if (!is.null(self$api_client$access_token)) { - header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ") + # OAuth-related settings + if (is.null(self$api_client$oauth_client_id) || is.null(self$api_client$oauth_secret)) { + rlang::abort(message = "oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `find_pets_by_status`.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `find_pets_by_status`.")) } + is_oauth <- TRUE + oauth_scopes <- "read:pets" # The Accept request HTTP header - local_var_accepts = list("application/xml", "application/json") + local_var_accepts <- list("application/xml", "application/json") # The Content-Type representation header - local_var_content_types = list() + 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", @@ -894,6 +911,8 @@ PetApi <- R6::R6Class( 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) { @@ -977,6 +996,8 @@ PetApi <- R6::R6Class( 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`.", @@ -989,16 +1010,21 @@ PetApi <- R6::R6Class( query_params["tags"] <- `tags` local_var_url_path <- "/pet/findByTags" - # OAuth token - if (!is.null(self$api_client$access_token)) { - header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ") + # OAuth-related settings + if (is.null(self$api_client$oauth_client_id) || is.null(self$api_client$oauth_secret)) { + rlang::abort(message = "oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `find_pets_by_tags`.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `find_pets_by_tags`.")) } + is_oauth <- TRUE + oauth_scopes <- "read:pets" # The Accept request HTTP header - local_var_accepts = list("application/xml", "application/json") + local_var_accepts <- list("application/xml", "application/json") # The Content-Type representation header - local_var_content_types = list() + 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", @@ -1009,6 +1035,8 @@ PetApi <- R6::R6Class( 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) { @@ -1092,6 +1120,8 @@ PetApi <- R6::R6Class( 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`.", @@ -1112,10 +1142,10 @@ PetApi <- R6::R6Class( } # The Accept request HTTP header - local_var_accepts = list("application/xml", "application/json") + local_var_accepts <- list("application/xml", "application/json") # The Content-Type representation header - local_var_content_types = list() + 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", @@ -1126,6 +1156,8 @@ PetApi <- R6::R6Class( 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) { @@ -1215,6 +1247,8 @@ PetApi <- R6::R6Class( 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`.", @@ -1235,10 +1269,10 @@ PetApi <- R6::R6Class( } # The Accept request HTTP header - local_var_accepts = list("application/xml", "application/json") + local_var_accepts <- list("application/xml", "application/json") # The Content-Type representation header - local_var_content_types = list() + 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", @@ -1249,6 +1283,8 @@ PetApi <- R6::R6Class( 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, ...) @@ -1343,6 +1379,8 @@ PetApi <- R6::R6Class( 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`.", @@ -1361,10 +1399,10 @@ PetApi <- R6::R6Class( } # The Accept request HTTP header - local_var_accepts = list("application/xml", "application/json") + local_var_accepts <- list("application/xml", "application/json") # The Content-Type representation header - local_var_content_types = list() + 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", @@ -1375,6 +1413,8 @@ PetApi <- R6::R6Class( 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, ...) @@ -1463,6 +1503,8 @@ PetApi <- R6::R6Class( 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`.", @@ -1479,16 +1521,21 @@ PetApi <- R6::R6Class( } local_var_url_path <- "/pet" - # OAuth token - if (!is.null(self$api_client$access_token)) { - header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ") + # OAuth-related settings + if (is.null(self$api_client$oauth_client_id) || is.null(self$api_client$oauth_secret)) { + rlang::abort(message = "oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `update_pet`.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `update_pet`.")) } + is_oauth <- TRUE + oauth_scopes <- "write:pets read:pets" # The Accept request HTTP header - local_var_accepts = list("application/xml", "application/json") + 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_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", @@ -1499,6 +1546,8 @@ PetApi <- R6::R6Class( 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) { @@ -1584,6 +1633,8 @@ PetApi <- R6::R6Class( 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`.", @@ -1602,16 +1653,12 @@ PetApi <- R6::R6Class( local_var_url_path <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) } - # OAuth token - if (!is.null(self$api_client$access_token)) { - header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ") - } # The Accept request HTTP header - local_var_accepts = list() + local_var_accepts <- list() # The Content-Type representation header - local_var_content_types = list("application/x-www-form-urlencoded") + 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", @@ -1622,6 +1669,8 @@ PetApi <- R6::R6Class( 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) { @@ -1696,6 +1745,8 @@ PetApi <- R6::R6Class( 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`.", @@ -1714,16 +1765,21 @@ PetApi <- R6::R6Class( local_var_url_path <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) } - # OAuth token - if (!is.null(self$api_client$access_token)) { - header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ") + # OAuth-related settings + if (is.null(self$api_client$oauth_client_id) || is.null(self$api_client$oauth_secret)) { + rlang::abort(message = "oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `upload_file`.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `upload_file`.")) } + is_oauth <- TRUE + oauth_scopes <- "write:pets read:pets" # The Accept request HTTP header - local_var_accepts = list("application/json") + local_var_accepts <- list("application/json") # The Content-Type representation header - local_var_content_types = list("multipart/form-data") + 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", @@ -1734,6 +1790,8 @@ PetApi <- R6::R6Class( 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) { diff --git a/samples/client/petstore/R-httr2/R/store_api.R b/samples/client/petstore/R-httr2/R/store_api.R index 42d301a3b2d..40d031caa27 100644 --- a/samples/client/petstore/R-httr2/R/store_api.R +++ b/samples/client/petstore/R-httr2/R/store_api.R @@ -276,6 +276,8 @@ StoreApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE if (missing(`order_id`)) { rlang::abort(message = "Missing required parameter `order_id`.", @@ -292,10 +294,10 @@ StoreApi <- R6::R6Class( # The Accept request HTTP header - local_var_accepts = list() + local_var_accepts <- list() # The Content-Type representation header - local_var_content_types = list() + 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", @@ -306,6 +308,8 @@ StoreApi <- R6::R6Class( 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) { @@ -374,6 +378,8 @@ StoreApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE local_var_url_path <- "/store/inventory" # API key authentication @@ -382,10 +388,10 @@ StoreApi <- R6::R6Class( } # The Accept request HTTP header - local_var_accepts = list("application/json") + local_var_accepts <- list("application/json") # The Content-Type representation header - local_var_content_types = list() + 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", @@ -396,6 +402,8 @@ StoreApi <- R6::R6Class( 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) { @@ -479,6 +487,8 @@ StoreApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE if (missing(`order_id`)) { rlang::abort(message = "Missing required parameter `order_id`.", @@ -507,10 +517,10 @@ StoreApi <- R6::R6Class( # The Accept request HTTP header - local_var_accepts = list("application/xml", "application/json") + local_var_accepts <- list("application/xml", "application/json") # The Content-Type representation header - local_var_content_types = list() + 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", @@ -521,6 +531,8 @@ StoreApi <- R6::R6Class( 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) { @@ -604,6 +616,8 @@ StoreApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE if (missing(`order`)) { rlang::abort(message = "Missing required parameter `order`.", @@ -622,10 +636,10 @@ StoreApi <- R6::R6Class( local_var_url_path <- "/store/order" # The Accept request HTTP header - local_var_accepts = list("application/xml", "application/json") + local_var_accepts <- list("application/xml", "application/json") # The Content-Type representation header - local_var_content_types = list("application/json") + local_var_content_types <- list("application/json") local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path), method = "POST", @@ -636,6 +650,8 @@ StoreApi <- R6::R6Class( 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) { diff --git a/samples/client/petstore/R-httr2/R/user_api.R b/samples/client/petstore/R-httr2/R/user_api.R index 8a4bf8a28f8..9231eb5e3fc 100644 --- a/samples/client/petstore/R-httr2/R/user_api.R +++ b/samples/client/petstore/R-httr2/R/user_api.R @@ -462,6 +462,8 @@ UserApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE if (missing(`user`)) { rlang::abort(message = "Missing required parameter `user`.", @@ -484,10 +486,10 @@ UserApi <- R6::R6Class( } # The Accept request HTTP header - local_var_accepts = list() + local_var_accepts <- list() # The Content-Type representation header - local_var_content_types = list("application/json") + local_var_content_types <- list("application/json") local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path), method = "POST", @@ -498,6 +500,8 @@ UserApi <- R6::R6Class( 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) { @@ -566,6 +570,8 @@ UserApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE if (missing(`user`)) { rlang::abort(message = "Missing required parameter `user`.", @@ -591,10 +597,10 @@ UserApi <- R6::R6Class( } # The Accept request HTTP header - local_var_accepts = list() + local_var_accepts <- list() # The Content-Type representation header - local_var_content_types = list("application/json") + local_var_content_types <- list("application/json") local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path), method = "POST", @@ -605,6 +611,8 @@ UserApi <- R6::R6Class( 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) { @@ -673,6 +681,8 @@ UserApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE if (missing(`user`)) { rlang::abort(message = "Missing required parameter `user`.", @@ -698,10 +708,10 @@ UserApi <- R6::R6Class( } # The Accept request HTTP header - local_var_accepts = list() + local_var_accepts <- list() # The Content-Type representation header - local_var_content_types = list("application/json") + local_var_content_types <- list("application/json") local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path), method = "POST", @@ -712,6 +722,8 @@ UserApi <- R6::R6Class( 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) { @@ -780,6 +792,8 @@ UserApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE if (missing(`username`)) { rlang::abort(message = "Missing required parameter `username`.", @@ -800,10 +814,10 @@ UserApi <- R6::R6Class( } # The Accept request HTTP header - local_var_accepts = list() + local_var_accepts <- list() # The Content-Type representation header - local_var_content_types = list() + 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", @@ -814,6 +828,8 @@ UserApi <- R6::R6Class( 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) { @@ -884,6 +900,8 @@ UserApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE if (missing(`username`)) { rlang::abort(message = "Missing required parameter `username`.", @@ -900,10 +918,10 @@ UserApi <- R6::R6Class( # The Accept request HTTP header - local_var_accepts = list("application/xml", "application/json") + local_var_accepts <- list("application/xml", "application/json") # The Content-Type representation header - local_var_content_types = list() + 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", @@ -914,6 +932,8 @@ UserApi <- R6::R6Class( 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) { @@ -999,6 +1019,8 @@ UserApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE if (missing(`username`)) { rlang::abort(message = "Missing required parameter `username`.", @@ -1029,10 +1051,10 @@ UserApi <- R6::R6Class( local_var_url_path <- "/user/login" # The Accept request HTTP header - local_var_accepts = list("application/xml", "application/json") + local_var_accepts <- list("application/xml", "application/json") # The Content-Type representation header - local_var_content_types = list() + 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", @@ -1043,6 +1065,8 @@ UserApi <- R6::R6Class( 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) { @@ -1122,6 +1146,8 @@ UserApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE local_var_url_path <- "/user/logout" # API key authentication @@ -1130,10 +1156,10 @@ UserApi <- R6::R6Class( } # The Accept request HTTP header - local_var_accepts = list() + local_var_accepts <- list() # The Content-Type representation header - local_var_content_types = list() + 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", @@ -1144,6 +1170,8 @@ UserApi <- R6::R6Class( 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) { @@ -1214,6 +1242,8 @@ UserApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE if (missing(`username`)) { rlang::abort(message = "Missing required parameter `username`.", @@ -1248,10 +1278,10 @@ UserApi <- R6::R6Class( } # The Accept request HTTP header - local_var_accepts = list() + local_var_accepts <- list() # The Content-Type representation header - local_var_content_types = list("application/json") + local_var_content_types <- list("application/json") local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path), method = "PUT", @@ -1262,6 +1292,8 @@ UserApi <- R6::R6Class( 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) { diff --git a/samples/client/petstore/R-httr2/docs/PetApi.md b/samples/client/petstore/R-httr2/docs/PetApi.md index 2498a03ae7a..f323e6ebc9d 100644 --- a/samples/client/petstore/R-httr2/docs/PetApi.md +++ b/samples/client/petstore/R-httr2/docs/PetApi.md @@ -534,8 +534,6 @@ var_status <- "status_example" # character | Updated status of the pet (Optional #Updates a pet in the store with form data 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$update_pet_with_form(var_pet_id, name = var_name, status = var_status), ApiException = function(ex) ex @@ -564,7 +562,7 @@ void (empty response body) ### Authorization -[petstore_auth](../README.md#petstore_auth) +No authorization required ### HTTP request headers diff --git a/samples/client/petstore/R-httr2/tests/testthat/test_petstore.R b/samples/client/petstore/R-httr2/tests/testthat/test_petstore.R index d0e7088c464..ad50729bd8d 100644 --- a/samples/client/petstore/R-httr2/tests/testthat/test_petstore.R +++ b/samples/client/petstore/R-httr2/tests/testthat/test_petstore.R @@ -112,6 +112,8 @@ test_that("update_pet_with_form", { result <- pet_api$add_pet(update_pet) ## update pet with form + pet_api$api_client$oauth_client_id <- "client_id_aaa" + pet_api$api_client$oauth_secret <- "secrete_bbb" update_result <- pet_api$update_pet_with_form(update_pet_id, name = "pet2", status = "sold") # get pet diff --git a/samples/client/petstore/R/R/api_client.R b/samples/client/petstore/R/R/api_client.R index 870cb82c45c..2d32c0f9b20 100644 --- a/samples/client/petstore/R/R/api_client.R +++ b/samples/client/petstore/R/R/api_client.R @@ -29,6 +29,13 @@ #' @field password Password for HTTP basic authentication #' @field api_keys API keys #' @field access_token Access token +#' @field oauth_client_id OAuth client ID +#' @field oauth_secret OAuth secret +#' @field oauth_refresh_token OAuth refresh token +#' @field oauth_flow_type OAuth flow type +#' @field oauth_authorization_url Authoriziation URL +#' @field oauth_token_url Token URL +#' @field oauth_pkce Boolean flag to enable PKCE #' @field bearer_token Bearer token #' @field timeout Default timeout in seconds #' @field retry_status_codes vector of status codes to retry @@ -53,6 +60,21 @@ ApiClient <- R6::R6Class( api_keys = NULL, # Access token access_token = NULL, + # OAuth2 client ID + oauth_client_id = NULL, + # OAuth2 secret + oauth_secret = NULL, + # OAuth2 refresh token + oauth_refresh_token = NULL, + # OAuth2 + # Flow type + oauth_flow_type = "implicit", + # Authoriziation URL + oauth_authorization_url = "http://petstore.swagger.io/api/oauth/dialog", + # Token URL + oauth_token_url = "", + # Enable PKCE? + oauth_pkce = TRUE, # Bearer token bearer_token = NULL, # Time Out (seconds) diff --git a/samples/client/petstore/R/R/fake_api.R b/samples/client/petstore/R/R/fake_api.R index e35d774b06a..c320097ab80 100644 --- a/samples/client/petstore/R/R/fake_api.R +++ b/samples/client/petstore/R/R/fake_api.R @@ -128,6 +128,8 @@ FakeApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE if (missing(`dummy`)) { rlang::abort(message = "Missing required parameter `dummy`.", @@ -145,10 +147,10 @@ FakeApi <- R6::R6Class( local_var_url_path <- "/fake/data_file" # The Accept request HTTP header - local_var_accepts = list("application/xml", "application/json") + local_var_accepts <- list("application/xml", "application/json") # The Content-Type representation header - local_var_content_types = list() + 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", @@ -159,6 +161,8 @@ FakeApi <- R6::R6Class( 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) { diff --git a/samples/client/petstore/R/R/pet_api.R b/samples/client/petstore/R/R/pet_api.R index 3743f84c2d9..dcc0c09ddd9 100644 --- a/samples/client/petstore/R/R/pet_api.R +++ b/samples/client/petstore/R/R/pet_api.R @@ -522,9 +522,6 @@ #' #Updates a pet in the store with form data #' api.instance <- PetApi$new() #' -#' # Configure OAuth2 access token for authorization: petstore_auth -#' api.instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN'; -#' #'result <- tryCatch( #' api.instance$UpdatePetWithForm(var.pet_id, name=var.name, status=var.status), #' ApiException = function(ex) ex @@ -632,6 +629,8 @@ PetApi <- R6::R6Class( 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`.", @@ -658,10 +657,10 @@ PetApi <- R6::R6Class( 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") + 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_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", @@ -672,6 +671,8 @@ PetApi <- R6::R6Class( 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) { @@ -755,6 +756,8 @@ PetApi <- R6::R6Class( 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`.", @@ -772,16 +775,21 @@ PetApi <- R6::R6Class( local_var_url_path <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) } - # OAuth token - if (!is.null(self$api_client$access_token)) { - header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ") + # OAuth-related settings + if (is.null(self$api_client$oauth_client_id) || is.null(self$api_client$oauth_secret)) { + rlang::abort(message = "oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `DeletePet`.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `DeletePet`.")) } + is_oauth <- TRUE + oauth_scopes <- "write:pets read:pets" # The Accept request HTTP header - local_var_accepts = list() + local_var_accepts <- list() # The Content-Type representation header - local_var_content_types = list() + 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", @@ -792,6 +800,8 @@ PetApi <- R6::R6Class( 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) { @@ -862,6 +872,8 @@ PetApi <- R6::R6Class( 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`.", @@ -874,16 +886,21 @@ PetApi <- R6::R6Class( query_params["status"] <- `status` local_var_url_path <- "/pet/findByStatus" - # OAuth token - if (!is.null(self$api_client$access_token)) { - header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ") + # OAuth-related settings + if (is.null(self$api_client$oauth_client_id) || is.null(self$api_client$oauth_secret)) { + rlang::abort(message = "oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `FindPetsByStatus`.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `FindPetsByStatus`.")) } + is_oauth <- TRUE + oauth_scopes <- "read:pets" # The Accept request HTTP header - local_var_accepts = list("application/xml", "application/json") + local_var_accepts <- list("application/xml", "application/json") # The Content-Type representation header - local_var_content_types = list() + 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", @@ -894,6 +911,8 @@ PetApi <- R6::R6Class( 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) { @@ -977,6 +996,8 @@ PetApi <- R6::R6Class( 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`.", @@ -989,16 +1010,21 @@ PetApi <- R6::R6Class( query_params["tags"] <- `tags` local_var_url_path <- "/pet/findByTags" - # OAuth token - if (!is.null(self$api_client$access_token)) { - header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ") + # OAuth-related settings + if (is.null(self$api_client$oauth_client_id) || is.null(self$api_client$oauth_secret)) { + rlang::abort(message = "oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `FindPetsByTags`.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `FindPetsByTags`.")) } + is_oauth <- TRUE + oauth_scopes <- "read:pets" # The Accept request HTTP header - local_var_accepts = list("application/xml", "application/json") + local_var_accepts <- list("application/xml", "application/json") # The Content-Type representation header - local_var_content_types = list() + 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", @@ -1009,6 +1035,8 @@ PetApi <- R6::R6Class( 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) { @@ -1092,6 +1120,8 @@ PetApi <- R6::R6Class( 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`.", @@ -1112,10 +1142,10 @@ PetApi <- R6::R6Class( } # The Accept request HTTP header - local_var_accepts = list("application/xml", "application/json") + local_var_accepts <- list("application/xml", "application/json") # The Content-Type representation header - local_var_content_types = list() + 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", @@ -1126,6 +1156,8 @@ PetApi <- R6::R6Class( 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) { @@ -1215,6 +1247,8 @@ PetApi <- R6::R6Class( 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`.", @@ -1235,10 +1269,10 @@ PetApi <- R6::R6Class( } # The Accept request HTTP header - local_var_accepts = list("application/xml", "application/json") + local_var_accepts <- list("application/xml", "application/json") # The Content-Type representation header - local_var_content_types = list() + 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", @@ -1249,6 +1283,8 @@ PetApi <- R6::R6Class( 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, ...) @@ -1343,6 +1379,8 @@ PetApi <- R6::R6Class( 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`.", @@ -1361,10 +1399,10 @@ PetApi <- R6::R6Class( } # The Accept request HTTP header - local_var_accepts = list("application/xml", "application/json") + local_var_accepts <- list("application/xml", "application/json") # The Content-Type representation header - local_var_content_types = list() + 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", @@ -1375,6 +1413,8 @@ PetApi <- R6::R6Class( 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, ...) @@ -1463,6 +1503,8 @@ PetApi <- R6::R6Class( 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`.", @@ -1479,16 +1521,21 @@ PetApi <- R6::R6Class( } local_var_url_path <- "/pet" - # OAuth token - if (!is.null(self$api_client$access_token)) { - header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ") + # OAuth-related settings + if (is.null(self$api_client$oauth_client_id) || is.null(self$api_client$oauth_secret)) { + rlang::abort(message = "oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `UpdatePet`.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `UpdatePet`.")) } + is_oauth <- TRUE + oauth_scopes <- "write:pets read:pets" # The Accept request HTTP header - local_var_accepts = list("application/xml", "application/json") + 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_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", @@ -1499,6 +1546,8 @@ PetApi <- R6::R6Class( 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) { @@ -1584,6 +1633,8 @@ PetApi <- R6::R6Class( 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`.", @@ -1602,16 +1653,12 @@ PetApi <- R6::R6Class( local_var_url_path <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) } - # OAuth token - if (!is.null(self$api_client$access_token)) { - header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ") - } # The Accept request HTTP header - local_var_accepts = list() + local_var_accepts <- list() # The Content-Type representation header - local_var_content_types = list("application/x-www-form-urlencoded") + 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", @@ -1622,6 +1669,8 @@ PetApi <- R6::R6Class( 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) { @@ -1696,6 +1745,8 @@ PetApi <- R6::R6Class( 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`.", @@ -1714,16 +1765,21 @@ PetApi <- R6::R6Class( local_var_url_path <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) } - # OAuth token - if (!is.null(self$api_client$access_token)) { - header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ") + # OAuth-related settings + if (is.null(self$api_client$oauth_client_id) || is.null(self$api_client$oauth_secret)) { + rlang::abort(message = "oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `UploadFile`.", + .subclass = "ApiException", + ApiException = ApiException$new(status = 0, + reason = "oauth_client_id, oauth_secret in `api_client` must be set for authentication in the endpoint `UploadFile`.")) } + is_oauth <- TRUE + oauth_scopes <- "write:pets read:pets" # The Accept request HTTP header - local_var_accepts = list("application/json") + local_var_accepts <- list("application/json") # The Content-Type representation header - local_var_content_types = list("multipart/form-data") + 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", @@ -1734,6 +1790,8 @@ PetApi <- R6::R6Class( 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) { diff --git a/samples/client/petstore/R/R/store_api.R b/samples/client/petstore/R/R/store_api.R index a93dd2a5062..3d513000ae3 100644 --- a/samples/client/petstore/R/R/store_api.R +++ b/samples/client/petstore/R/R/store_api.R @@ -276,6 +276,8 @@ StoreApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE if (missing(`order_id`)) { rlang::abort(message = "Missing required parameter `order_id`.", @@ -292,10 +294,10 @@ StoreApi <- R6::R6Class( # The Accept request HTTP header - local_var_accepts = list() + local_var_accepts <- list() # The Content-Type representation header - local_var_content_types = list() + 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", @@ -306,6 +308,8 @@ StoreApi <- R6::R6Class( 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) { @@ -374,6 +378,8 @@ StoreApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE local_var_url_path <- "/store/inventory" # API key authentication @@ -382,10 +388,10 @@ StoreApi <- R6::R6Class( } # The Accept request HTTP header - local_var_accepts = list("application/json") + local_var_accepts <- list("application/json") # The Content-Type representation header - local_var_content_types = list() + 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", @@ -396,6 +402,8 @@ StoreApi <- R6::R6Class( 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) { @@ -479,6 +487,8 @@ StoreApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE if (missing(`order_id`)) { rlang::abort(message = "Missing required parameter `order_id`.", @@ -507,10 +517,10 @@ StoreApi <- R6::R6Class( # The Accept request HTTP header - local_var_accepts = list("application/xml", "application/json") + local_var_accepts <- list("application/xml", "application/json") # The Content-Type representation header - local_var_content_types = list() + 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", @@ -521,6 +531,8 @@ StoreApi <- R6::R6Class( 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) { @@ -604,6 +616,8 @@ StoreApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE if (missing(`order`)) { rlang::abort(message = "Missing required parameter `order`.", @@ -622,10 +636,10 @@ StoreApi <- R6::R6Class( local_var_url_path <- "/store/order" # The Accept request HTTP header - local_var_accepts = list("application/xml", "application/json") + local_var_accepts <- list("application/xml", "application/json") # The Content-Type representation header - local_var_content_types = list("application/json") + local_var_content_types <- list("application/json") local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path), method = "POST", @@ -636,6 +650,8 @@ StoreApi <- R6::R6Class( 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) { diff --git a/samples/client/petstore/R/R/user_api.R b/samples/client/petstore/R/R/user_api.R index ce6b4444d4c..491129a2618 100644 --- a/samples/client/petstore/R/R/user_api.R +++ b/samples/client/petstore/R/R/user_api.R @@ -462,6 +462,8 @@ UserApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE if (missing(`user`)) { rlang::abort(message = "Missing required parameter `user`.", @@ -484,10 +486,10 @@ UserApi <- R6::R6Class( } # The Accept request HTTP header - local_var_accepts = list() + local_var_accepts <- list() # The Content-Type representation header - local_var_content_types = list("application/json") + local_var_content_types <- list("application/json") local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path), method = "POST", @@ -498,6 +500,8 @@ UserApi <- R6::R6Class( 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) { @@ -566,6 +570,8 @@ UserApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE if (missing(`user`)) { rlang::abort(message = "Missing required parameter `user`.", @@ -591,10 +597,10 @@ UserApi <- R6::R6Class( } # The Accept request HTTP header - local_var_accepts = list() + local_var_accepts <- list() # The Content-Type representation header - local_var_content_types = list("application/json") + local_var_content_types <- list("application/json") local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path), method = "POST", @@ -605,6 +611,8 @@ UserApi <- R6::R6Class( 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) { @@ -673,6 +681,8 @@ UserApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE if (missing(`user`)) { rlang::abort(message = "Missing required parameter `user`.", @@ -698,10 +708,10 @@ UserApi <- R6::R6Class( } # The Accept request HTTP header - local_var_accepts = list() + local_var_accepts <- list() # The Content-Type representation header - local_var_content_types = list("application/json") + local_var_content_types <- list("application/json") local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path), method = "POST", @@ -712,6 +722,8 @@ UserApi <- R6::R6Class( 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) { @@ -780,6 +792,8 @@ UserApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE if (missing(`username`)) { rlang::abort(message = "Missing required parameter `username`.", @@ -800,10 +814,10 @@ UserApi <- R6::R6Class( } # The Accept request HTTP header - local_var_accepts = list() + local_var_accepts <- list() # The Content-Type representation header - local_var_content_types = list() + 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", @@ -814,6 +828,8 @@ UserApi <- R6::R6Class( 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) { @@ -884,6 +900,8 @@ UserApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE if (missing(`username`)) { rlang::abort(message = "Missing required parameter `username`.", @@ -900,10 +918,10 @@ UserApi <- R6::R6Class( # The Accept request HTTP header - local_var_accepts = list("application/xml", "application/json") + local_var_accepts <- list("application/xml", "application/json") # The Content-Type representation header - local_var_content_types = list() + 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", @@ -914,6 +932,8 @@ UserApi <- R6::R6Class( 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) { @@ -999,6 +1019,8 @@ UserApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE if (missing(`username`)) { rlang::abort(message = "Missing required parameter `username`.", @@ -1029,10 +1051,10 @@ UserApi <- R6::R6Class( local_var_url_path <- "/user/login" # The Accept request HTTP header - local_var_accepts = list("application/xml", "application/json") + local_var_accepts <- list("application/xml", "application/json") # The Content-Type representation header - local_var_content_types = list() + 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", @@ -1043,6 +1065,8 @@ UserApi <- R6::R6Class( 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) { @@ -1122,6 +1146,8 @@ UserApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE local_var_url_path <- "/user/logout" # API key authentication @@ -1130,10 +1156,10 @@ UserApi <- R6::R6Class( } # The Accept request HTTP header - local_var_accepts = list() + local_var_accepts <- list() # The Content-Type representation header - local_var_content_types = list() + 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", @@ -1144,6 +1170,8 @@ UserApi <- R6::R6Class( 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) { @@ -1214,6 +1242,8 @@ UserApi <- R6::R6Class( form_params <- list() file_params <- list() local_var_body <- NULL + oauth_scopes <- NULL + is_oauth <- FALSE if (missing(`username`)) { rlang::abort(message = "Missing required parameter `username`.", @@ -1248,10 +1278,10 @@ UserApi <- R6::R6Class( } # The Accept request HTTP header - local_var_accepts = list() + local_var_accepts <- list() # The Content-Type representation header - local_var_content_types = list("application/json") + local_var_content_types <- list("application/json") local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path), method = "PUT", @@ -1262,6 +1292,8 @@ UserApi <- R6::R6Class( 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) { diff --git a/samples/client/petstore/R/docs/PetApi.md b/samples/client/petstore/R/docs/PetApi.md index 4c6bae4a7e5..3053f3b9860 100644 --- a/samples/client/petstore/R/docs/PetApi.md +++ b/samples/client/petstore/R/docs/PetApi.md @@ -534,8 +534,6 @@ var_status <- "status_example" # character | Updated status of the pet (Optional #Updates a pet in the store with form data 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$UpdatePetWithForm(var_pet_id, name = var_name, status = var_status), ApiException = function(ex) ex @@ -564,7 +562,7 @@ void (empty response body) ### Authorization -[petstore_auth](../README.md#petstore_auth) +No authorization required ### HTTP request headers diff --git a/samples/client/petstore/R/tests/testthat/test_petstore.R b/samples/client/petstore/R/tests/testthat/test_petstore.R index 903993395dd..da38644bad3 100644 --- a/samples/client/petstore/R/tests/testthat/test_petstore.R +++ b/samples/client/petstore/R/tests/testthat/test_petstore.R @@ -22,6 +22,9 @@ test_that("Test toJSONString", { }) test_that("Test FindPetByStatus", { + pet_api$api_client$oauth_client_id <- "client_id_test" + pet_api$api_client$oauth_secret <- "secret_test" + result <- pet_api$FindPetsByStatus("available") expect_equal(result[[1]]$status, "available") })