Create absent package scaffold files, a local schema copy, project policy, a client-owned httr2 request helper, and session controls.
Usage
initialize_client(
root,
schema,
package = NULL,
title = NULL,
author = NULL,
license = NULL,
base_url = NULL,
naming = c("operation_id", "tag_prefix", "path"),
group_by = c("tag", "none"),
name_case = c("asis", "snake_case", "camel_case", "pascal_case",
"screaming_snake_case", "dot_case"),
companions = character(),
naming_options = NULL,
origin = NULL
)Arguments
- root
Destination client directory; it may be created when absent.
- schema
Local JSON, YAML, or YML schema, or a reviewed data frame returned by configure_apis for multiple APIs. Multi-API setup requires an existing root containing those schemas, and a new package. Each included API receives a separate request helper, namespaced function names and credential identities.
- package
New R package name, for example
catalogueclient. Must agree with an existing DESCRIPTION when supplied.- title
Human-readable package title, required for a new package.
Named list with
given,family, andemailstrings, required for a new package.- license
Explicit license string for a new package.
MIT + file LICENSEalso creates an MIT license metadata file.- base_url
Optional absolute HTTP(S) override for all operations in the new client-owned transport. Overrides schema servers; a runtime option can override it.
- naming
Preserve operationId names by default, or propose tag-prefixed snake_case names. Or path, which derives names from the route. See configure_client.
- group_by
Group operations by first tag (default), or use one default group with none. Multi-API initialization writes one YAML file per API with nested groups; single-schema initialization keeps flat group files.
- name_case
Case convention for proposed names. Choices are as-is, snake_case, camelCase, PascalCase, SCREAMING_SNAKE_CASE, and dot.case. See configure_client.
- companions
Optional selection of
batching,pagination,arcgis,discovery,graphqland/orcache. ArcGIS captures, Google API Discovery documents and GraphQL introspection results automatically include their protocol callbacks, and the first two include pagination. Batching and pagination emit reusable, exported helper-prefixed companions; arcgis, discovery and graphql add internal protocol callbacks. cache adds the response cache functions that theresponse_cachesetting needs and puts cachem and rlang in new-client Imports; an existing DESCRIPTION must declare them. Their client-owned baseline is recorded. Empty by default. Pagination adds digest to new-client Imports; an existing DESCRIPTION must declare it.- naming_options
Options for naming = 'path': prefix, drop_segments, strip_stem, collision_suffix, by_param. See configure_client.
- origin
Optional reviewed absolute HTTP(S) URL the OpenAPI or Swagger schema was downloaded from, such as
https://example.org/api/docs/openapi.json. Relative root, path and operation servers resolve against it (RFC 3986), keeping their precedence, so operations with their own relative servers keep their own paths. It is written to each service YAML asschemas.originand recorded indev/init.R; the schema copy is unchanged. Unlikebase_url, it does not override schema servers. Without it, relative servers keep their server diagnostics.
Value
A list of applied file records, each containing file, path, and action. The configuration attribute contains proposed files, operation assignments, and diagnostics. Stops before application for invalid metadata, tag filename collisions, or conflicting scaffold paths.
Details
This function writes immediately and refuses any existing-file conflict. Supply package, title, author (given, family, email), and license for a new package. Existing DESCRIPTION metadata is retained; it must already declare httr2 and jsonlite, which the default transport needs for HTTP and JSON. Adding a new default transport also requires curl for form uploads. Without an explicit override, generated wrappers use operation, path, then root servers, resolving variable defaults. Ambiguous or unsupported selection produces server_diagnostics and fails before HTTP unless a runtime override is supplied. Baseline YAML defaults.request_controls exposes timeout, max_retries, and retry_writes. Regeneration passes these inherited defaults into helper calls without editing the client-owned helper. Runtime options override these fields. The helper reads the lowercase dry-run prefix plus .request as an R option containing base_url, timeout (default 30 seconds per attempt), max_retries (default 0), and retry_writes (default FALSE). Enabled retries cover transient HTTP responses for GET, HEAD, OPTIONS, PUT and DELETE; other methods need explicit write permission. Retry-After is honored. Normal generation never updates this helper. Initialization does not generate wrappers or tests: follow with generate_client(). The helper is client runtime code and does not import specmill.
Initialization also emits client-owned dev/init.R and
dev/generate.R, excluded from package builds. Source the first and call
init_main(root) with an absent destination to recreate the initial
scaffold from local schema copies. Later policy and helper edits are not replayed.
Source the second and call generate_main(args = "--plan") to preview
maintenance; "--check" checks and no flag applies. Both locate their
source package independently of the working directory. Regeneration preserves
these scripts. For prompted setup, see setup_client().
New clients also receive client-owned R/api_options.R with
<package>_run_verbose(verbose = FALSE) and
<package>_dry_run(enabled = FALSE). Function prefixes preserve the exact
package name; no unprefixed control aliases are exported.
These set package-prefixed run_verbose and dry_run R options.
Both default to off. An explicit dry-run option overrides the legacy dry-run
environment flag. Dry runs return prepared httr2 requests without sending them;
input validation and authentication still apply, and returned requests may
contain credentials. Verbose messages contain method and HTTP status only.
Multi-API clients share one set of controls. Existing helpers and clients require
manual adoption; regeneration never overwrites client-owned runtime files.
Note
Service YAML includes explicit operation allowlists and editable names, including unsupported operations. Name collisions and unsupported transports require review before wrapper generation; initialization does not resolve them. Inspect attr(result, 'configuration')$diagnostics, or preview with configure_client() before initialization.
See also
configure_hooks for optional client-owned pre/post execution. configure_lifecycle for optional .onLoad() and .onAttach() stubs; this function does not write them. Step-by-step guide.
