From 5de43b4e5ffbe22838cfee13cb72ce03ca3fd860 Mon Sep 17 00:00:00 2001 From: Ramanth Date: Tue, 5 Mar 2019 15:53:01 +0530 Subject: [PATCH 1/2] updated toJSONString() to handle optional params when the optional params are not given by the user, the listContainer type params are being sent as empty [] which are being considered as empty values instead of null --- .../src/main/resources/r/model.mustache | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/model.mustache b/modules/openapi-generator/src/main/resources/r/model.mustache index 9c41f3a034c4..63ac983016e0 100644 --- a/modules/openapi-generator/src/main/resources/r/model.mustache +++ b/modules/openapi-generator/src/main/resources/r/model.mustache @@ -157,8 +157,8 @@ } {{/vars}} }, - toJSONString = function() { - sprintf( + toJSONString = function() { + outstring = sprintf( '{ {{#vars}} "{{baseName}}": @@ -181,24 +181,32 @@ {{/vars}} }', {{#vars}} + {{!AAPI Added the if else condition to handle null values}} + if (!is.null(self$`{{baseName}}`)) { {{#isListContainer}} {{#isPrimitiveType}} - paste(unlist(lapply(self$`{{{baseName}}}`, function(x) paste0('"', x, '"'))), collapse=","){{#hasMore}},{{/hasMore}} + paste(unlist(lapply(self$`{{{baseName}}}`, function(x) paste0('"', x, '"'))), collapse=",") {{/isPrimitiveType}} {{^isPrimitiveType}} - paste(unlist(lapply(self$`{{{baseName}}}`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox=TRUE))), collapse=","){{#hasMore}},{{/hasMore}} + paste(unlist(lapply(self$`{{{baseName}}}`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox=TRUE))), collapse=",") {{/isPrimitiveType}} {{/isListContainer}} {{^isListContainer}} {{#isPrimitiveType}} - self$`{{baseName}}`{{#hasMore}},{{/hasMore}} + self$`{{baseName}}` {{/isPrimitiveType}} {{^isPrimitiveType}} - jsonlite::toJSON(self$`{{baseName}}`$toJSON(), auto_unbox=TRUE){{#hasMore}},{{/hasMore}} + jsonlite::toJSON(self$`{{baseName}}`$toJSON(), auto_unbox=TRUE) {{/isPrimitiveType}} {{/isListContainer}} + } + else{ + "null" + }{{#hasMore}},{{/hasMore}} {{/vars}} ) + outstring = gsub("[\r\n]| ", "", outstring) + gsub(':\\[null\\]|:\\\"null\\\"',':null',outstring) }, fromJSONString = function({{classname}}Json) { {{classname}}Object <- jsonlite::fromJSON({{classname}}Json) From 0cd42fa5177a1c7390f2505d16a1361304742a86 Mon Sep 17 00:00:00 2001 From: Ramanth Date: Tue, 5 Mar 2019 15:55:35 +0530 Subject: [PATCH 2/2] fixed the indentation mismatch --- .../src/main/resources/r/model.mustache | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/model.mustache b/modules/openapi-generator/src/main/resources/r/model.mustache index 63ac983016e0..7217a6575532 100644 --- a/modules/openapi-generator/src/main/resources/r/model.mustache +++ b/modules/openapi-generator/src/main/resources/r/model.mustache @@ -181,8 +181,8 @@ {{/vars}} }', {{#vars}} - {{!AAPI Added the if else condition to handle null values}} - if (!is.null(self$`{{baseName}}`)) { + {{! Added the if else condition to handle null values}} + if (!is.null(self$`{{baseName}}`)) { {{#isListContainer}} {{#isPrimitiveType}} paste(unlist(lapply(self$`{{{baseName}}}`, function(x) paste0('"', x, '"'))), collapse=",") @@ -199,10 +199,10 @@ jsonlite::toJSON(self$`{{baseName}}`$toJSON(), auto_unbox=TRUE) {{/isPrimitiveType}} {{/isListContainer}} - } - else{ - "null" - }{{#hasMore}},{{/hasMore}} + } + else{ + "null" + }{{#hasMore}},{{/hasMore}} {{/vars}} ) outstring = gsub("[\r\n]| ", "", outstring)