Hello!
I have my plumber API in the main directory of my R package. Is there a way to fill in the apiVersion with the version in the DESCRIPTION
file?
I have not dived into programmatically creating roxygen-like documentation in files before. Theoretically, I want to do something like this:
#* @apiTitle My Plumber API
#* @apiVersion `r desc::desc_get_version()`
Any thoughts on achieving this or if it's possible at all are greatly appreciated!
meztez
September 3, 2021, 9:54pm
2
I have the same need. That would be a good PR.
In the mean time, here's an ugly hack programmatically.
library(plumber)
pr <- pr()
pr$.__enclos_env__$private$globalSettings$info$version <- "4.0.0"
pr$run()
Less ugly hack by overwriting the spec using annotations
#* @plumber
function(pr) {
oas <- function(spec) {
spec$info$version <- packageVersion("plumber") |> as.character()
spec
}
pr$setApiSpec(oas)
}
#* @get /sample
function() {
"OK"
}
1 Like
Perfect! This gets me what I want I ended up with the following
#* @plumber
function(pr) {
oas <- function(spec) {
spec$info$version <- pkgload::pkg_version() %>% as.character()
spec$info$title <- "My API"
spec
}
pr$setApiSpec(oas)
}
I use to have the @apiTitle tag. But when I used this method it ended up appending the "@plumber " to the end of it. Easy modification with the code you shared! Thank you so much!
system
Closed
September 14, 2021, 10:12pm
4
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.