When defining plumber routers with comments, function parameters are inferred and matching query string parameters are automatically passed to the underlying function. Similar behavior is expected when programmatically defining handlers using the $handle method. However, the following error results:
library(plumber)
pr <- plumber$new()
pr$handle("GET", "/add", function(x, y) sum(as.numeric(x), as.numeric(y)))
pr$run()
#> Error in endpointParams[[p]] : subscript out of bounds
Full error traceback:
6. priorizeProperty(defaultApiType, endpointParams[[p]]$type, funcParams[[p]]$type) at openapi-spec.R#98
5. parametersSpecification(routerEndpointEntry$params, pathParams,
funcParams) at openapi-spec.R#19
4. endpointSpecification(endpointEntry, join_paths(parentPath, endpointEntry$path)) at plumber.R#1119
3. private$routerSpecificationInternal(self) at plumber.R#916
2. self$apiSpec() at plumber.R#319
1. pr$run()
I'll check but I believe it is fixed in one of the PR. Let me come back to you on this.
It's fixed in https://github.com/rstudio/plumber/pull/562 with
https://github.com/rstudio/plumber/blob/a2434b016021da3fc08f34240d4bffa33ec28ca5/R/openapi-spec.R#L19
Defaults endpoint params is NA and this cannot be subsetted as you can with NULL.
Instead getEndpointParams returns an empty list().
Fixed in #562
Most helpful comment
I'll check but I believe it is fixed in one of the PR. Let me come back to you on this.
It's fixed in https://github.com/rstudio/plumber/pull/562 with
https://github.com/rstudio/plumber/blob/a2434b016021da3fc08f34240d4bffa33ec28ca5/R/openapi-spec.R#L19
Defaults endpoint params is NA and this cannot be subsetted as you can with NULL.
Instead getEndpointParams returns an empty list().