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 body The HTTP request body.
#' @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 ... Other optional arguments.
#' @return HTTP response
@ -204,7 +204,7 @@ ApiClient <- R6::R6Class(
#' @param content_types The HTTP content-type headers.
#' @param body The HTTP request body.
#' @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 ... Other optional arguments.
#' @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
{{#allowableValues}}
{{classname}} <- R6::R6Class(
"{{classname}}",
public = list(
initialize = function(...) {
local.optional.var <- list(...)
val <- unlist(local.optional.var)
enumvec <- .parse_{{name}}()
"{{classname}}",
public = list(
#' Initialize a new {{{classname}}} class.
#'
#' @description
#' 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)
stop("Use one of the valid values: ",
paste0(enumvec, collapse = ", "))
private$value <- val
},
toJSON = function() {
jsonlite::toJSON(private$value, auto_unbox = TRUE)
},
fromJSON = function({{classname}}Json) {
private$value <- jsonlite::fromJSON({{classname}}Json,
simplifyVector = FALSE)
self
},
toJSONString = function() {
as.character(jsonlite::toJSON(private$value,
auto_unbox = TRUE))
},
fromJSONString = function({{classname}}Json) {
private$value <- jsonlite::fromJSON({{classname}}Json,
simplifyVector = FALSE)
self
}
),
private = list(
value = NULL
)
if (!val %in% enumvec)
stop("Use one of the valid values: ",
paste0(enumvec, collapse = ", "))
private$value <- val
},
#' To JSON string
#'
#' @description
#' To JSON String
#'
#' @return {{{classname}}} in JSON format
#' @export
toJSON = function() {
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
fromJSON = function(input_json) {
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
.parse_{{name}} <- function(vals) {
res <- gsub("^\\[|\\]$", "",
"{{{values}}}"
)
unlist(strsplit(res, ", "))
res <- gsub("^\\[|\\]$", "", "{{{values}}}")
unlist(strsplit(res, ", "))
}
{{/allowableValues}}
{{/allowableValues}}

View File

@ -166,7 +166,7 @@ ApiClient <- R6::R6Class(
#' @param content_types The HTTP content-type headers.
#' @param body The HTTP request body.
#' @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 ... Other optional arguments.
#' @return HTTP response
@ -197,7 +197,7 @@ ApiClient <- R6::R6Class(
#' @param content_types The HTTP content-type headers.
#' @param body The HTTP request body.
#' @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 ... Other optional arguments.
#' @return HTTP response