Skip to content

Commit 7b27c22

Browse files
authored
Update path documentation (#139)
Add documentation for all three functions in paths, but don't export the "main" function by default. This will allow (and require) the user to review each path file before the package exports things. I also discovered bugs with the use of `pkg_dir` while updating the generated fixtures, and fixed those bugs, plus brought the package back up to 100% coverage. Fixes #134.
1 parent 01778dd commit 7b27c22

88 files changed

Lines changed: 482 additions & 137 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitignore‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ inst/doc
99
exploration
1010
/_beekeeper_rapid.rds
1111
_slackapi_rapid.rds
12-
.positai
12+
.posit/assistant
1313
conversation-export.json

‎DESCRIPTION‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ VignetteBuilder:
5050
Remotes:
5151
api2r/nectar,
5252
api2r/rapid,
53+
httptest2=nealrichardson/httptest2,
5354
wranglezone/stbl,
54-
wranglezone/tibblify,
55-
httptest2=nealrichardson/httptest2
55+
wranglezone/tibblify
56+
Config/Needs/website: rmarkdown
5657
Config/roxygen2/version: 8.0.0
5758
Config/testthat/edition: 3
5859
Encoding: UTF-8
5960
Language: en-US
6061
Roxygen: list(markdown = TRUE)
6162
RoxygenNote: 8.0.0
62-
Config/Needs/website: rmarkdown

‎R/generate_pkg-pagination.R‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
#' @keywords internal
55
.generate_pagination <- function() {
66
# TODO: Accept pagination config and generate 030-pagination.R (#63)
7-
list()
7+
list() # nocov
88
}

‎R/generate_pkg-template.R‎

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
data,
1111
...,
1212
target = template,
13-
dir = c("R", "tests/testthat")
13+
dir = c("R", "tests/testthat"),
14+
pkg_dir = "."
1415
) {
1516
rlang::check_dots_empty()
1617
dir <- match.arg(dir)
17-
target <- .bk_use_template_impl(template, data, target, dir)
18+
target <- .bk_use_template_impl(template, data, target, dir, pkg_dir)
1819
return(invisible(target))
1920
}
2021

