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

$handle method doesn't handle parameters as expected #591

Closed
blairj09 opened this issue Jul 9, 2020 · 2 comments
Closed

$handle method doesn't handle parameters as expected #591

blairj09 opened this issue Jul 9, 2020 · 2 comments

Comments

@blairj09
Copy link
Collaborator

blairj09 commented Jul 9, 2020

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() 
@meztez
Copy link
Collaborator

meztez commented Jul 9, 2020

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 #562 with

endpointParams <- routerEndpointEntry$getEndpointParams()

Defaults endpoint params is NA and this cannot be subsetted as you can with NULL.
Instead getEndpointParams returns an empty list().

@schloerke
Copy link
Collaborator

Fixed in #562

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants