From e0d6f7df1ff75affbdc10a57b3fd08b43379d32f Mon Sep 17 00:00:00 2001 From: Ramanth Addala Date: Wed, 4 Dec 2019 07:23:55 +0530 Subject: [PATCH] fix(r): fixing serializatin bug in empty json array (#4667) * fix(r): fixing serializatin bug in empty json array * fix(r): fixing serializatin bug in empty json array --- .../src/main/resources/r/api_client.mustache | 10 ++++++---- samples/client/petstore/R/R/api_client.R | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/api_client.mustache b/modules/openapi-generator/src/main/resources/r/api_client.mustache index eb70bad3447..22fd994ab64 100644 --- a/modules/openapi-generator/src/main/resources/r/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/r/api_client.mustache @@ -151,10 +151,12 @@ ApiClient <- R6::R6Class( } } } else { - returnObj <- vector("list", length = nrow(obj)) - if (nrow(obj) > 0) { - for (row in 1:nrow(obj)) { - returnObj[[row]] <- self$deserializeObj(obj[row, , drop = FALSE], innerReturnType, pkgEnv) + if(!is.null(nrow(obj))){ + returnObj <- vector("list", length = nrow(obj)) + if (nrow(obj) > 0) { + for (row in 1:nrow(obj)) { + returnObj[[row]] <- self$deserializeObj(obj[row, , drop = FALSE], innerReturnType, pkgEnv) + } } } } diff --git a/samples/client/petstore/R/R/api_client.R b/samples/client/petstore/R/R/api_client.R index 45396b84391..f6b8544aacd 100644 --- a/samples/client/petstore/R/R/api_client.R +++ b/samples/client/petstore/R/R/api_client.R @@ -149,10 +149,12 @@ ApiClient <- R6::R6Class( } } } else { - returnObj <- vector("list", length = nrow(obj)) - if (nrow(obj) > 0) { - for (row in 1:nrow(obj)) { - returnObj[[row]] <- self$deserializeObj(obj[row, , drop = FALSE], innerReturnType, pkgEnv) + if(!is.null(nrow(obj))){ + returnObj <- vector("list", length = nrow(obj)) + if (nrow(obj) > 0) { + for (row in 1:nrow(obj)) { + returnObj[[row]] <- self$deserializeObj(obj[row, , drop = FALSE], innerReturnType, pkgEnv) + } } } }