add http basic test in r client (#12978)

This commit is contained in:
William Cheng 2022-07-22 10:01:48 +08:00 committed by GitHub
parent f26985c239
commit 6e6c2f9a0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 10 deletions

View File

@ -38,9 +38,7 @@ paths:
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
- http_auth: []
requestBody:
$ref: '#/components/requestBodies/Pet'
put:
@ -671,6 +669,9 @@ components:
description: Pet object that needs to be added to the store
required: true
securitySchemes:
http_auth:
type : http
scheme : basic
BearerToken:
type : http
scheme : bearer

View File

@ -262,8 +262,11 @@
#' #Add a new pet to the store
#' api.instance <- PetApi$new()
#'
#' # Configure OAuth2 access token for authorization: petstore_auth
#' api.instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN';
#' #Configure HTTP basic authorization: http_auth
#' # provide the username
#' api.instance$api_client$username <- 'TODO_YOUR_USERNAME';
#' # provide the password
#' api.instance$api_client$password <- 'TODO_YOUR_PASSWORD';
#'
#'result <- tryCatch(
#' api.instance$AddPet(var.pet),
@ -582,8 +585,8 @@ PetApi <- R6::R6Class(
}
url_path <- "/pet"
# OAuth token
header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ")
# HTTP basic auth
header_params["Authorization"] <- paste("Basic", base64enc::base64encode(charToRaw(paste(self$api_client$username, self$api_client$password, sep = ":"))))
resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "POST",

View File

@ -121,6 +121,10 @@ Class | Method | HTTP request | Description
- **API key parameter name**: api_key
- **Location**: HTTP header
### http_auth
- **Type**: HTTP basic authentication
### petstore_auth
- **Type**: OAuth

View File

@ -30,8 +30,9 @@ var_pet <- Pet$new("name_example", list("photoUrls_example"), 123, Category$new(
#Add a new pet to the store
api_instance <- PetApi$new()
# Configure OAuth2 access token for authorization: petstore_auth
api_instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN';
# Configure HTTP basic authorization: http_auth
api_instance$api_client$username <- 'TODO_YOUR_USERNAME';
api_instance$api_client$password <- 'TODO_YOUR_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"),
@ -63,7 +64,7 @@ Name | Type | Description | Notes
### Authorization
[petstore_auth](../README.md#petstore_auth)
[http_auth](../README.md#http_auth)
### HTTP request headers

View File

@ -11,6 +11,8 @@ pet <- Pet$new("name_test",
),
status = "available"
)
pet_api$api_client$username <- "username123"
pet_api$api_client$password <- "password123"
result <- pet_api$AddPet(pet)
test_that("AddPet", {