Skip to content

Commit 2b702ca

Browse files
committed
Merge branch 'feat/r-client-skip-parsing' of https://github.com/mattpollock/openapi-generator into mattpollock-feat/r-client-skip-parsing
2 parents 396c4c6 + 122acd2 commit 2b702ca

File tree

19 files changed

+674
-222
lines changed

19 files changed

+674
-222
lines changed

modules/openapi-generator/src/main/resources/r/api.mustache

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,13 @@
142142
#' @param data_file (optional) name of the data file to save the result
143143
{{/returnType}}
144144
#' @param ... Other optional arguments
145+
{{#returnType}}
146+
#' @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.
147+
{{/returnType}}
145148
#'
146149
#' @return {{{returnType}}}{{^returnType}}void{{/returnType}}
147-
{{{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}}...) {
148-
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}}...)
150+
{{{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}}) {
151+
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}})
149152
{{#vendorExtensions.x-streaming}}
150153
if (typeof(stream_callback) == "closure") { # return void if streaming is enabled
151154
return(invisible(NULL))
@@ -178,9 +181,12 @@
178181
#' @param data_file (optional) name of the data file to save the result
179182
{{/returnType}}
180183
#' @param ... Other optional arguments
184+
{{#returnType}}
185+
#' @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.
186+
{{/returnType}}
181187
#'
182188
#' @return API response ({{{returnType}}}{{^returnType}}void{{/returnType}}) with additional information such as HTTP status code, headers
183-
{{{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}}...) {
189+
{{{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}}) {
184190
args <- list(...)
185191
query_params <- list()
186192
header_params <- c()
@@ -559,6 +565,10 @@
559565
if (!is.null(data_file)) {
560566
self$api_client$WriteFile(local_var_resp, data_file)
561567
}
568+
if (!.parse) {
569+
local_var_resp$content <- local_var_resp$response_as_text()
570+
return(local_var_resp)
571+
}
562572
563573
ApiResponse$new(content = content, response = resp, status_code = local_var_resp$status_code)
564574
{{/isPrimitiveType}}
@@ -567,6 +577,10 @@
567577
if (!is.null(data_file)) {
568578
self$api_client$WriteFile(local_var_resp, data_file)
569579
}
580+
if (!.parse) {
581+
local_var_resp$content <- local_var_resp$response_as_text()
582+
return(local_var_resp)
583+
}
570584
571585
deserialized_resp_obj <- tryCatch(
572586
self$api_client$DeserializeResponse(local_var_resp, "{{returnType}}"),

samples/client/echo_api/r/R/auth_api.R

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ AuthApi <- R6::R6Class(
7373
#'
7474
#' @param data_file (optional) name of the data file to save the result
7575
#' @param ... Other optional arguments
76+
#' @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.
7677
#'
7778
#' @return character
78-
TestAuthHttpBasic = function(data_file = NULL, ...) {
79-
local_var_response <- self$TestAuthHttpBasicWithHttpInfo(data_file = data_file, ...)
79+
TestAuthHttpBasic = function(data_file = NULL, ..., .parse = TRUE) {
80+
local_var_response <- self$TestAuthHttpBasicWithHttpInfo(data_file = data_file, ..., .parse = .parse)
8081
if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) {
8182
return(local_var_response$content)
8283
} else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) {
@@ -93,9 +94,10 @@ AuthApi <- R6::R6Class(
9394
#'
9495
#' @param data_file (optional) name of the data file to save the result
9596
#' @param ... Other optional arguments
97+
#' @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.
9698
#'
9799
#' @return API response (character) with additional information such as HTTP status code, headers
98-
TestAuthHttpBasicWithHttpInfo = function(data_file = NULL, ...) {
100+
TestAuthHttpBasicWithHttpInfo = function(data_file = NULL, ..., .parse = TRUE) {
99101
args <- list(...)
100102
query_params <- list()
101103
header_params <- c()
@@ -135,6 +137,10 @@ AuthApi <- R6::R6Class(
135137
if (!is.null(data_file)) {
136138
self$api_client$WriteFile(local_var_resp, data_file)
137139
}
140+
if (!.parse) {
141+
local_var_resp$content <- local_var_resp$response_as_text()
142+
return(local_var_resp)
143+
}
138144

139145
deserialized_resp_obj <- tryCatch(
140146
self$api_client$DeserializeResponse(local_var_resp, "character"),
@@ -168,10 +174,11 @@ AuthApi <- R6::R6Class(
168174
#'
169175
#' @param data_file (optional) name of the data file to save the result
170176
#' @param ... Other optional arguments
177+
#' @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.
171178
#'
172179
#' @return character
173-
TestAuthHttpBearer = function(data_file = NULL, ...) {
174-
local_var_response <- self$TestAuthHttpBearerWithHttpInfo(data_file = data_file, ...)
180+
TestAuthHttpBearer = function(data_file = NULL, ..., .parse = TRUE) {
181+
local_var_response <- self$TestAuthHttpBearerWithHttpInfo(data_file = data_file, ..., .parse = .parse)
175182
if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) {
176183
return(local_var_response$content)
177184
} else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) {
@@ -188,9 +195,10 @@ AuthApi <- R6::R6Class(
188195
#'
189196
#' @param data_file (optional) name of the data file to save the result
190197
#' @param ... Other optional arguments
198+
#' @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.
191199
#'
192200
#' @return API response (character) with additional information such as HTTP status code, headers
193-
TestAuthHttpBearerWithHttpInfo = function(data_file = NULL, ...) {
201+
TestAuthHttpBearerWithHttpInfo = function(data_file = NULL, ..., .parse = TRUE) {
194202
args <- list(...)
195203
query_params <- list()
196204
header_params <- c()
@@ -230,6 +238,10 @@ AuthApi <- R6::R6Class(
230238
if (!is.null(data_file)) {
231239
self$api_client$WriteFile(local_var_resp, data_file)
232240
}
241+
if (!.parse) {
242+
local_var_resp$content <- local_var_resp$response_as_text()
243+
return(local_var_resp)
244+
}
233245

234246
deserialized_resp_obj <- tryCatch(
235247
self$api_client$DeserializeResponse(local_var_resp, "character"),

0 commit comments

Comments
 (0)