fix issues reported by roxygen in r client (#13176)

This commit is contained in:
William Cheng 2022-08-13 12:23:49 +08:00 committed by GitHub
parent 123f92d136
commit 1f42b09b33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 83 additions and 42 deletions

View File

@ -173,7 +173,7 @@ ApiClient <- R6::R6Class(
#' @param content_types The HTTP content-type headers. #' @param content_types The HTTP content-type headers.
#' @param body The HTTP request body. #' @param body The HTTP request body.
#' @param is_oauth True if the endpoints required OAuth authentication. #' @param is_oauth True if the endpoints required OAuth authentication.
#' @param oauth_scoeps OAuth scopes. #' @param oauth_scopes OAuth scopes.
#' @param stream_callback Callback function to process the data stream. #' @param stream_callback Callback function to process the data stream.
#' @param ... Other optional arguments. #' @param ... Other optional arguments.
#' @return HTTP response #' @return HTTP response
@ -204,7 +204,7 @@ ApiClient <- R6::R6Class(
#' @param content_types The HTTP content-type headers. #' @param content_types The HTTP content-type headers.
#' @param body The HTTP request body. #' @param body The HTTP request body.
#' @param is_oauth True if the endpoints required OAuth authentication. #' @param is_oauth True if the endpoints required OAuth authentication.
#' @param oauth_scoeps OAuth scopes. #' @param oauth_scopes OAuth scopes.
#' @param stream_callback Callback function to process data stream. #' @param stream_callback Callback function to process data stream.
#' @param ... Other optional arguments. #' @param ... Other optional arguments.
#' @return HTTP response #' @return HTTP response

View File

@ -1,48 +1,89 @@
#' @docType class
#' @title {{classname}}
#' @description {{classname}} Class
#' @format An \code{R6Class} generator object
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export #' @export
{{#allowableValues}} {{#allowableValues}}
{{classname}} <- R6::R6Class( {{classname}} <- R6::R6Class(
"{{classname}}", "{{classname}}",
public = list( public = list(
initialize = function(...) { #' Initialize a new {{{classname}}} class.
local.optional.var <- list(...) #'
val <- unlist(local.optional.var) #' @description
enumvec <- .parse_{{name}}() #' Initialize a new {{{classname}}} class.
#'
#' @param ... Optional arguments.
#' @export
initialize = function(...) {
local.optional.var <- list(...)
val <- unlist(local.optional.var)
enumvec <- .parse_{{name}}()
stopifnot(length(val) == 1L) stopifnot(length(val) == 1L)
if (!val %in% enumvec) if (!val %in% enumvec)
stop("Use one of the valid values: ", stop("Use one of the valid values: ",
paste0(enumvec, collapse = ", ")) paste0(enumvec, collapse = ", "))
private$value <- val private$value <- val
}, },
toJSON = function() { #' To JSON string
jsonlite::toJSON(private$value, auto_unbox = TRUE) #'
}, #' @description
fromJSON = function({{classname}}Json) { #' To JSON String
private$value <- jsonlite::fromJSON({{classname}}Json, #'
simplifyVector = FALSE) #' @return {{{classname}}} in JSON format
self #' @export
}, toJSON = function() {
toJSONString = function() { jsonlite::toJSON(private$value, auto_unbox = TRUE)
as.character(jsonlite::toJSON(private$value, },
auto_unbox = TRUE)) #' Deserialize JSON string into an instance of {{{classname}}}
}, #'
fromJSONString = function({{classname}}Json) { #' @description
private$value <- jsonlite::fromJSON({{classname}}Json, #' Deserialize JSON string into an instance of {{{classname}}}
simplifyVector = FALSE) #'
self #' @param input_json the JSON input
} #' @return the instance of {{{classname}}}
), #' @export
private = list( fromJSON = function(input_json) {
value = NULL private$value <- jsonlite::fromJSON(input_json,
) simplifyVector = FALSE)
self
},
#' To JSON string
#'
#' @description
#' To JSON String
#'
#' @return {{{classname}}} in JSON format
#' @export
toJSONString = function() {
as.character(jsonlite::toJSON(private$value,
auto_unbox = TRUE))
},
#' Deserialize JSON string into an instance of {{{classname}}}
#'
#' @description
#' Deserialize JSON string into an instance of {{{classname}}}
#'
#' @param input_json the JSON input
#' @return the instance of {{{classname}}}
#' @export
fromJSONString = function(input_json) {
private$value <- jsonlite::fromJSON(input_json,
simplifyVector = FALSE)
self
}
),
private = list(
value = NULL
)
) )
# add to utils.R # add to utils.R
.parse_{{name}} <- function(vals) { .parse_{{name}} <- function(vals) {
res <- gsub("^\\[|\\]$", "", res <- gsub("^\\[|\\]$", "", "{{{values}}}")
"{{{values}}}" unlist(strsplit(res, ", "))
)
unlist(strsplit(res, ", "))
} }
{{/allowableValues}} {{/allowableValues}}

View File

@ -166,7 +166,7 @@ ApiClient <- R6::R6Class(
#' @param content_types The HTTP content-type headers. #' @param content_types The HTTP content-type headers.
#' @param body The HTTP request body. #' @param body The HTTP request body.
#' @param is_oauth True if the endpoints required OAuth authentication. #' @param is_oauth True if the endpoints required OAuth authentication.
#' @param oauth_scoeps OAuth scopes. #' @param oauth_scopes OAuth scopes.
#' @param stream_callback Callback function to process the data stream. #' @param stream_callback Callback function to process the data stream.
#' @param ... Other optional arguments. #' @param ... Other optional arguments.
#' @return HTTP response #' @return HTTP response
@ -197,7 +197,7 @@ ApiClient <- R6::R6Class(
#' @param content_types The HTTP content-type headers. #' @param content_types The HTTP content-type headers.
#' @param body The HTTP request body. #' @param body The HTTP request body.
#' @param is_oauth True if the endpoints required OAuth authentication. #' @param is_oauth True if the endpoints required OAuth authentication.
#' @param oauth_scoeps OAuth scopes. #' @param oauth_scopes OAuth scopes.
#' @param stream_callback Callback function to process data stream. #' @param stream_callback Callback function to process data stream.
#' @param ... Other optional arguments. #' @param ... Other optional arguments.
#' @return HTTP response #' @return HTTP response