plumber (version 1.0.0)

pr_set_api_spec: Set the OpenAPI Specification information

Description

When set, it will be called with a character string corresponding to the API visual documentation url. This allows RStudio to open swagger docs when a Plumber router pr_run() method is executed using default plumber.docs.callback option.

Usage

pr_set_api_spec(pr, api)

Arguments

pr

A Plumber API. Note: The supplied Plumber API object will also be updated in place as well as returned by the function.

api

This can be

  • an OpenAPI Specification formatted list object

  • a function that accepts the OpenAPI Specification autogenerated by plumber and returns a OpenAPI Specification formatted list object.

The value returned will not be validated for OAS compatibility.

Value

The Plumber router with the new OpenAPI Specification object or function.

Examples

Run this code
# NOT RUN {
# Set the API Spec to a function to use the auto-generated OAS object
pr() %>%
  pr_set_api_spec(function(spec) {
    spec$info$title <- Sys.time()
    spec
  }) %>%
  pr_get("/plus/<a:int>/<b:int>", function(a, b) { a + b }) %>%
  pr_run()

# Set the API Spec using an object
pr() %>%
  pr_set_api_spec(my_custom_object) %>%
  pr_get("/plus/<a:int>/<b:int>", function(a, b) { a + b }) %>%
  pr_run()
# }

Run the code above in your browser using DataLab