Skip to content

Commit

Permalink
Merge pull request #4 from meztez/schloerke-patch-1
Browse files Browse the repository at this point in the history
Add a on load hook for plumber and change docs location
  • Loading branch information
meztez authored Aug 24, 2020
2 parents 67ab32c + 6ef2bda commit f47860c
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions R/paths.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,31 +65,36 @@ redoc_spec <- function(spec_url = "https://redocly.github.io/redoc/openapi.yaml"
index_txt
}

plumber_register_ui <- function() {
if (requireNamespace("plumber", quietly = TRUE)) {
register_ui <- tryCatch(
plumber::register_ui,
error = function(err) {
function(...) {
return()
}
}


plumber_docs <- function() {
list(
name = "redoc",
index = function(...) {
redoc::redoc_spec(
spec_url = "\' + window.location.origin + window.location.pathname.replace(/\\(__docs__\\\\/|__docs__\\\\/index.html\\)$/, '') + 'openapi.json' + \'",
...
)
register_ui(
name = "redoc",
index = function(...) {
redoc::redoc_spec(
spec_url = "\' + window.location.origin + window.location.pathname.replace(/\\(__redoc__\\\\/|__redoc__\\\\/index.html\\)$/, '') + 'openapi.json' + \'",
...
)
},
static = function(...) {
redoc::redoc_path()
}
)
}
},
static = function(...) {
redoc::redoc_path()
}
)
}

.onLoad <- function(...) {
plumber_register_ui()
plumber_register_docs <- function() {
tryCatch({
do.call(plumber::register_docs, plumber_docs())
}, error = function(e) {
message("Error registering redoc docs. Error: ", e)
})
}

setHook(packageEvent("plumber", "onLoad"), function(...) {
plumber_register_docs()
})
if ("plumber" %in% loadedNamespaces()) {
plumber_register_docs()
}
}

0 comments on commit f47860c

Please sign in to comment.