-
Notifications
You must be signed in to change notification settings - Fork 256
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
update to generate swagger docs for mounted routers #274
Conversation
Codecov Report
@@ Coverage Diff @@
## master #274 +/- ##
==========================================
+ Coverage 87.91% 89.89% +1.97%
==========================================
Files 25 25
Lines 1109 1128 +19
==========================================
+ Hits 975 1014 +39
+ Misses 134 114 -20
Continue to review full report at Codecov.
|
Hi @bradleyhd ! Thanks for the PR! Good catch! (Unsolicited PRs are welcome anytime!) Couple things to address.
mountedEndpoints <- unlist(lapply(names(self$mounts), function(path) {
...
if (length(mountEndpoints) == 0) return(NULL)
...
}))
endpoints <- c(endpoints, mountedEndpoints)
pr <- plumber$new()
pr$handle("GET", "/nested/path/here", function(){})
pr$handle("POST", "/nested/path/here", function(){})
stat <- PlumberStatic$new(".")
pr2 <- plumber$new()
pr2$handle("POST", "/something", function(){})
pr2$handle("GET", "/", function(){})
pr3 <- plumber$new()
pr3$handle("POST", "/else", function(){})
pr3$handle("GET", "/", function(){})
pr$mount("/static", stat)
pr2$mount("/sub3", pr3)
pr$mount("/sub2", pr2)
pr$swaggerFile() Thank you in advance, |
Yes, it solves #219 |
Thanks for the pointers/feedback! I've updated to walk routers/mounts recursively and it seems to work on your example and a few others I tried out. However, if you repeatedly call |
Correct. This is caused by I've added some small GitHub review changes. By cloning Last thing before merging... Add a test in
Thank you! |
@schloerke maybe I'm not looking in the right place, but I don't see any review changes. Mind re-adding them? |
R/plumber.R
Outdated
endpointEntry | ||
}) | ||
|
||
endpoint |
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.
change to endpointEntries
as the value of endpointEntries
will be different than endpoint
.
parentPath <- sub("[/]$", "", parentPath) | ||
endpoints <- lapply(router$endpoints, function(endpoint){ | ||
|
||
endpointEntries <- lapply(endpoint, function(endpointEntry){ |
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.
add a line just inside function(endpointEntry)
to be
function(enpointEntry) {
enpointEntry <- enpointEntry$clone()
...
}
It avoids altering the global endpointEntry$path
value
My fault.. never hit "submit review". (GitHub review is new to me) |
No worries at all. I've pushed the test and clone changes, let me know if there's anything else! |
mountedEndpoints <- private$swaggerFileWalkMountsInternal(mountedSubrouter, paste(parentPath, mountPath, sep="/")) | ||
})) | ||
|
||
c(endpoints, list(mountedEndpoints)) |
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.
Is there a reason you call list
here? My understanding is that at this point endpoints
is a list and mountedEndpoints
is a character vector, so the result will definitely be a list.
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.
@alandipert I'm a bit fuzzy on the types but I think endpoints is a list of lists and mountedEndpoints without the extra list
call is just a list. If you remove that call and try to run swagger documentation, you'll get Error in for (e in fil) { : invalid for() loop sequence
. When I print out the result of calling c
above without modification, I get entries like
[[1]]`$__no-preempt__14`
<PlumberEndpoint>
...
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.
Ah, that makes sense, thanks for clarifying.
* update to generate swagger docs for mounted routers * update swagger doc generation to recursively walk mounted routers * add test for swaggerFile paths and clone endpointEntry * prepareSwaggerEndpoints should use entries and not nested entries within endpoints * Collect endpoint entries, not nested entries within endpoints that contain filter structure use small helper methods to deal with slashes For the endgame of swagger docs, filter information is not needed and should be removed to not misrepresent that it does exist. A true "flatten router" method should be implemented. Then, swaggerFileWalkMountsInternal will become `flatten(pr)$endpoints` * add swaggerFile recursive mounts tests multiple entries static file parameter in path filter nested mounts trailing slash in route * add news item for #274 * tag bradleyhd in news * document * use regular roxygen version
Merged in #280 Thank you @bradleyhd!! |
Hi, a quick question. Do you upload the version with this feature 0.4.6.9000 (based on versión downloaded by install_github) to CRAN repositories?. Same case on 0.5.0 version, based on changelogs. I understand that both versions are more similars, one is a snapshot another is a release. Am I mistaked? |
Hi,
I'm not sure if plumber is currently taking unsolicited PRs, but I'm new to both R and plumber and really wanted the automatic swagger doc generation to work with mounted routers. These changes seem to work for me (at least for walking this list of endpoints for the router children of the root router). Open to any/all feedback/criticism and happy to revise.
Thanks!
(I think this addresses #219)