Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions modules/openapi-generator/src/main/resources/r/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,13 @@
#' @param data_file (optional) name of the data file to save the result
{{/returnType}}
#' @param ... Other optional arguments
{{#returnType}}
#' @param .parse Logical. If \code{TRUE} then the response will be parsed to a generated type. If \code{FALSE} the response will be returned as unparsed text.
{{/returnType}}
#'
#' @return {{{returnType}}}{{^returnType}}void{{/returnType}}
{{{operationId}}} = function({{#requiredParams}}{{paramName}}, {{/requiredParams}}{{#optionalParams}}{{paramName}} = {{^defaultValue}}NULL{{/defaultValue}}{{{defaultValue}}}, {{/optionalParams}}{{#vendorExtensions.x-streaming}}stream_callback = NULL, {{/vendorExtensions.x-streaming}}{{#returnType}}data_file = NULL, {{/returnType}}...) {
local_var_response <- self${{{operationId}}}{{WithHttpInfo}}({{#allParams}}{{paramName}}, {{/allParams}}{{#vendorExtensions.x-streaming}}stream_callback = stream_callback, {{/vendorExtensions.x-streaming}}{{#returnType}}data_file = data_file, {{/returnType}}...)
{{{operationId}}} = function({{#requiredParams}}{{paramName}}, {{/requiredParams}}{{#optionalParams}}{{paramName}} = {{^defaultValue}}NULL{{/defaultValue}}{{{defaultValue}}}, {{/optionalParams}}{{#vendorExtensions.x-streaming}}stream_callback = NULL, {{/vendorExtensions.x-streaming}}{{#returnType}}data_file = NULL, {{/returnType}}...{{#returnType}}, .parse = TRUE{{/returnType}}) {
local_var_response <- self${{{operationId}}}{{WithHttpInfo}}({{#allParams}}{{paramName}}, {{/allParams}}{{#vendorExtensions.x-streaming}}stream_callback = stream_callback, {{/vendorExtensions.x-streaming}}{{#returnType}}data_file = data_file, {{/returnType}}...{{#returnType}}, .parse = .parse{{/returnType}})
{{#vendorExtensions.x-streaming}}
if (typeof(stream_callback) == "closure") { # return void if streaming is enabled
return(invisible(NULL))
Expand Down Expand Up @@ -179,9 +182,12 @@
#' @param data_file (optional) name of the data file to save the result
{{/returnType}}
#' @param ... Other optional arguments
{{#returnType}}
#' @param .parse Logical. If \code{TRUE} then the response will be parsed to a generated type. If \code{FALSE} the response will be returned as unparsed text.
{{/returnType}}
#'
#' @return API response ({{{returnType}}}{{^returnType}}void{{/returnType}}) with additional information such as HTTP status code, headers
{{{operationId}}}{{WithHttpInfo}} = function({{#requiredParams}}{{paramName}}, {{/requiredParams}}{{#optionalParams}}{{paramName}} = {{^defaultValue}}NULL{{/defaultValue}}{{{defaultValue}}}, {{/optionalParams}}{{#vendorExtensions.x-streaming}}stream_callback = NULL, {{/vendorExtensions.x-streaming}}{{#returnType}}data_file = NULL, {{/returnType}}...) {
{{{operationId}}}{{WithHttpInfo}} = function({{#requiredParams}}{{paramName}}, {{/requiredParams}}{{#optionalParams}}{{paramName}} = {{^defaultValue}}NULL{{/defaultValue}}{{{defaultValue}}}, {{/optionalParams}}{{#vendorExtensions.x-streaming}}stream_callback = NULL, {{/vendorExtensions.x-streaming}}{{#returnType}}data_file = NULL, {{/returnType}}...{{#returnType}}, .parse = TRUE{{/returnType}}) {
args <- list(...)
query_params <- list()
header_params <- c()
Expand Down Expand Up @@ -560,6 +566,10 @@
if (!is.null(data_file)) {
self$api_client$WriteFile(local_var_resp, data_file)
}
if (!.parse) {
local_var_resp$content <- local_var_resp$response_as_text()
return(local_var_resp)
}

ApiResponse$new(content,resp)
{{/isPrimitiveType}}
Expand All @@ -568,6 +578,10 @@
if (!is.null(data_file)) {
self$api_client$WriteFile(local_var_resp, data_file)
}
if (!.parse) {
local_var_resp$content <- local_var_resp$response_as_text()
return(local_var_resp)
}

deserialized_resp_obj <- tryCatch(
self$api_client$DeserializeResponse(local_var_resp, "{{returnType}}"),
Expand Down
24 changes: 18 additions & 6 deletions samples/client/echo_api/r/R/auth_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ AuthApi <- R6::R6Class(
#'
#' @param data_file (optional) name of the data file to save the result
#' @param ... Other optional arguments
#' @param .parse Logical. If \code{TRUE} then the response will be parsed to a generated type. If \code{FALSE} the response will be returned as unparsed text.
#'
#' @return character
TestAuthHttpBasic = function(data_file = NULL, ...) {
local_var_response <- self$TestAuthHttpBasicWithHttpInfo(data_file = data_file, ...)
TestAuthHttpBasic = function(data_file = NULL, ..., .parse = TRUE) {
Copy link
Contributor Author

@mattpollock mattpollock Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This follows the ..., .variable = some-default pattern common for forcing named parameters when overriding defaults. E.g., see https://purrr.tidyverse.org/reference/map_if.html

I opted for .parse over parse to avoid potential conflicts with endpoint arguments since R supports variable names that begin with a period.

local_var_response <- self$TestAuthHttpBasicWithHttpInfo(data_file = data_file, ..., .parse = .parse)
if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) {
return(local_var_response$content)
} else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) {
Expand All @@ -93,9 +94,10 @@ AuthApi <- R6::R6Class(
#'
#' @param data_file (optional) name of the data file to save the result
#' @param ... Other optional arguments
#' @param .parse Logical. If \code{TRUE} then the response will be parsed to a generated type. If \code{FALSE} the response will be returned as unparsed text.
#'
#' @return API response (character) with additional information such as HTTP status code, headers
TestAuthHttpBasicWithHttpInfo = function(data_file = NULL, ...) {
TestAuthHttpBasicWithHttpInfo = function(data_file = NULL, ..., .parse = TRUE) {
args <- list(...)
query_params <- list()
header_params <- c()
Expand Down Expand Up @@ -135,6 +137,10 @@ AuthApi <- R6::R6Class(
if (!is.null(data_file)) {
self$api_client$WriteFile(local_var_resp, data_file)
}
if (!.parse) {
local_var_resp$content <- local_var_resp$response_as_text()
return(local_var_resp)
}

deserialized_resp_obj <- tryCatch(
self$api_client$DeserializeResponse(local_var_resp, "character"),
Expand Down Expand Up @@ -164,10 +170,11 @@ AuthApi <- R6::R6Class(
#'
#' @param data_file (optional) name of the data file to save the result
#' @param ... Other optional arguments
#' @param .parse Logical. If \code{TRUE} then the response will be parsed to a generated type. If \code{FALSE} the response will be returned as unparsed text.
#'
#' @return character
TestAuthHttpBearer = function(data_file = NULL, ...) {
local_var_response <- self$TestAuthHttpBearerWithHttpInfo(data_file = data_file, ...)
TestAuthHttpBearer = function(data_file = NULL, ..., .parse = TRUE) {
local_var_response <- self$TestAuthHttpBearerWithHttpInfo(data_file = data_file, ..., .parse = .parse)
if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) {
return(local_var_response$content)
} else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) {
Expand All @@ -184,9 +191,10 @@ AuthApi <- R6::R6Class(
#'
#' @param data_file (optional) name of the data file to save the result
#' @param ... Other optional arguments
#' @param .parse Logical. If \code{TRUE} then the response will be parsed to a generated type. If \code{FALSE} the response will be returned as unparsed text.
#'
#' @return API response (character) with additional information such as HTTP status code, headers
TestAuthHttpBearerWithHttpInfo = function(data_file = NULL, ...) {
TestAuthHttpBearerWithHttpInfo = function(data_file = NULL, ..., .parse = TRUE) {
args <- list(...)
query_params <- list()
header_params <- c()
Expand Down Expand Up @@ -226,6 +234,10 @@ AuthApi <- R6::R6Class(
if (!is.null(data_file)) {
self$api_client$WriteFile(local_var_resp, data_file)
}
if (!.parse) {
local_var_resp$content <- local_var_resp$response_as_text()
return(local_var_resp)
}

deserialized_resp_obj <- tryCatch(
self$api_client$DeserializeResponse(local_var_resp, "character"),
Expand Down
Loading
Loading