[英]Programmatically use @apiVersion with plumber
我使用管道工編寫了一個 API 端點。 我在注釋中使用@apiVersion 標記用於文檔目的,並希望將版本作為字符串添加到 JSON object 我的端點返回:
#' @apiTitle My cool API
#' @apiDescription This API does something.
#' @apiVersion 0.1
#* @serializer unboxedJSON
#* @post /call_me
function() {
return(list(my_value = 42, api_version = "0.1"))
}
有沒有辦法以編程方式訪問@apiVersion 中的字符串?
apiVersion 信息存儲在路由器私有全局設置中。
pr$.__enclos_env__$private$globalSettings$info$version
它們是解析管道工文件時要讀取的最后信息,因此在文件解析完成之前它們不可用。
這是直接使用apiSpec
的一種方法。
#' @apiTitle My cool API
#' @apiDescription This API does something.
#' @apiVersion 0.599
#' @plumber
function(pr) {
assign("apiV",
function() {
pr$getApiSpec()$info$version
# or the line below if endpoint response time is important
# pr$.__enclos_env__$private$globalSettings$info$version
},
envir = pr$environment)
}
#* @serializer unboxedJSON
#* @post /call_me
function() {
return(list(my_value = 42, api_version = apiV()))
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.