-
Notifications
You must be signed in to change notification settings - Fork 258
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
Swaggerfile support for array parameters, object, files #532
Conversation
Performance testing on a puny old laptop from the ages with library library(plumber)
tmpf <- tempfile()
writeLines('
#* Echo back the input
#* @param msg:character The message to echo
#* @post /test8
function(msg = list(part1 = "a", part1 = "b", part1 = "c")) {
do.call(paste, msg)
}
', tmpf)
pr <- plumb(tmpf)
pr$run(port = 8477, swagger = FALSE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good PR to code review tomorrow
Merge remote-tracking branch 'upstream/master' into list_plumber_type # Conflicts: # NAMESPACE # R/plumber-step.R
Co-authored-by: Carson Sievert <cpsievert1@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking pretty good to me, pending the suggestions. @schloerke is to:
- Make sure that the unit (or other) tests cover the important code paths.
- Look into and possibly resolve Swaggerfile support for array parameters, object, files #532 (comment)
- In a different PR, leverage
webutils::parse_query()
insideparseQS()
I'm off for the weekend. I'll look into it on Monday. Enjoy your weekend! |
Super excited about multipart file upload! Is this documented? I cannot find it in |
No documented yet on rplumber.io. I believe the goal is to use pkgdown to build plumber documentation. There is another branch in development for that. I'm super pump too. |
I tried it, works great! Is there a way to upload an arbitrary number of files at the same time? |
@ThHarbig It would probably work via curl, I would mostly have to adapt the openapi spec generation. Please open a different issue so I can reference it in a PR. |
This is a great addition! Thank you very much. Just wondering if it would be possible to get an example of the file upload feature? I'm having some trouble getting it to work with the example above when i try to upload some pdfs. |
In the implementation that made it to master, you get a vector of raw bytes to play with. Here is a working example with the current master. #* @apiTitle Upload test
#* @param pdf:file
#* @post /upload
function(pdf) {
f <- tempfile()
on.exit(unlink(f), add = TRUE)
writeBin(as.raw(pdf), f, useBytes = TRUE)
finfo <- file.info(f)
finfo$mode <- as.character(finfo$mode)
finfo$real_filename <- attr(pdf, "filename")
finfo
} |
@meztez Thank you very much! This works great. |
@meztez sorry to bug you, but could you provide an example how to use this with |
yeah, the filename comes from the multipart form-data. plumber::options_plumber(port = 8004)
#* @param a_file:file
#* @post /upload
function(a_file) {
# Get a named list. The names correspond
# to the files names. The content of the list
# will depend on the content-type set
# for each files.
return(name_of_file = list(names(a_file), file_content_length = nchar(a_file[[1]])))
} with httr::POST f <- tempfile("stempy")
writeLines(stringi::stri_rand_strings(1, 100), f)
res <- httr::POST("http://127.0.0.1:8004/upload",
body = list(a_file = httr::upload_file(f)),
encode = "multipart")
httr::content(res) Should be similar with curl, files is specific to my system
|
thanks! i didn't know about |
Fixes #187
Add swagger support for array parameters per https://swagger.io/docs/specification/serialization/ using square brackets around typed parameters.
Add swagger support for openapi
object
type to be listed underrequestBody
using plumber typeslist
,df
anddata.frame
.Add swagger/plumber support for files upload, multipart content-type
Add support for detection of endpoint plumberExpression parameters.
Add support for custom body parsers, like serializers, more raw.
Around 30% overheads reduction for POST request with json body.
Syntax support for parameters would become :
So something like below works with a matching openapi file to go with it.
Notes:
object
parameters would not be supported in path parameters.Default upload location set to getOption("plumber.upload.dir", "."). Use multipart parse from mime package. (copied with very slight change to buffer size, filename decoding and file args response)
openapi field
example
forobject
feeded from plumberExpression arguments.Fixes:
Breaking:
req$postBody is raw since it can contains file and other breaking havoc on string elements.
Related:
#516, #512, #469, #509, #417, #523, #502, #463, #320
At this point I would need help to do more testing across different platforms.
Thank you, comments are welcome.
PR task list:
devtools::document()
See other PR for documentation, will update there if this one pass.