Navigation Menu

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

Interface mount #562

Closed
wants to merge 65 commits into from
Closed
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
cd52da2
ui mounting and generalize interface
Jun 23, 2020
5965964
merge master
Jun 23, 2020
d891473
update news and description
Jun 23, 2020
40aa40c
typo
Jun 23, 2020
6ae7cef
comment out redoc
Jun 23, 2020
a1890c0
Update NEWS.md
meztez Jun 23, 2020
a5236b8
Update NEWS.md
meztez Jun 23, 2020
2f0cb37
mid PR review
Jun 23, 2020
b0858b8
merge master
Jun 24, 2020
17143be
remove UI mounts on.exit, PR review.
Jun 24, 2020
b38a559
Merge branch 'interface_mount' of github.com:meztez/plumber into inte…
Jun 24, 2020
b15a514
comment out redoc
Jun 24, 2020
c9406a2
vector allocation, named arg
Jun 24, 2020
d6b544c
update news
Jun 24, 2020
e89e17b
typos, moved code to redoc package
Jun 24, 2020
1a1dd84
add unmount, removeHandle tests
Jun 24, 2020
cc59f2c
PR Review, apiSpec fix see test in openapi
Jun 24, 2020
f6154be
consistent return(NULL) across package, PR review
Jun 24, 2020
6d9ea95
PR Review
Jun 24, 2020
6ce9a02
return() : early, return(NULL) : value assign
Jun 24, 2020
c35c5e0
renaming, adding openapi.yaml
Jun 25, 2020
7af97e4
reshape help, news, merge master
Jun 25, 2020
536ccde
options doc refix because Im dumdum
Jun 25, 2020
eccf376
merge master
Jun 26, 2020
9017a26
Update R/plumber-options.R
meztez Jun 27, 2020
639d3b8
Update R/plumber-options.R
meztez Jun 27, 2020
b2b7986
Update R/plumber.R
meztez Jun 27, 2020
11ec4e9
pr suggest onload
Jun 27, 2020
ab82538
Update R/plumber-options.R
meztez Jun 27, 2020
d181bff
adding rapidoc interface reference
Jun 27, 2020
7eb05f3
typo
Jun 28, 2020
99d8e93
make sure ui get the right ... expansion
Jun 28, 2020
c39e3fc
Allow for changes to ui on the fly using the URI. Soft validate ui av…
Jun 28, 2020
296199a
strip ?.* in HTTP_REFERER in case it exists
Jun 28, 2020
b91a8da
arbitrary files number
Jun 30, 2020
8379730
Merge branch 'multi_files' into interface_mount
Jun 30, 2020
9a42ad6
Merge branch 'master' into interface_mount
schloerke Jul 2, 2020
039c717
Update R/plumber.R
Jul 2, 2020
ced7001
Update R/plumber.R
Jul 2, 2020
d1fa0c3
Update R/plumber.R
Jul 2, 2020
ac17479
Update R/plumber-step.R
Jul 2, 2020
8e751dd
Update R/plumber.R
Jul 2, 2020
eb3052d
Update R/plumber.R
Jul 2, 2020
347c096
Update R/plumber.R
Jul 2, 2020
b335ed1
Update R/plumber.R
Jul 2, 2020
1afb6d8
Update R/plumber.R
Jul 2, 2020
2586ea6
Update R/ui.R
Jul 2, 2020
7f21ba7
Update R/ui.R
Jul 2, 2020
6b444c5
Update R/ui.R
Jul 2, 2020
e3e4c2a
Merge branch 'interface_mount' of github.com:meztez/plumber into inte…
Jul 2, 2020
5089f49
post PR review
Jul 2, 2020
44ee359
remove startsWith, endsWith from mount
Jul 2, 2020
be2d6d2
change to TRUE
Jul 2, 2020
573c762
update pkgdown index
Jul 3, 2020
0312266
inverse mount$ui_name to ui_name$mount, remove branch polution from o…
Jul 4, 2020
a2434b0
merge master
Jul 4, 2020
0080420
Remove Redoc and RapiDoc reference, wait after they hit CRAN.
Jul 10, 2020
5af07b8
Update R/plumber.R
Jul 13, 2020
78c5fa3
Update R/plumber.R
Jul 13, 2020
e71309b
Move up apiURL option. PR corrections
Jul 13, 2020
ff42f8c
rename setApiHandler to apiSpecHandler, check for null scheme
Jul 13, 2020
541a5e5
rename apiSpecHandler to apiSpecTransform
Jul 13, 2020
e26d6d5
Update NEWS according to PR suggestion.
Jul 13, 2020
b90630f
Merge remote-tracking branch 'upstream/master' into interface_mount
Jul 19, 2020
3f6f397
removing arguments swagger, swaggerCallback and ... from run R6 plumb…
Jul 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Expand Up @@ -79,6 +79,7 @@ Collate:
'serializer-yaml.R'
'serializer.R'
'session-cookie.R'
'ui.R'
'utf8.R'
'zzz.R'
RoxygenNote: 7.1.0
1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -4,6 +4,7 @@ export(PlumberEndpoint)
export(PlumberStatic)
export(addParser)
export(addSerializer)
export(add_ui)
export(do_configure_https)
export(do_deploy_api)
export(do_forward)
Expand Down
16 changes: 10 additions & 6 deletions NEWS.md
Expand Up @@ -18,27 +18,32 @@ plumber 1.0.0
API were using encrypted cookies and an attacker knew the encryption key in
order to craft arbitrary cookies. (#325)


### Breaking changes

* Plumber's swagger definition is now defined using
[OpenAPI 3](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md),
* Plumber's OpenAPI Specification is now defined using
[OpenAPI 3](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md),
upgrading from Swagger Specification. (#365)

* Plumber router `$run()` method arguments `swagger` and `swaggerCallback` deprecated. Parameter `swaggerCallback` replaced by `callback`. User interface is now enabled by default and managed through Plumber router `$setUI()` method and option `plumber.ui`. (@meztez, #562)

* The source files used in plumber **must use** the UTF-8 encoding if they contain
non-ASCII characters (@shrektan, #312,
#328).

* R repository modified to `focal-cran40` using Ubuntu 20.04 LTS for digital ocean provisioning (@meztez, #529)


### New features

* Generalize user interface integration. Plumber can now use other OpenAPI compatible user interfaces like `RapiDoc` (https://github.com/mrin9/RapiDoc) and `Redoc` (https://github.com/Redocly/redoc). Pending CRAN approbations, R packages for
both UIs integration are available from https://github.com/meztez/rapidoc/ and https://github.com/meztez/redoc/. (@meztez, #562)

* Added support for promises in endpoints, filters, and hooks. (#248)

* Add support for `#' @plumber` tag to gain programmatic access to the `plumber` router via `function(pr) {....}`. (@meztez and @blairj09, #568)

* Added Swagger support for array parameters using syntax `name:[type]` and new type `list` (synonym df, data.frame). (@meztez, #532)
* Added OpenAPI support for array parameters using syntax `name:[type]` and new type `list` (synonym df, data.frame). (@meztez, #532)

* Added user provided OpenAPI Specification handler to Plumber router. Use `apiSpecTransform()` to provide a function to alter the Plumber generated OpenAPI Specification returned by Plumber router method `$apiSpec()`. This also affects `/openapi.json` and `/openapi.yaml` (#365)(@meztez, #562)

* Added support to a router's run method to allow the `swagger` parameter to be a function that
enhances the existing swagger specification before being returned to `/openapi.json`. (#365)
Expand Down Expand Up @@ -105,7 +110,6 @@ plumber 1.0.0
* Date response header is now supplied by httpuv and not plumber. Fixes non standard date response header issues when using different locales. (@shrektan, #319, #380)



plumber 0.4.6
--------------------------------------------------------------------------------
* BUGFIX: Hooks that accept a `value` argument (`postroute`, `preserialize`,
Expand Down
1 change: 1 addition & 0 deletions R/globals.R
Expand Up @@ -2,3 +2,4 @@
.globals$serializers <- list()
.globals$processors <- new.env()
.globals$parsers <- list(func = list(), pattern = list())
.globals$UIs <- list()
6 changes: 4 additions & 2 deletions R/openapi-spec.R
Expand Up @@ -13,10 +13,12 @@ endpointSpecification <- function(routerEndpointEntry, path = routerEndpointEntr

# Get the params from the path
pathParams <- routerEndpointEntry$getTypedParams()
# Get the params from endpoint func
# Get the params from endpoint expression
funcParams <- routerEndpointEntry$getFuncParams()
# Get the plumber decoration defined endpoint params
endpointParams <- routerEndpointEntry$getEndpointParams()
for (verb in routerEndpointEntry$verbs) {
params <- parametersSpecification(routerEndpointEntry$params, pathParams, funcParams)
params <- parametersSpecification(endpointParams, pathParams, funcParams)

# If we haven't already documented a path param, we should add it here.
# FIXME: warning("Undocumented path parameters: ", paste0())
Expand Down
66 changes: 45 additions & 21 deletions R/plumber-options.R
@@ -1,60 +1,84 @@

#' How to use Plumber options
#' Plumber options
#'
#' @section Options:
#' There are a number of global options that affect Plumber's behavior. These can
#' be set globally with [options()] or with [options_plumber()]. Options set using
#' [options_plumber()] should not include the `plumber.` prefix.
#'
#' \describe{
#' \item{`plumber.apiHost` (defaults to `host` defined by `run` method, or an empty string
#' when used outside a running router)}{Host used to build UI url and server url for
#' OpenAPI specification.}
#' \item{`plumber.debug` (defaults to `FALSE`)}{Provides more insight into your API errors. Alternatively,
#' use parameter `debug` of plumber router `run` method}
#' \item{`plumber.maxRequestSize` (defaults to `0`)}{Maximum length in bytes of request body. Body larger
#' than maximum are rejected with http error 413. `0` means unlimited size.}
#' \item{`plumber.postBody` (defaults to `TRUE`)}{Copy post body content to `req$postBody` using system encoding.
#' \item{`plumber.apiURL`}{UI url and server urls for OpenAPI Specification respecting
#' pattern `scheme://host:port/path`. Other UI url options will be ignored when set.}
#' \item{`plumber.apiScheme`}{Scheme used to build UI url and server url for
#' OpenAPI Specification. Defaults to `http`, or an empty string
#' when used outside a running router}
#' \item{`plumber.apiHost`}{Host used to build UI url and server url for
#' OpenAPI Specification. Defaults to `host` defined by `run` method, or an empty string
#' when used outside a running router}
#' \item{`plumber.apiPort`}{Port used to build UI url and server url for
#' OpenAPI Specification. Defaults to `port` defined by `run` method, or an empty string
#' when used outside a running router}
#' \item{`plumber.apiPath`}{Path used to build UI url and server url for
#' OpenAPI Specification. Defaults to an empty string}
#' \item{`plumber.debug`}{Provides more insight into your API errors. Alternatively,
#' use parameter `debug` of plumber router `run` method. Defaults to `FALSE`}
#' \item{`plumber.maxRequestSize`}{Maximum length in bytes of request body. Body larger
#' than maximum are rejected with http error 413. `0` means unlimited size. Defaults to `0`}
#' \item{`plumber.postBody`}{Copy post body content to `req$postBody` using system encoding.
#' This should be set to `FALSE` if you do not need it. Default is `TRUE` to preserve compatibility with
#' previous version behavior.}
#' \item{`plumber.port` (defaults to `NULL`)}{Port Plumber will attempt to use to start http server.
#' If the port is already in use, server will not be able to start.}
#' \item{`plumber.sharedSecret` (defaults to `NULL`)}{Shared secret used to filter incoming request.
#' previous version behavior. Defaults to `TRUE`}
#' \item{`plumber.port`}{Port Plumber will attempt to use to start http server.
#' If the port is already in use, server will not be able to start. Defaults to `NULL`}
#' \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.}
#' \item{`plumber.swagger.url` (defaults to `NULL`)}{A function. Called with
#' `PLUMBER_SHARED_SECRET`. Failure to match results in http error 400. Defaults to `NULL`}
#' \item{`plumber.ui`}{Name of the UI interface to use. Defaults to `TRUE`}
#' \item{`plumber.ui.callback`}{A function. Called with
#' a single parameter corresponding to ui url after Plumber server is ready. This can be used
#' by RStudio to open UI when API is ran for the editor.}
#' by RStudio to open UI when API is ran for the editor. Defaults to option `plumber.swagger.url`}
#' }
#'
#' @param apiScheme see details
#' @param apiHost see details
#' @param apiPort see details
#' @param apiPath see details
#' @param apiURL see details
#' @param debug see details
#' @param maxRequestSize see details
#' @param postBody see details
#' @param port see details
#' @param sharedSecret see details
#' @param swagger.url see details
#' @param ui see details
#' @param ui.callback see details
#' @return
#' The complete, prior set of [options()] values.
#' If a particular parameter is not supplied, it will return the current value.
#' If no parameters are supplied, all returned values will be the current [options()] values.
#' @export
options_plumber <- function(
apiScheme = getOption("plumber.apiScheme"),
apiHost = getOption("plumber.apiHost"),
apiPort = getOption("plumber.apiPort"),
apiPath = getOption("plumber.apiPath"),
apiURL = getOption("plumber.apiURL"),
debug = getOption("plumber.debug"),
maxRequestSize = getOption("plumber.maxRequestSize"),
postBody = getOption("plumber.postBody"),
port = getOption("plumber.port"),
sharedSecret = getOption("plumber.sharedSecret"),
swagger.url = getOption("plumber.swagger.url")
ui = getOption("plumber.ui"),
ui.callback = getOption("plumber.ui.callback")
) {
options(
plumber.apiScheme = apiScheme,
plumber.apiHost = apiHost,
plumber.apiPort = apiPort,
plumber.apiPath = apiPath,
plumber.apiURL = apiURL,
plumber.debug = debug,
plumber.maxRequestSize = maxRequestSize,
plumber.postBody = postBody,
plumber.port = port,
plumber.sharedSecret = sharedSecret,
plumber.swagger.url = swagger.url
plumber.ui = ui,
plumber.ui.callback = ui.callback
)
}
10 changes: 10 additions & 0 deletions R/plumber-step.R
Expand Up @@ -228,6 +228,16 @@ PlumberEndpoint <- R6Class(
#' @description retrieve endpoint expression parameters
getFuncParams = function() {
getArgsMetadata(private$func)
},
#' @description retrieve endpoint defined parameters
getEndpointParams = function() {
if (length(self$params) == 0) {
return(list())
}
if (isTRUE(is.na(self$params))) {
return(list())
}
self$params
}
),
private = list(
Expand Down