Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always redirect /__swagger_/ to /__docs__/ #694

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ plumber 1.0.0.9999 Development version

* When calling `Plumber$handle()` and defining a new `PlumberEndpoint`, `...` will be checked for invalid names #677

* `/__swagger__/` now always redirect to `/__docs__/`, even when Swagger isn't the selected interface. Use `options(plumber.legacyRedirects = FALSE)` to disable this behavior (. (@blairj09 #694)

plumber 1.0.0
--------------------------------------------------------------------------------

Expand Down
11 changes: 8 additions & 3 deletions R/plumber-options.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@
#' \item{`plumber.sharedSecret`}{Shared secret used to filter incoming request.
#' When `NULL`, secret is not validated. Otherwise, Plumber compares secret with http header
#' `PLUMBER_SHARED_SECRET`. Failure to match results in http error 400. Defaults to `NULL`.}
#' \item{`plumber.legacyRedirects`}{Plumber will redirect legacy route `/__swagger__/` and
#' `/__swagger__/index.html` to `../__docs__/` and `../__docs__/index.html`. You can disable this
#' by settings this option to `FALSE`. Defaults to `TRUE`}
#' }
#'
#' @param port,docs,docs.callback,apiScheme,apiHost,apiPort,apiPath,apiURL,maxRequestSize,sharedSecret See details
#' @param port,docs,docs.callback,apiScheme,apiHost,apiPort,apiPath,apiURL,maxRequestSize,sharedSecret,legacyRedirects See details
#' @return
#' The complete, prior set of [options()] values.
#' If a particular parameter is not supplied, it will return the current value.
Expand All @@ -47,7 +50,8 @@ options_plumber <- function(
apiPort = getOption("plumber.apiPort"),
apiPath = getOption("plumber.apiPath"),
maxRequestSize = getOption("plumber.maxRequestSize"),
sharedSecret = getOption("plumber.sharedSecret")
sharedSecret = getOption("plumber.sharedSecret"),
legacyRedirects = getOption("plumber.legacyRedirects")
) {
options(
plumber.apiScheme = apiScheme,
Expand All @@ -59,6 +63,7 @@ options_plumber <- function(
plumber.port = port,
plumber.sharedSecret = sharedSecret,
plumber.docs = docs,
plumber.docs.callback = docs.callback
plumber.docs.callback = docs.callback,
plumber.legacyRedirects = legacyRedirects
)
}
33 changes: 16 additions & 17 deletions R/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ register_docs <- function(name, index, static = NULL) {
stopifnot(is.function(index))
if (!is.null(static)) stopifnot(is.function(static))

is_swagger <- isTRUE(name == "swagger")

docs_root <- paste0("/__docs__/")
docs_paths <- c("/index.html", "/")

Expand Down Expand Up @@ -213,12 +211,10 @@ register_docs <- function(name, index, static = NULL) {

pr$mount(docs_root, docs_router)

# add legacy swagger redirects
if (is_swagger) {
redirect_info <- swagger_redirects()
for (path in names(redirect_info)) {
pr_get(pr, path, redirect_info[[path]])
}
# add legacy swagger redirects (RStudio Connect)
redirect_info <- swagger_redirects()
for (path in names(redirect_info)) {
pr_get(pr, path, redirect_info[[path]])
}

docs_url <- paste0(api_url, docs_root)
Expand All @@ -228,12 +224,11 @@ register_docs <- function(name, index, static = NULL) {
pr$unmount(docs_root)

# remove legacy swagger redirects
if (is_swagger) {
redirect_info <- swagger_redirects()
for (path in names(redirect_info)) {
pr$removeHandle("GET", path)
}
redirect_info <- swagger_redirects()
for (path in names(redirect_info)) {
pr$removeHandle("GET", path)
}

invisible()
}

Expand Down Expand Up @@ -261,10 +256,14 @@ swagger_redirects <- function() {
res
}
}
list(
"/__swagger__/" = to_route("../__docs__/"),
"/__swagger__/index.html" = to_route("../__docs__/index.html")
)
if (isTRUE(getOption("plumber.legacyRedirects", TRUE))) {
list(
"/__swagger__/" = to_route("../__docs__/"),
"/__swagger__/index.html" = to_route("../__docs__/index.html")
)
} else {
list()
}
}


Expand Down
2 changes: 1 addition & 1 deletion man/Plumber.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions man/options_plumber.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/parsers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/plumb.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/pr_set_parsers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions man/register_parser.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/serializers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.