| Title: | Rapidly Scaffold API Client Packages |
|---|---|
| Description: | Automatically generate R package skeletons from 'application programming interfaces (APIs)' that follow the 'OpenAPI Specification (OAS)'. The skeletons implement best practices to streamline package development. |
| Authors: | Jon Harmon [aut, cre, cph] (ORCID: <https://orcid.org/0000-0003-4781-4346>), R Consortium [fnd] |
| Maintainer: | Jon Harmon <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.5.0.9000 |
| Built: | 2026-05-22 16:29:59 UTC |
| Source: | https://github.com/jonthegeek/beekeeper |
Creates or updates package files based on the information in a beekeeper
config file (generated by use_beekeeper() or manually). The files enforce
an opinionated framework for API packages.
generate_pkg( api_abbr = read_api_abbr(pkg_dir, config_filename), api_definition = read_api_definition(pkg_dir, read_rapid_filename(pkg_dir, config_filename)), api_title = read_api_title(pkg_dir, config_filename), config_filename = "_beekeeper.yml", pkg_dir = "." )generate_pkg( api_abbr = read_api_abbr(pkg_dir, config_filename), api_definition = read_api_definition(pkg_dir, read_rapid_filename(pkg_dir, config_filename)), api_title = read_api_title(pkg_dir, config_filename), config_filename = "_beekeeper.yml", pkg_dir = "." )
api_abbr |
( |
api_definition |
( |
api_title |
( |
config_filename |
( |
pkg_dir |
( |
(character, invisibly) Paths to files that were added or updated.
Other package generation functions:
generate_pkg_auth(),
generate_pkg_paths(),
generate_pkg_req_prepare(),
generate_pkg_shared_params()
# Set up an empty package. pkg_dir <- unclass(fs::path_norm(withr::local_tempdir())) usethis::create_package(pkg_dir, open = FALSE, check_name = FALSE) bk_files <- c("_beekeeper.yml", "_beekeeper_rapid.rds") fs::file_copy( fs::path_package("beekeeper", "guru", bk_files), fs::path(pkg_dir, bk_files) ) usethis::local_project(pkg_dir) # Generate a package. generate_pkg() fs::dir_ls("R") fs::dir_ls("tests/testthat") # Clean up. withr::deferred_run()# Set up an empty package. pkg_dir <- unclass(fs::path_norm(withr::local_tempdir())) usethis::create_package(pkg_dir, open = FALSE, check_name = FALSE) bk_files <- c("_beekeeper.yml", "_beekeeper_rapid.rds") fs::file_copy( fs::path_package("beekeeper", "guru", bk_files), fs::path(pkg_dir, bk_files) ) usethis::local_project(pkg_dir) # Generate a package. generate_pkg() fs::dir_ls("R") fs::dir_ls("tests/testthat") # Clean up. withr::deferred_run()
Generate the authentication helper file for a package under development from the API security schemes stored in the OpenAPI definition. This supports incremental package scaffolding when you want to review or customize auth handling before generating the rest of the package files.
generate_pkg_auth( api_abbr = read_api_abbr(pkg_dir, config_filename), security_schemes = read_security_schemes(pkg_dir, read_rapid_filename(pkg_dir, config_filename)), save_security_data = TRUE, security_data_filename = "_beekeeper_security.yml", config_filename = "_beekeeper.yml", pkg_dir = "." )generate_pkg_auth( api_abbr = read_api_abbr(pkg_dir, config_filename), security_schemes = read_security_schemes(pkg_dir, read_rapid_filename(pkg_dir, config_filename)), save_security_data = TRUE, security_data_filename = "_beekeeper_security.yml", config_filename = "_beekeeper.yml", pkg_dir = "." )
api_abbr |
( |
security_schemes |
( |
save_security_data |
( |
security_data_filename |
( |
config_filename |
( |
pkg_dir |
( |
(list) Generated security metadata. R/020-auth.R is generated as
a side effect. When save_security_data is TRUE (strongly recommended
when calling this function as a stand-alone), the file designated by
security_data_filename, and the security_data_filename field in the
file designated by config_filename are generated as side effects.
Other package generation functions:
generate_pkg(),
generate_pkg_paths(),
generate_pkg_req_prepare(),
generate_pkg_shared_params()
# Set up an empty package. pkg_dir <- unclass(fs::path_norm(withr::local_tempdir())) usethis::create_package(pkg_dir, open = FALSE, check_name = FALSE) bk_files <- c("_beekeeper.yml", "_beekeeper_rapid.rds") fs::file_copy( fs::path_package("beekeeper", "trello", bk_files), fs::path(pkg_dir, bk_files) ) usethis::local_project(pkg_dir) # Generate package authentication functions. generate_pkg_auth() fs::dir_ls("R") # Clean up. withr::deferred_run()# Set up an empty package. pkg_dir <- unclass(fs::path_norm(withr::local_tempdir())) usethis::create_package(pkg_dir, open = FALSE, check_name = FALSE) bk_files <- c("_beekeeper.yml", "_beekeeper_rapid.rds") fs::file_copy( fs::path_package("beekeeper", "trello", bk_files), fs::path(pkg_dir, bk_files) ) usethis::local_project(pkg_dir) # Generate package authentication functions. generate_pkg_auth() fs::dir_ls("R") # Clean up. withr::deferred_run()
Generate operation functions and their tests from the API paths stored in the OpenAPI definition. This supports incremental package scaffolding when you want to review or customize endpoint wrappers separately from other package components.
generate_pkg_paths( api_abbr = read_api_abbr(pkg_dir, config_filename), api_definition = read_api_definition(pkg_dir, read_rapid_filename(pkg_dir, config_filename)), security_data = read_security_data(pkg_dir, config_filename), config_filename = "_beekeeper.yml", pkg_dir = "." )generate_pkg_paths( api_abbr = read_api_abbr(pkg_dir, config_filename), api_definition = read_api_definition(pkg_dir, read_rapid_filename(pkg_dir, config_filename)), security_data = read_security_data(pkg_dir, config_filename), config_filename = "_beekeeper.yml", pkg_dir = "." )
api_abbr |
( |
api_definition |
( |
security_data |
( |
config_filename |
( |
pkg_dir |
( |
(character) Generated file paths. As a side effect, zero or more
R/paths-*.R files are generated from the paths in the api_definition,
as well as the associated test files as tests/testthat/test-paths-*.R.
Other package generation functions:
generate_pkg(),
generate_pkg_auth(),
generate_pkg_req_prepare(),
generate_pkg_shared_params()
# Set up an empty package. pkg_dir <- unclass(fs::path_norm(withr::local_tempdir())) usethis::create_package(pkg_dir, open = FALSE, check_name = FALSE) bk_files <- c("_beekeeper.yml", "_beekeeper_rapid.rds") fs::file_copy( fs::path_package("beekeeper", "guru", bk_files), fs::path(pkg_dir, bk_files) ) usethis::local_project(pkg_dir) # Generate functions and tests for API paths. generate_pkg_paths() fs::dir_ls("R") fs::dir_ls("tests/testthat") # Clean up. withr::deferred_run()# Set up an empty package. pkg_dir <- unclass(fs::path_norm(withr::local_tempdir())) usethis::create_package(pkg_dir, open = FALSE, check_name = FALSE) bk_files <- c("_beekeeper.yml", "_beekeeper_rapid.rds") fs::file_copy( fs::path_package("beekeeper", "guru", bk_files), fs::path(pkg_dir, bk_files) ) usethis::local_project(pkg_dir) # Generate functions and tests for API paths. generate_pkg_paths() fs::dir_ls("R") fs::dir_ls("tests/testthat") # Clean up. withr::deferred_run()
Generate the core request helper and its initial test file for a package under development. This supports incremental package scaffolding when you want to review or customize the central request-construction helper used by generated endpoint wrappers separately from other package components.
generate_pkg_req_prepare( api_abbr = read_api_abbr(pkg_dir, config_filename), api_definition = read_api_definition(pkg_dir, read_rapid_filename(pkg_dir, config_filename)), api_title = read_api_title(pkg_dir, config_filename), security_data = read_security_data(pkg_dir, config_filename), config_filename = "_beekeeper.yml", pkg_dir = "." )generate_pkg_req_prepare( api_abbr = read_api_abbr(pkg_dir, config_filename), api_definition = read_api_definition(pkg_dir, read_rapid_filename(pkg_dir, config_filename)), api_title = read_api_title(pkg_dir, config_filename), security_data = read_security_data(pkg_dir, config_filename), config_filename = "_beekeeper.yml", pkg_dir = "." )
api_abbr |
( |
api_definition |
( |
api_title |
( |
security_data |
( |
config_filename |
( |
pkg_dir |
( |
(character) Generated file paths. As a side effect,
R/010-prepare.R and tests/testthat/test-010-prepare.R are generated.
Other package generation functions:
generate_pkg(),
generate_pkg_auth(),
generate_pkg_paths(),
generate_pkg_shared_params()
# Set up an empty package. pkg_dir <- unclass(fs::path_norm(withr::local_tempdir())) usethis::create_package(pkg_dir, open = FALSE, check_name = FALSE) bk_files <- c("_beekeeper.yml", "_beekeeper_rapid.rds") fs::file_copy( fs::path_package("beekeeper", "guru", bk_files), fs::path(pkg_dir, bk_files) ) usethis::local_project(pkg_dir) # Generate functions and tests for request preparation. generate_pkg_req_prepare() fs::dir_ls("R") fs::dir_ls("tests/testthat") # Clean up. withr::deferred_run()# Set up an empty package. pkg_dir <- unclass(fs::path_norm(withr::local_tempdir())) usethis::create_package(pkg_dir, open = FALSE, check_name = FALSE) bk_files <- c("_beekeeper.yml", "_beekeeper_rapid.rds") fs::file_copy( fs::path_package("beekeeper", "guru", bk_files), fs::path(pkg_dir, bk_files) ) usethis::local_project(pkg_dir) # Generate functions and tests for request preparation. generate_pkg_req_prepare() fs::dir_ls("R") fs::dir_ls("tests/testthat") # Clean up. withr::deferred_run()
Read the api_abbr field from a beekeeper config file.
read_api_abbr(pkg_dir = ".", config_filename = "_beekeeper.yml")read_api_abbr(pkg_dir = ".", config_filename = "_beekeeper.yml")
pkg_dir |
( |
config_filename |
( |
(character(1)) The api_abbr field from the beekeeper
config file.
Other config readers:
read_api_definition(),
read_api_title(),
read_config(),
read_rapid_filename(),
read_security_data(),
read_security_data_filename(),
read_security_schemes()
read_api_abbr(pkg_dir = fs::path_package("beekeeper", "guru"))read_api_abbr(pkg_dir = fs::path_package("beekeeper", "guru"))
Read an RDS file (default name _beekeeper_rapid.rds) with the API
definition stored as a rapid::class_rapid() object. This file is generated
by use_beekeeper() based on an OpenAPI definition file.
read_api_definition( pkg_dir = ".", rapid_filename = read_rapid_filename(pkg_dir) )read_api_definition( pkg_dir = ".", rapid_filename = read_rapid_filename(pkg_dir) )
pkg_dir |
( |
rapid_filename |
( |
(rapid::class_rapid) The definition of the API.
Other config readers:
read_api_abbr(),
read_api_title(),
read_config(),
read_rapid_filename(),
read_security_data(),
read_security_data_filename(),
read_security_schemes()
api_definition <- read_api_definition(fs::path_package("beekeeper", "guru")) class(api_definition) api_definition@info@origin@urlapi_definition <- read_api_definition(fs::path_package("beekeeper", "guru")) class(api_definition) api_definition@info@origin@url
Read the api_title field from a beekeeper config file.
read_api_title(pkg_dir = ".", config_filename = "_beekeeper.yml")read_api_title(pkg_dir = ".", config_filename = "_beekeeper.yml")
pkg_dir |
( |
config_filename |
( |
(character(1)) The api_title field from the beekeeper
config file.
Other config readers:
read_api_abbr(),
read_api_definition(),
read_config(),
read_rapid_filename(),
read_security_data(),
read_security_data_filename(),
read_security_schemes()
read_api_title(pkg_dir = fs::path_package("beekeeper", "guru"))read_api_title(pkg_dir = fs::path_package("beekeeper", "guru"))
Read a YAML file (default name _beekeeper.yml) with configuration
information about the API and the package. This file is generated by
use_beekeeper(), or can be created manually.
read_config(pkg_dir = ".", config_filename = "_beekeeper.yml")read_config(pkg_dir = ".", config_filename = "_beekeeper.yml")
pkg_dir |
( |
config_filename |
( |
The configuration information must contain these fields:
api_title (character(1)): The title of the API, used in documentation
and messages.
api_abbr (character(1)): An abbreviation for the API, used in function
names and other identifiers.
api_version (character(1)): The version of the API.
rapid_filename (character(1)): The name of the file (relative to the
package root) where the API definition is stored as an RDS file. By default,
this is _beekeeper_rapid.rds, and is generated by use_beekeeper() based
on an OpenAPI definition file.
updated_on (character(1)): A timestamp of when the API definition was
last updated, in the format "YYYY-MM-DD HH:MM:SS" (UTC).
security_data_filename (character(1)): Optionally, the path (relative
to the package root) where generated security metadata is stored.
(list) Configuration information, with elements api_title,
api_abbr, api_version, rapid_filename, and updated_on, plus
security_data_filename when present.
Other config readers:
read_api_abbr(),
read_api_definition(),
read_api_title(),
read_rapid_filename(),
read_security_data(),
read_security_data_filename(),
read_security_schemes()
read_config(pkg_dir = fs::path_package("beekeeper", "guru"))read_config(pkg_dir = fs::path_package("beekeeper", "guru"))
Read the rapid_filename field from a beekeeper config file.
read_rapid_filename(pkg_dir = ".", config_filename = "_beekeeper.yml")read_rapid_filename(pkg_dir = ".", config_filename = "_beekeeper.yml")
pkg_dir |
( |
config_filename |
( |
(character(1)) The rapid_filename field from the beekeeper
config file.
Other config readers:
read_api_abbr(),
read_api_definition(),
read_api_title(),
read_config(),
read_security_data(),
read_security_data_filename(),
read_security_schemes()
read_rapid_filename(pkg_dir = fs::path_package("beekeeper", "guru"))read_rapid_filename(pkg_dir = fs::path_package("beekeeper", "guru"))
Read prepared security metadata from a YAML file (default name
_beekeeper_security.yml) generated via generate_pkg_auth().
read_security_data( pkg_dir = ".", config_filename = "_beekeeper.yml", security_data_filename = read_security_data_filename(pkg_dir, config_filename) )read_security_data( pkg_dir = ".", config_filename = "_beekeeper.yml", security_data_filename = read_security_data_filename(pkg_dir, config_filename) )
pkg_dir |
( |
config_filename |
( |
security_data_filename |
( |
(list) Saved security metadata.
Other config readers:
read_api_abbr(),
read_api_definition(),
read_api_title(),
read_config(),
read_rapid_filename(),
read_security_data_filename(),
read_security_schemes()
read_security_data(pkg_dir = fs::path_package("beekeeper", "trello"))read_security_data(pkg_dir = fs::path_package("beekeeper", "trello"))
Read the security_data_filename field from a beekeeper config file.
read_security_data_filename(pkg_dir = ".", config_filename = "_beekeeper.yml")read_security_data_filename(pkg_dir = ".", config_filename = "_beekeeper.yml")
pkg_dir |
( |
config_filename |
( |
(character(1)) The configured security metadata file path.
Other config readers:
read_api_abbr(),
read_api_definition(),
read_api_title(),
read_config(),
read_rapid_filename(),
read_security_data(),
read_security_schemes()
read_security_data_filename( pkg_dir = fs::path_package("beekeeper", "trello") )read_security_data_filename( pkg_dir = fs::path_package("beekeeper", "trello") )
Read the security schemes from an API definition stored as a
rapid::class_rapid() object.
read_security_schemes( pkg_dir = ".", rapid_filename = read_rapid_filename(pkg_dir) )read_security_schemes( pkg_dir = ".", rapid_filename = read_rapid_filename(pkg_dir) )
pkg_dir |
( |
rapid_filename |
( |
(rapid::class_security_schemes) Security schemes from the API
definition.
Other config readers:
read_api_abbr(),
read_api_definition(),
read_api_title(),
read_config(),
read_rapid_filename(),
read_security_data(),
read_security_data_filename()
Create a configuration file for a package to use beekeeper. The configuration file tracks information that will be used for generation of other functions, and the timestamp when the configuration was last updated or used.
use_beekeeper( x, api_abbr, ..., pkg_dir = ".", config_filename = "_beekeeper.yml", rapid_filename = "_beekeeper_rapid.rds" )use_beekeeper( x, api_abbr, ..., pkg_dir = ".", config_filename = "_beekeeper.yml", rapid_filename = "_beekeeper_rapid.rds" )
x |
An object to use to define the configuration. It must be
translatable to a |
api_abbr |
( |
... |
These dots are for future extensions and must be empty. |
pkg_dir |
( |
config_filename |
( |
rapid_filename |
( |
(character(1), invisibly) The path to the configuration file. The
config file is written as a side effect of this function. The rapid object
is also written, and the path to that file (relative to pkg_dir) is saved
in the config file.
# Set up an empty package. pkg_dir <- unclass(fs::path_norm(withr::local_tempdir())) usethis::create_package(pkg_dir, open = FALSE, check_name = FALSE) usethis::local_project(pkg_dir) # Read an api definition. This could also simply be a URL to such a # definition. api_definition <- read_api_definition(fs::path_package("beekeeper", "guru")) # Set up the package to use beekeeper with that definition. use_beekeeper(api_definition, "guru") read_config() all.equal(read_api_definition(), api_definition) # Clean up. withr::deferred_run()# Set up an empty package. pkg_dir <- unclass(fs::path_norm(withr::local_tempdir())) usethis::create_package(pkg_dir, open = FALSE, check_name = FALSE) usethis::local_project(pkg_dir) # Read an api definition. This could also simply be a URL to such a # definition. api_definition <- read_api_definition(fs::path_package("beekeeper", "guru")) # Set up the package to use beekeeper with that definition. use_beekeeper(api_definition, "guru") read_config() all.equal(read_api_definition(), api_definition) # Clean up. withr::deferred_run()