@@ -23,18 +24,23 @@
2324
#' @inheritParams .shared-params
2425
#' @returns (`character(1)`) The generated file path.
2526
#' @keywords internal
26-
.bk_use_template_impl <- function(template, data, target, dir) {
27-
target <- usethis::proj_path(dir, target)
28-
save_as <- fs::path_rel(target, usethis::proj_path())
29-
if (fs::file_exists(target)) {
30-
# TODO: Intelligently prompt about this.
31-
fs::file_delete(target)
32-
}
33-
usethis::use_template(
34-
template = template,
35-
save_as = save_as,
36-
data = data,
37-
package = "beekeeper"
27+
.bk_use_template_impl <- function(template, data, target, dir, pkg_dir = ".") {
28+
usethis::with_project(
29+
pkg_dir,
30+
{
31+
target <- usethis::proj_path(dir, target)
32+
save_as <- fs::path_rel(target, usethis::proj_path())
33+
if (fs::file_exists(target)) {
34+
# TODO: Intelligently prompt about this.
35+
fs::file_delete(target)
36+
}
37+
usethis::use_template(
38+
template = template,
39+
save_as = save_as,
40+
data = data,
41+
package = "beekeeper"
42+
)
43+
}
3844
)
3945
return(target)
4046
}

‎R/generate_pkg_auth.R‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ generate_pkg_auth <- function(
4848
.use_r_directory(pkg_dir)
4949
.use_nectar(pkg_dir)
5050
.use_pkg_beekeeper(pkg_dir)
51-
security_data <- .generate_security(api_abbr, security_schemes)
51+
security_data <- .generate_security(api_abbr, security_schemes, pkg_dir)
5252
if (save_security_data) {
5353
.write_security_data(
5454
.without_security_file_path(security_data),
@@ -65,12 +65,13 @@ generate_pkg_auth <- function(
6565
#' @inheritParams .shared-params
6666
#' @returns (`list`) Generated security metadata.
6767
#' @keywords internal
68-
.generate_security <- function(api_abbr, security_schemes) {
68+
.generate_security <- function(api_abbr, security_schemes, pkg_dir = ".") {
6969
security_data <- as_bk_data(security_schemes)
7070
if (length(security_data)) {
7171
security_data$security_file_path <- .bk_use_template(
7272
template = "020-auth.R",
73-
data = c(security_data, api_abbr = api_abbr)
73+
data = c(security_data, api_abbr = api_abbr),
74+
pkg_dir = pkg_dir
7475
)
7576
security_data$security_signature <- .generate_security_signature(
7677
security_data$security_arg_names,

‎R/generate_pkg_paths.R‎

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ generate_pkg_paths <- function(
5858
pagination_data = .generate_pagination(),
5959
base_url = api_definition@servers@url,
6060
use_prefix = use_prefix,
61-
exclude_from_response = exclude_from_response
61+
exclude_from_response = exclude_from_response,
62+
pkg_dir = pkg_dir
6263
)
6364
}
6465

@@ -74,7 +75,8 @@ generate_pkg_paths <- function(
7475
pagination_data = list(),
7576
base_url,
7677
use_prefix = FALSE,
77-
exclude_from_response = character()
78+
exclude_from_response = character(),
79+
pkg_dir = "."
7880
) {
7981
paths_by_operation <- as_bk_data(
8082
paths,
@@ -87,12 +89,14 @@ generate_pkg_paths <- function(
8789
api_abbr,
8890
security_data,
8991
pagination_data,
90-
use_prefix = use_prefix
92+
use_prefix = use_prefix,
93+
pkg_dir = pkg_dir
9194
)
9295
setup_file <- .bk_use_template(
9396
template = "setup.R",
9497
data = list(base_url = base_url),
95-
dir = "tests/testthat"
98+
dir = "tests/testthat",
99+
pkg_dir = pkg_dir
96100
)
97101
paths_file_paths <- c(paths_file_paths, setup_file)
98102
}
@@ -523,7 +527,8 @@ S7::method(as_bk_data, class_paths) <- function(
523527
api_abbr,
524528
security_data,
525529
pagination_data,
526-
use_prefix = FALSE
530+
use_prefix = FALSE,
531+
pkg_dir = "."
527532
) {
528533
security_arg_names <- security_data$security_arg_names %|0|% character()
529534

@@ -558,7 +563,8 @@ S7::method(as_bk_data, class_paths) <- function(
558563
op_id,
559564
api_abbr,
560565
security_data,
561-
use_prefix = use_prefix
566+
use_prefix = use_prefix,
567+
pkg_dir = pkg_dir
562568
)
563569
})))
564570

@@ -568,7 +574,8 @@ S7::method(as_bk_data, class_paths) <- function(
568574
op,
569575
op_id,
570576
api_abbr,
571-
use_prefix = use_prefix
577+
use_prefix = use_prefix,
578+
pkg_dir = pkg_dir
572579
)
573580
})))
574581

@@ -679,7 +686,8 @@ S7::method(as_bk_data, class_paths) <- function(
679686
operation_id,
680687
api_abbr,
681688
security_data,
682-
use_prefix = FALSE
689+
use_prefix = FALSE,
690+
pkg_dir = "."
683691
) {
684692
fn_prefix <- if (use_prefix) paste0(api_abbr, "_") else ""
685693
tidy_policy_body <-
@@ -699,7 +707,8 @@ S7::method(as_bk_data, class_paths) <- function(
699707
pagination_fn = ""
700708
)
701709
),
702-
target = glue::glue("paths-{path_operation$tag}-{operation_id}.R")
710+
target = glue::glue("paths-{path_operation$tag}-{operation_id}.R"),
711+
pkg_dir = pkg_dir
703712
)
704713
}
705714

@@ -712,7 +721,8 @@ S7::method(as_bk_data, class_paths) <- function(
712721
path_operation,
713722
operation_id,
714723
api_abbr,
715-
use_prefix = FALSE
724+
use_prefix = FALSE,
725+
pkg_dir = "."
716726
) {
717727
fn_prefix <- if (use_prefix) paste0(api_abbr, "_") else ""
718728
.bk_use_template(
@@ -725,6 +735,7 @@ S7::method(as_bk_data, class_paths) <- function(
725735
test_args = path_operation$test_args %|0|% ""
726736
),
727737
dir = "tests/testthat",
728-
target = glue::glue("test-paths-{path_operation$tag}-{operation_id}.R")
738+
target = glue::glue("test-paths-{path_operation$tag}-{operation_id}.R"),
739+
pkg_dir = pkg_dir
729740
)
730741
}

‎R/generate_pkg_req_prepare.R‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ generate_pkg_req_prepare <- function(
4949
.generate_prepare(
5050
config = list(api_abbr = api_abbr, api_title = api_title),
5151
api_definition = api_definition,
52-
security_data = security_data
52+
security_data = security_data,
53+
pkg_dir = pkg_dir
5354
)
5455
}
5556

@@ -58,10 +59,15 @@ generate_pkg_req_prepare <- function(
5859
#' @inheritParams .shared-params
5960
#' @returns (`character`) Generated file paths.
6061
#' @keywords internal
61-
.generate_prepare <- function(config, api_definition, security_data) {
62+
.generate_prepare <- function(
63+
config,
64+
api_definition,
65+
security_data,
66+
pkg_dir = "."
67+
) {
6268
c(
63-
.generate_prepare_r(config, api_definition, security_data),
64-
.generate_prepare_test(config$api_abbr)
69+
.generate_prepare_r(config, api_definition, security_data, pkg_dir),
70+
.generate_prepare_test(config$api_abbr, pkg_dir)
6571
)
6672
}
6773

@@ -70,7 +76,12 @@ generate_pkg_req_prepare <- function(
7076
#' @inheritParams .shared-params
7177
#' @returns (`character(1)`) The generated file path.
7278
#' @keywords internal
73-
.generate_prepare_r <- function(config, api_definition, security_data) {
79+
.generate_prepare_r <- function(
80+
config,
81+
api_definition,
82+
security_data,
83+
pkg_dir = "."
84+
) {
7485
.bk_use_template(
7586
template = "010-prepare.R",
7687
data = list(
@@ -81,7 +92,8 @@ generate_pkg_req_prepare <- function(
8192
security_arg_helps = security_data$security_arg_helps,
8293
security_signature = security_data$security_signature,
8394
security_arg_list = security_data$security_arg_list
84-
)
95+
),
96+
pkg_dir = pkg_dir
8597
)
8698
}
8799

@@ -90,10 +102,11 @@ generate_pkg_req_prepare <- function(
90102
#' @inheritParams .shared-params
91103
#' @returns (`character(1)`) The generated test file path.
92104
#' @keywords internal
93-
.generate_prepare_test <- function(api_abbr) {
105+
.generate_prepare_test <- function(api_abbr, pkg_dir = ".") {
94106
.bk_use_template(
95107
template = "test-010-prepare.R",
96108
dir = "tests/testthat",
97-
data = list(api_abbr = api_abbr)
109+
data = list(api_abbr = api_abbr),
110+
pkg_dir = pkg_dir
98111
)
99112
}

‎R/generate_pkg_shared_params.R‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,22 @@ generate_pkg_shared_params <- function(
3535
.use_r_directory(pkg_dir)
3636
.use_nectar(pkg_dir)
3737
.use_pkg_beekeeper(pkg_dir)
38-
.generate_shared_params(security_data)
38+
.generate_shared_params(security_data, pkg_dir)
3939
}
4040

4141
#' Generate shared parameter docs
4242
#'
4343
#' @inheritParams .shared-params
4444
#' @returns (`character(1)`) The generated file path.
4545
#' @keywords internal
46-
.generate_shared_params <- function(security_data) {
46+
.generate_shared_params <- function(security_data, pkg_dir = ".") {
4747
shared_file_path <- .bk_use_template(
4848
template = "000-shared.R",
4949
data = list(
5050
shared_arg_helps = list(),
5151
security_arg_helps = security_data$security_arg_helps
52-
)
52+
),
53+
pkg_dir = pkg_dir
5354
)
5455
return(shared_file_path)
5556
}

‎inst/templates/paths.R‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#' @inheritParams .shared-params
1111
#'
1212
#' @returns `{{fn_prefix}}{{operation_id}}()`: {{response_description}}
13-
#' @export
13+
#' @keywords internal
1414
{{fn_prefix}}{{operation_id}} <- function({{#args}}{{{args}}}, {{/args}}{{#has_security}}{{{security_signature}}}, {{/has_security}}max_reqs = Inf, max_tries_per_req = 3) {
1515
req <- req_{{fn_prefix}}{{operation_id}}({{#args_named}}{{{args_named}}}{{/args_named}}{{#has_security}}{{#args_named}}, {{/args_named}}{{{security_arg_list}}}{{/has_security}})
1616
resps <- nectar::req_perform_opinionated(
@@ -23,6 +23,7 @@
2323

2424
#' @rdname {{fn_prefix}}{{operation_id}}
2525
#' @returns `req_{{fn_prefix}}{{operation_id}}()`: (`httr2_request`) A [httr2::request()] object.
26+
#' @export
2627
req_{{fn_prefix}}{{operation_id}} <- function({{#args}}{{{args}}}{{/args}}{{#has_security}}{{#args}}, {{/args}}{{{security_signature}}}{{/has_security}}) {
2728
{{#validations}}
2829
{{name}} <- stbl::{{to_r}}({{name}})
@@ -39,6 +40,10 @@ req_{{fn_prefix}}{{operation_id}} <- function({{#args}}{{{args}}}{{/args}}{{#has
3940
)
4041
}
4142

43+
#' @rdname {{fn_prefix}}{{operation_id}}
44+
#' @returns `tidy_policy_{{fn_prefix}}{{operation_id}}()`: (`nectar_tidy_policy`)
45+
#' A list like the ones returned by [nectar::tidy_policy_prepare()].
46+
#' @export
4247
tidy_policy_{{fn_prefix}}{{operation_id}} <- function() {
4348
{{{tidy_policy_body}}}
4449
}

‎man/dot-bk_use_template.Rd‎

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)