forked from loafle/openapi-generator-original
[R] support explode (true/false) in query array parameters (#13364)
* fix query parameters (explode or not) in r client * add tests
This commit is contained in:
parent
4c19eca929
commit
f98753aa8b
@ -382,12 +382,19 @@
|
|||||||
{{/headerParams}}
|
{{/headerParams}}
|
||||||
{{#queryParams}}
|
{{#queryParams}}
|
||||||
{{#isArray}}
|
{{#isArray}}
|
||||||
|
{{#isExplode}}
|
||||||
|
# explore
|
||||||
for (query_item in `{{{paramName}}}`) {
|
for (query_item in `{{{paramName}}}`) {
|
||||||
query_params[["{{{baseName}}}"]] <- c(query_params[["{{{baseName}}}"]], list(`{{{baseName}}}` = query_item))
|
query_params[["{{{baseName}}}"]] <- c(query_params[["{{{baseName}}}"]], list(`{{{baseName}}}` = query_item))
|
||||||
}
|
}
|
||||||
|
{{/isExplode}}
|
||||||
|
{{^isExplode}}
|
||||||
|
# no explore
|
||||||
|
query_params[["{{{baseName}}}"]] <- I(paste(lapply(`{{{paramName}}}`, URLencode, reserved = TRUE), collapse = ","))
|
||||||
|
{{/isExplode}}
|
||||||
{{/isArray}}
|
{{/isArray}}
|
||||||
{{^isArray}}
|
{{^isArray}}
|
||||||
query_params["{{baseName}}"] <- `{{paramName}}`
|
query_params[["{{baseName}}"]] <- `{{paramName}}`
|
||||||
{{/isArray}}
|
{{/isArray}}
|
||||||
|
|
||||||
{{/queryParams}}
|
{{/queryParams}}
|
||||||
|
@ -234,8 +234,15 @@ ApiClient <- R6::R6Class(
|
|||||||
}
|
}
|
||||||
|
|
||||||
## add query parameters
|
## add query parameters
|
||||||
for (query_param in query_params) {
|
for (query_param in names(query_params)) {
|
||||||
req <- req %>% req_url_query(!!!query_param)
|
if (typeof(query_params[[query_param]]) == "list") {
|
||||||
|
# for explode, e.g. a=1,a=2,a=3
|
||||||
|
req <- req %>% req_url_query(!!!query_params[[query_param]])
|
||||||
|
} else { # for non-explode, e.g. a=1,2,3
|
||||||
|
tmp <- list()
|
||||||
|
tmp[[query_param]] <- query_params[[query_param]]
|
||||||
|
req <- req %>% req_url_query(!!!tmp)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# has file upload?
|
# has file upload?
|
||||||
|
@ -82,7 +82,7 @@ paths:
|
|||||||
description: Status values that need to be considered for filter
|
description: Status values that need to be considered for filter
|
||||||
required: true
|
required: true
|
||||||
style: form
|
style: form
|
||||||
explode: false
|
explode: true # change to true for testing purpose
|
||||||
deprecated: true
|
deprecated: true
|
||||||
schema:
|
schema:
|
||||||
type: array
|
type: array
|
||||||
@ -148,9 +148,10 @@ paths:
|
|||||||
$ref: '#/components/schemas/Pet'
|
$ref: '#/components/schemas/Pet'
|
||||||
'400':
|
'400':
|
||||||
description: Invalid tag value
|
description: Invalid tag value
|
||||||
security:
|
# comment out for testing purpose
|
||||||
- petstore_auth:
|
#security:
|
||||||
- 'read:pets'
|
# - petstore_auth:
|
||||||
|
# - 'read:pets'
|
||||||
deprecated: true
|
deprecated: true
|
||||||
'/pet/{petId}':
|
'/pet/{petId}':
|
||||||
get:
|
get:
|
||||||
|
@ -226,8 +226,15 @@ ApiClient <- R6::R6Class(
|
|||||||
}
|
}
|
||||||
|
|
||||||
## add query parameters
|
## add query parameters
|
||||||
for (query_param in query_params) {
|
for (query_param in names(query_params)) {
|
||||||
req <- req %>% req_url_query(!!!query_param)
|
if (typeof(query_params[[query_param]]) == "list") {
|
||||||
|
# for explode, e.g. a=1,a=2,a=3
|
||||||
|
req <- req %>% req_url_query(!!!query_params[[query_param]])
|
||||||
|
} else { # for non-explode, e.g. a=1,2,3
|
||||||
|
tmp <- list()
|
||||||
|
tmp[[query_param]] <- query_params[[query_param]]
|
||||||
|
req <- req %>% req_url_query(!!!tmp)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# has file upload?
|
# has file upload?
|
||||||
|
@ -395,9 +395,6 @@
|
|||||||
#' #Finds Pets by tags
|
#' #Finds Pets by tags
|
||||||
#' api_instance <- petstore_api$new()
|
#' api_instance <- petstore_api$new()
|
||||||
#'
|
#'
|
||||||
#' # Configure OAuth2 access token for authorization: petstore_auth
|
|
||||||
#' api_instance$api_client$access_token <- Sys.getenv("ACCESS_TOKEN")
|
|
||||||
#'
|
|
||||||
#' result <- tryCatch(
|
#' result <- tryCatch(
|
||||||
#'
|
#'
|
||||||
#' # to save the result into a file, simply add the optional `data_file` parameter, e.g.
|
#' # to save the result into a file, simply add the optional `data_file` parameter, e.g.
|
||||||
@ -944,6 +941,7 @@ PetApi <- R6::R6Class(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# explore
|
||||||
for (query_item in `status`) {
|
for (query_item in `status`) {
|
||||||
query_params[["status"]] <- c(query_params[["status"]], list(`status` = query_item))
|
query_params[["status"]] <- c(query_params[["status"]], list(`status` = query_item))
|
||||||
}
|
}
|
||||||
@ -1064,14 +1062,10 @@ PetApi <- R6::R6Class(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (query_item in `tags`) {
|
# no explore
|
||||||
query_params[["tags"]] <- c(query_params[["tags"]], list(`tags` = query_item))
|
query_params[["tags"]] <- I(paste(lapply(`tags`, URLencode, reserved = TRUE), collapse = ","))
|
||||||
}
|
|
||||||
|
|
||||||
local_var_url_path <- "/pet/findByTags"
|
local_var_url_path <- "/pet/findByTags"
|
||||||
# OAuth-related settings
|
|
||||||
is_oauth <- TRUE
|
|
||||||
oauth_scopes <- "read:pets"
|
|
||||||
|
|
||||||
# The Accept request HTTP header
|
# The Accept request HTTP header
|
||||||
local_var_accepts <- list("application/xml", "application/json")
|
local_var_accepts <- list("application/xml", "application/json")
|
||||||
|
@ -1071,9 +1071,9 @@ UserApi <- R6::R6Class(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
query_params["username"] <- `username`
|
query_params[["username"]] <- `username`
|
||||||
|
|
||||||
query_params["password"] <- `password`
|
query_params[["password"]] <- `password`
|
||||||
|
|
||||||
local_var_url_path <- "/user/login"
|
local_var_url_path <- "/user/login"
|
||||||
|
|
||||||
|
@ -213,8 +213,6 @@ var_tags <- list("inner_example") # array[character] | Tags to filter by
|
|||||||
|
|
||||||
# Finds Pets by tags
|
# Finds Pets by tags
|
||||||
api_instance <- petstore_api$new()
|
api_instance <- petstore_api$new()
|
||||||
# Configure OAuth2 access token for authorization: petstore_auth
|
|
||||||
api_instance$api_client$access_token <- Sys.getenv("ACCESS_TOKEN")
|
|
||||||
result <- tryCatch(
|
result <- tryCatch(
|
||||||
# to save the result into a file, simply add the optional `data_file` parameter, e.g.
|
# to save the result into a file, simply add the optional `data_file` parameter, e.g.
|
||||||
# api_instance$pet_api$find_pets_by_tags(var_tags, data_file = "result.txt"),
|
# api_instance$pet_api$find_pets_by_tags(var_tags, data_file = "result.txt"),
|
||||||
@ -247,7 +245,7 @@ Name | Type | Description | Notes
|
|||||||
|
|
||||||
### Authorization
|
### Authorization
|
||||||
|
|
||||||
[petstore_auth](../README.md#petstore_auth)
|
No authorization required
|
||||||
|
|
||||||
### HTTP request headers
|
### HTTP request headers
|
||||||
|
|
||||||
|
@ -3,7 +3,33 @@ install.packages("petstore_1.0.0.tar.gz",repos=NULL, type="source")
|
|||||||
library(petstore)
|
library(petstore)
|
||||||
library(jsonlite)
|
library(jsonlite)
|
||||||
|
|
||||||
var_tags <- list("innerzzzzzzz", "second_example", "345") # array[character] | Tags to filter by
|
var_status <- list("something inside", "explode please", "123") # array[character] | Status values that need to be considered for filter
|
||||||
|
|
||||||
|
# Finds Pets by status
|
||||||
|
api_instance <- petstore_api$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$pet_api$find_pets_by_status(var_status, data_file = "result.txt"),
|
||||||
|
api_instance$pet_api$find_pets_by_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 `find_pets_by_status`:")
|
||||||
|
dput(result$ApiException$toString())
|
||||||
|
# error object
|
||||||
|
dput(result$ApiException$error_object$toJSONString())
|
||||||
|
} else {
|
||||||
|
# deserialized response object
|
||||||
|
print("The response is ...")
|
||||||
|
dput(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var_tags <- c("innerzzzzzzz", "second,example", "345") # array[character] | Tags to filter by
|
||||||
|
|
||||||
# Finds Pets by tags
|
# Finds Pets by tags
|
||||||
api_instance <- petstore_api$new()
|
api_instance <- petstore_api$new()
|
||||||
|
@ -234,6 +234,35 @@ test_that("GetPetById with data_file", {
|
|||||||
expect_equal(response$name, "name_test")
|
expect_equal(response$name, "name_test")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test_that("find_pets_by_status", {
|
||||||
|
pet_tag_test <- Pet$new("name_test",
|
||||||
|
photoUrls = list("photo_test", "second test"),
|
||||||
|
category = Category$new(id = 4455, name = "test_cat"),
|
||||||
|
id = 4455,
|
||||||
|
tags = list(
|
||||||
|
Tag$new(id = 4455, name = "tag_test"), Tag$new(id = 488, name = "unknown 2")
|
||||||
|
),
|
||||||
|
status = "available"
|
||||||
|
)
|
||||||
|
result <- pet_api$add_pet(pet_tag_test)
|
||||||
|
|
||||||
|
# vector as input
|
||||||
|
var_tags <- c("unknown", "unknown 2") # array[character] | Tags to filter by
|
||||||
|
result <- pet_api$find_pets_by_tags(var_tags)
|
||||||
|
expect_true(!is.null(result))
|
||||||
|
expect_equal(result[[1]]$id, 123321)
|
||||||
|
expect_equal(result[[2]]$id, 123999)
|
||||||
|
expect_equal(result[[3]]$id, 4455)
|
||||||
|
|
||||||
|
# list as input
|
||||||
|
var_tags <- list("unknown", "unknown 2") # array[character] | Tags to filter by
|
||||||
|
result <- pet_api$find_pets_by_tags(var_tags)
|
||||||
|
expect_true(!is.null(result))
|
||||||
|
expect_equal(result[[1]]$id, 123321)
|
||||||
|
expect_equal(result[[2]]$id, 123999)
|
||||||
|
expect_equal(result[[3]]$id, 4455)
|
||||||
|
})
|
||||||
|
|
||||||
test_that("Tests allOf", {
|
test_that("Tests allOf", {
|
||||||
# test allOf without discriminator
|
# test allOf without discriminator
|
||||||
a1 <- AllofTagApiResponse$new(id = 450, name = "test_cat", code = 200, type = "test_type", message = "test_message")
|
a1 <- AllofTagApiResponse$new(id = 450, name = "test_cat", code = 200, type = "test_type", message = "test_message")
|
||||||
|
@ -226,8 +226,15 @@ ApiClient <- R6::R6Class(
|
|||||||
}
|
}
|
||||||
|
|
||||||
## add query parameters
|
## add query parameters
|
||||||
for (query_param in query_params) {
|
for (query_param in names(query_params)) {
|
||||||
req <- req %>% req_url_query(!!!query_param)
|
if (typeof(query_params[[query_param]]) == "list") {
|
||||||
|
# for explode, e.g. a=1,a=2,a=3
|
||||||
|
req <- req %>% req_url_query(!!!query_params[[query_param]])
|
||||||
|
} else { # for non-explode, e.g. a=1,2,3
|
||||||
|
tmp <- list()
|
||||||
|
tmp[[query_param]] <- query_params[[query_param]]
|
||||||
|
req <- req %>% req_url_query(!!!tmp)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# has file upload?
|
# has file upload?
|
||||||
|
@ -395,9 +395,6 @@
|
|||||||
#' #Finds Pets by tags
|
#' #Finds Pets by tags
|
||||||
#' api_instance <- PetApi$new()
|
#' api_instance <- PetApi$new()
|
||||||
#'
|
#'
|
||||||
#' # Configure OAuth2 access token for authorization: petstore_auth
|
|
||||||
#' api_instance$api_client$access_token <- Sys.getenv("ACCESS_TOKEN")
|
|
||||||
#'
|
|
||||||
#' result <- tryCatch(
|
#' result <- tryCatch(
|
||||||
#'
|
#'
|
||||||
#' # to save the result into a file, simply add the optional `data_file` parameter, e.g.
|
#' # to save the result into a file, simply add the optional `data_file` parameter, e.g.
|
||||||
@ -944,6 +941,7 @@ PetApi <- R6::R6Class(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# explore
|
||||||
for (query_item in `status`) {
|
for (query_item in `status`) {
|
||||||
query_params[["status"]] <- c(query_params[["status"]], list(`status` = query_item))
|
query_params[["status"]] <- c(query_params[["status"]], list(`status` = query_item))
|
||||||
}
|
}
|
||||||
@ -1064,14 +1062,10 @@ PetApi <- R6::R6Class(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (query_item in `tags`) {
|
# no explore
|
||||||
query_params[["tags"]] <- c(query_params[["tags"]], list(`tags` = query_item))
|
query_params[["tags"]] <- I(paste(lapply(`tags`, URLencode, reserved = TRUE), collapse = ","))
|
||||||
}
|
|
||||||
|
|
||||||
local_var_url_path <- "/pet/findByTags"
|
local_var_url_path <- "/pet/findByTags"
|
||||||
# OAuth-related settings
|
|
||||||
is_oauth <- TRUE
|
|
||||||
oauth_scopes <- "read:pets"
|
|
||||||
|
|
||||||
# The Accept request HTTP header
|
# The Accept request HTTP header
|
||||||
local_var_accepts <- list("application/xml", "application/json")
|
local_var_accepts <- list("application/xml", "application/json")
|
||||||
|
@ -1071,9 +1071,9 @@ UserApi <- R6::R6Class(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
query_params["username"] <- `username`
|
query_params[["username"]] <- `username`
|
||||||
|
|
||||||
query_params["password"] <- `password`
|
query_params[["password"]] <- `password`
|
||||||
|
|
||||||
local_var_url_path <- "/user/login"
|
local_var_url_path <- "/user/login"
|
||||||
|
|
||||||
|
@ -213,8 +213,6 @@ var_tags <- list("inner_example") # array[character] | Tags to filter by
|
|||||||
|
|
||||||
# Finds Pets by tags
|
# Finds Pets by tags
|
||||||
api_instance <- PetApi$new()
|
api_instance <- PetApi$new()
|
||||||
# Configure OAuth2 access token for authorization: petstore_auth
|
|
||||||
api_instance$api_client$access_token <- Sys.getenv("ACCESS_TOKEN")
|
|
||||||
result <- tryCatch(
|
result <- tryCatch(
|
||||||
# to save the result into a file, simply add the optional `data_file` parameter, e.g.
|
# to save the result into a file, simply add the optional `data_file` parameter, e.g.
|
||||||
# api_instance$find_pets_by_tags(var_tags, data_file = "result.txt"),
|
# api_instance$find_pets_by_tags(var_tags, data_file = "result.txt"),
|
||||||
@ -247,7 +245,7 @@ Name | Type | Description | Notes
|
|||||||
|
|
||||||
### Authorization
|
### Authorization
|
||||||
|
|
||||||
[petstore_auth](../README.md#petstore_auth)
|
No authorization required
|
||||||
|
|
||||||
### HTTP request headers
|
### HTTP request headers
|
||||||
|
|
||||||
|
@ -395,9 +395,6 @@
|
|||||||
#' #Finds Pets by tags
|
#' #Finds Pets by tags
|
||||||
#' api_instance <- PetApi$new()
|
#' api_instance <- PetApi$new()
|
||||||
#'
|
#'
|
||||||
#' # Configure OAuth2 access token for authorization: petstore_auth
|
|
||||||
#' api_instance$api_client$access_token <- Sys.getenv("ACCESS_TOKEN")
|
|
||||||
#'
|
|
||||||
#' result <- tryCatch(
|
#' result <- tryCatch(
|
||||||
#'
|
#'
|
||||||
#' # to save the result into a file, simply add the optional `data_file` parameter, e.g.
|
#' # to save the result into a file, simply add the optional `data_file` parameter, e.g.
|
||||||
@ -944,6 +941,7 @@ PetApi <- R6::R6Class(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# explore
|
||||||
for (query_item in `status`) {
|
for (query_item in `status`) {
|
||||||
query_params[["status"]] <- c(query_params[["status"]], list(`status` = query_item))
|
query_params[["status"]] <- c(query_params[["status"]], list(`status` = query_item))
|
||||||
}
|
}
|
||||||
@ -1064,14 +1062,10 @@ PetApi <- R6::R6Class(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (query_item in `tags`) {
|
# no explore
|
||||||
query_params[["tags"]] <- c(query_params[["tags"]], list(`tags` = query_item))
|
query_params[["tags"]] <- I(paste(lapply(`tags`, URLencode, reserved = TRUE), collapse = ","))
|
||||||
}
|
|
||||||
|
|
||||||
local_var_url_path <- "/pet/findByTags"
|
local_var_url_path <- "/pet/findByTags"
|
||||||
# OAuth-related settings
|
|
||||||
is_oauth <- TRUE
|
|
||||||
oauth_scopes <- "read:pets"
|
|
||||||
|
|
||||||
# The Accept request HTTP header
|
# The Accept request HTTP header
|
||||||
local_var_accepts <- list("application/xml", "application/json")
|
local_var_accepts <- list("application/xml", "application/json")
|
||||||
|
@ -1071,9 +1071,9 @@ UserApi <- R6::R6Class(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
query_params["username"] <- `username`
|
query_params[["username"]] <- `username`
|
||||||
|
|
||||||
query_params["password"] <- `password`
|
query_params[["password"]] <- `password`
|
||||||
|
|
||||||
local_var_url_path <- "/user/login"
|
local_var_url_path <- "/user/login"
|
||||||
|
|
||||||
|
@ -213,8 +213,6 @@ var_tags <- list("inner_example") # array[character] | Tags to filter by
|
|||||||
|
|
||||||
# Finds Pets by tags
|
# Finds Pets by tags
|
||||||
api_instance <- PetApi$new()
|
api_instance <- PetApi$new()
|
||||||
# Configure OAuth2 access token for authorization: petstore_auth
|
|
||||||
api_instance$api_client$access_token <- Sys.getenv("ACCESS_TOKEN")
|
|
||||||
result <- tryCatch(
|
result <- tryCatch(
|
||||||
# to save the result into a file, simply add the optional `data_file` parameter, e.g.
|
# 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, data_file = "result.txt"),
|
||||||
@ -247,7 +245,7 @@ Name | Type | Description | Notes
|
|||||||
|
|
||||||
### Authorization
|
### Authorization
|
||||||
|
|
||||||
[petstore_auth](../README.md#petstore_auth)
|
No authorization required
|
||||||
|
|
||||||
### HTTP request headers
|
### HTTP request headers
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user