Skip to content

Update the OpenAPI specification using model metadata

Usage

api_spec(spec, vetiver_model, path, all_docs = TRUE)

glue_spec_summary(ptype, return_type)

# S3 method for default
glue_spec_summary(ptype, return_type = NULL)

# S3 method for data.frame
glue_spec_summary(ptype, return_type = "predictions")

# S3 method for array
glue_spec_summary(ptype, return_type = "predictions")

Arguments

spec

An OpenAPI Specification formatted list object

vetiver_model

A deployable vetiver_model() object

path

The endpoint path

all_docs

Should the interactive visual API documentation be created for all POST endpoints in the router pr? This defaults to TRUE, and assumes that all POST endpoints use the vetiver_model$ptype input data prototype.

ptype

An input data prototype from a model

return_type

Character string to describe what endpoint returns, such as "predictions"

Value

api_spec() returns the updated OpenAPI Specification object. This function uses glue_spec_summary() internally, which returns a gluecharacter string.

Examples

library(plumber)
cars_lm <- lm(mpg ~ ., data = mtcars)
v <- vetiver_model(cars_lm, "cars_linear")

glue_spec_summary(v$ptype)
#> Return predictions from model using 10 features

modify_spec <- function(spec) api_spec(spec, v, "/predict")
pr() %>% pr_set_api_spec(api = modify_spec)
#> # Plumber router with 0 endpoints, 4 filters, and 0 sub-routers.
#> # Use `pr_run()` on this object to start the API.
#> ├──[queryString]
#> ├──[body]
#> ├──[cookieParser]
#> ├──[sharedSecret]