# NOT RUN {
# Example from the `swagger` R package
register_docs(
name = "swagger",
index = function(version = "3", ...) {
swagger::swagger_spec(
api_path = paste0(
"window.location.origin + ",
"window.location.pathname.replace(",
"/\\(__docs__\\\\/|__docs__\\\\/index.html\\)$/, \"\"",
") + ",
"\"openapi.json\""
),
version = version
)
},
static = function(version = "3", ...) {
swagger::swagger_path(version)
}
)
# When setting the docs, `index` and `static` function arguments can be supplied
# * via `pr_set_docs()`
# * or through URL query string variables
pr() %>%
# Set default argument `version = 3` for the swagger `index` and `static` functions
pr_set_docs("swagger", version = 3) %>%
pr_get("/plus/<a:int>/<b:int>", function(a, b) { a + b }) %>%
pr_run()
# }
Run the code above in your browser using DataCamp Workspace