Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions R/generate_pkg-paths.R
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ S7::method(as_bk_data, class_paths) <- function(x) {
params <- .remove_security_args(op$params, security_arg_names)
params_query <- .prep_param_args(op$params_query_raw, security_arg_names)
params_header <- .prep_param_args(op$params_header_raw, security_arg_names)
params_cookie <- .prep_param_args(op$params_cookie_raw, security_arg_names)
args <- .params_to_args(params)
args_named <- .params_to_named_args(params)
c(
Expand All @@ -232,6 +233,7 @@ S7::method(as_bk_data, class_paths) <- function(x) {
params = params,
params_query = params_query,
params_header = params_header,
params_cookie = params_cookie,
args = args,
args_named = args_named,
test_args = args
Expand Down
4 changes: 4 additions & 0 deletions inst/templates/010-prepare.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
path,
query = list(),
body = NULL,
header = list(),
cookie = list(),
method = NULL,
tidy_policy = nectar::tidy_policy_unknown(),{{#has_security}}
{{{security_signature}}},{{/has_security}}
Expand All @@ -24,6 +26,8 @@
path = path,
query = query,
body = body,
header = header,
cookie = cookie,
method = method,
tidy_policy = tidy_policy,
call = call
Expand Down
3 changes: 2 additions & 1 deletion inst/templates/paths.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ req_{{api_abbr}}_{{operation_id}} <- function({{#args}}{{{args}}}{{/args}}{{#has
method = "{{method}}"{{#has_security}},
{{security_arg_list}}{{/has_security}}{{#params_query}},
query = list({{params_query}}){{/params_query}}{{#params_header}},
body = list({{params_header}}){{/params_header}}{{#pagination}},
header = list({{params_header}}){{/params_header}}{{#params_cookie}},
cookie = list({{params_cookie}}){{/params_cookie}}{{#pagination}},
pagination_fn = {{pagination_fn}}{{/pagination}}{{#tidy}},
tidy_policy = {{tidy_policy}}{{/tidy}}
)
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/_fixtures/guru/010-prepare.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ guru_req_prepare <- function(
path,
query = list(),
body = NULL,
header = list(),
cookie = list(),
method = NULL,
tidy_policy = nectar::tidy_policy_unknown(),
call = rlang::caller_env()) {
Expand All @@ -22,6 +24,8 @@ guru_req_prepare <- function(
path = path,
query = query,
body = body,
header = header,
cookie = cookie,
method = method,
tidy_policy = tidy_policy,
call = call
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# These functions were generated by the {beekeeper} package, based on the paths
# element from the source API description. You should carefully review these
# functions.

#' Search things
#'
#' Search for things.
#'
#' @param x_auth_token (length-1 `character`) Authentication token
#' @param session_id (length-1 `character`) Session identifier
#' @param q (length-1 `character`) Search query
#' @inheritParams .shared-params
#'
#' @returns `test_search_things()`: The API response.
#' @export
test_search_things <- function(x_auth_token, session_id, q, max_reqs = Inf, max_tries_per_req = 3) {
req <- req_test_search_things(x_auth_token = x_auth_token, session_id = session_id, q = q)
resps <- nectar::req_perform_opinionated(
req,
max_reqs = max_reqs,
max_tries_per_req = max_tries_per_req
)
return(nectar::resp_parse(resps))
}

#' @rdname test_search_things
#' @returns `req_test_search_things()`: A `httr2_request` request object.
req_test_search_things <- function(x_auth_token, session_id, q) {
test_req_prepare(
path = "/things",
method = "get",
query = list(q = q),
header = list(x_auth_token = x_auth_token),
cookie = list(session_id = session_id)
)
}
4 changes: 4 additions & 0 deletions tests/testthat/_fixtures/trello/010-prepare.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ trello_req_prepare <- function(
path,
query = list(),
body = NULL,
header = list(),
cookie = list(),
method = NULL,
tidy_policy = nectar::tidy_policy_unknown(),
key = Sys.getenv("TRELLO_KEY"),
Expand All @@ -25,6 +27,8 @@ token = Sys.getenv("TRELLO_TOKEN"),
path = path,
query = query,
body = body,
header = header,
cookie = cookie,
method = method,
tidy_policy = tidy_policy,
call = call
Expand Down
50 changes: 50 additions & 0 deletions tests/testthat/test-generate_pkg-paths.R
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,53 @@ test_that(".compile_param_class_descriptions() uses class names (#85)", {
)
)
})

test_that(".generate_paths_file() renders header and cookie params correctly (#84)", {
skip_on_cran()
expected_content <- readLines(
test_path("_fixtures", "header_cookie", "paths-things-search_things.R")
)

tmp <- withr::local_tempdir()
local_mocked_bindings(.bk_use_template_impl = make_writing_impl(tmp))

op <- list(
operation_id = "search_things",
tag = "things",
path = '"/things"',
method = "get",
summary = "Search things",
description = "Search for things.",
params = list(
list(
name = "x_auth_token",
class = "length-1 `character`",
description = "Authentication token"
),
list(
name = "session_id",
class = "length-1 `character`",
description = "Session identifier"
),
list(
name = "q",
class = "length-1 `character`",
description = "Search query"
)
),
params_query = "q = q",
params_header = "x_auth_token = x_auth_token",
params_cookie = "session_id = session_id",
args = "x_auth_token, session_id, q",
args_named = "x_auth_token = x_auth_token, session_id = session_id, q = q",
test_args = "x_auth_token, session_id, q",
pagination = FALSE,
pagination_fn = ""
)
.generate_paths_file(op, "search_things", "test", list())

expect_identical(
readLines(file.path(tmp, "R", "paths-things-search_things.R")),
expected_content
)
})
Loading