diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index e29573f23b2..e3aabd05c19 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -430,18 +430,9 @@ {{#isBasic}} {{#isBasicBasic}} # HTTP basic auth - if (is.null(self$api_client$username) || is.null(self$api_client$password)) { - {{#useDefaultExceptionHandling}} - stop("username, password in `api_client` must be set for authentication in the endpoint `{{{operationId}}}`.") - {{/useDefaultExceptionHandling}} - {{#useRlangExceptionHandling}} - rlang::abort(message = "username, password in `api_client` must be set for authentication in the endpoint `{{{operationId}}}`.", - .subclass = "ApiException", - ApiException = ApiException$new(status = 0, - reason = "username, password in `api_client` must be set for authentication in the endpoint `{{{operationId}}}`.")) - {{/useRlangExceptionHandling}} + 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 = ":")))) } - header_params["Authorization"] <- paste("Basic", base64enc::base64encode(charToRaw(paste(self$api_client$username, self$api_client$password, sep = ":")))) {{/isBasicBasic}} {{#isBasicBearer}} # Bearer token diff --git a/samples/client/petstore/R-httr2-wrapper/R/pet_api.R b/samples/client/petstore/R-httr2-wrapper/R/pet_api.R index 9867ba330f9..e2b0e92cccc 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/pet_api.R +++ b/samples/client/petstore/R-httr2-wrapper/R/pet_api.R @@ -719,13 +719,9 @@ PetApi <- R6::R6Class( local_var_url_path <- "/pet" # HTTP basic auth - if (is.null(self$api_client$username) || is.null(self$api_client$password)) { - rlang::abort(message = "username, password in `api_client` must be set for authentication in the endpoint `add_pet`.", - .subclass = "ApiException", - ApiException = ApiException$new(status = 0, - reason = "username, password in `api_client` must be set for authentication in the endpoint `add_pet`.")) + 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 = ":")))) } - 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") diff --git a/samples/client/petstore/R-httr2/R/pet_api.R b/samples/client/petstore/R-httr2/R/pet_api.R index 8ea511e551d..14319ac68a3 100644 --- a/samples/client/petstore/R-httr2/R/pet_api.R +++ b/samples/client/petstore/R-httr2/R/pet_api.R @@ -719,13 +719,9 @@ PetApi <- R6::R6Class( local_var_url_path <- "/pet" # HTTP basic auth - if (is.null(self$api_client$username) || is.null(self$api_client$password)) { - rlang::abort(message = "username, password in `api_client` must be set for authentication in the endpoint `add_pet`.", - .subclass = "ApiException", - ApiException = ApiException$new(status = 0, - reason = "username, password in `api_client` must be set for authentication in the endpoint `add_pet`.")) + 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 = ":")))) } - 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") diff --git a/samples/client/petstore/R/R/pet_api.R b/samples/client/petstore/R/R/pet_api.R index bb02aec7ee3..c107111865d 100644 --- a/samples/client/petstore/R/R/pet_api.R +++ b/samples/client/petstore/R/R/pet_api.R @@ -719,13 +719,9 @@ PetApi <- R6::R6Class( local_var_url_path <- "/pet" # HTTP basic auth - if (is.null(self$api_client$username) || is.null(self$api_client$password)) { - rlang::abort(message = "username, password in `api_client` must be set for authentication in the endpoint `AddPet`.", - .subclass = "ApiException", - ApiException = ApiException$new(status = 0, - reason = "username, password in `api_client` must be set for authentication in the endpoint `AddPet`.")) + 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 = ":")))) } - 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") diff --git a/samples/client/petstore/R/tests/testthat/test_petstore.R b/samples/client/petstore/R/tests/testthat/test_petstore.R index da38644bad3..43a642d3f0a 100644 --- a/samples/client/petstore/R/tests/testthat/test_petstore.R +++ b/samples/client/petstore/R/tests/testthat/test_petstore.R @@ -12,8 +12,10 @@ pet <- Pet$new("name_test", status = "available" ) -pet_api$api_client$username <- "" -pet_api$api_client$password <- "" +# no need to set uasername, password and there should be no error +# since the endpoint can support multi auth schema +#pet_api$api_client$username <- "" +#pet_api$api_client$password <- "" result <- pet_api$AddPet(pet) test_that("Test toJSONString", {