From 1f42b09b3377dbb04d10ffc038c607e23091b412 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 13 Aug 2022 12:23:49 +0800 Subject: [PATCH] fix issues reported by roxygen in r client (#13176) --- .../r/libraries/httr2/api_client.mustache | 4 +- .../src/main/resources/r/modelEnum.mustache | 117 ++++++++++++------ .../client/petstore/R-httr2/R/api_client.R | 4 +- 3 files changed, 83 insertions(+), 42 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache b/modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache index bf4f3580efe..b97fa13c584 100644 --- a/modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache @@ -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 diff --git a/modules/openapi-generator/src/main/resources/r/modelEnum.mustache b/modules/openapi-generator/src/main/resources/r/modelEnum.mustache index f82b345e404..8471a94cad3 100644 --- a/modules/openapi-generator/src/main/resources/r/modelEnum.mustache +++ b/modules/openapi-generator/src/main/resources/r/modelEnum.mustache @@ -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}} \ No newline at end of file +{{/allowableValues}} diff --git a/samples/client/petstore/R-httr2/R/api_client.R b/samples/client/petstore/R-httr2/R/api_client.R index a368e8a5360..f0c4aab978e 100644 --- a/samples/client/petstore/R-httr2/R/api_client.R +++ b/samples/client/petstore/R-httr2/R/api_client.R @@ -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