diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index 7f21323c95f7..0fc38a78916b 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -164,6 +164,8 @@ resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { apiResponse$content + } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { + apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { apiResponse } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { diff --git a/modules/openapi-generator/src/main/resources/r/model.mustache b/modules/openapi-generator/src/main/resources/r/model.mustache index 3b83d4695620..ee20e432e742 100644 --- a/modules/openapi-generator/src/main/resources/r/model.mustache +++ b/modules/openapi-generator/src/main/resources/r/model.mustache @@ -23,7 +23,7 @@ local.optional.var <- list(...) {{#requiredVars}} if (!missing(`{{baseName}}`)) { - {{^isListContainer}} + {{^isContainer}} {{#isInteger}} stopifnot(is.numeric(`{{baseName}}`), length(`{{baseName}}`) == 1) {{/isInteger}} @@ -48,8 +48,8 @@ {{^isPrimitiveType}} stopifnot(R6::is.R6(`{{baseName}}`)) {{/isPrimitiveType}} - {{/isListContainer}} - {{#isListContainer}} + {{/isContainer}} + {{#isContainer}} {{#isPrimitiveType}} stopifnot(is.vector(`{{baseName}}`), length(`{{baseName}}`) != 0) sapply(`{{baseName}}`, function(x) stopifnot(is.character(x))) @@ -58,13 +58,13 @@ stopifnot(is.vector(`{{baseName}}`), length(`{{baseName}}`) != 0) sapply(`{{baseName}}`, function(x) stopifnot(R6::is.R6(x))) {{/isPrimitiveType}} - {{/isListContainer}} + {{/isContainer}} self$`{{baseName}}` <- `{{baseName}}` } {{/requiredVars}} {{#optionalVars}} if (!is.null(`{{baseName}}`)) { - {{^isListContainer}} + {{^isContainer}} {{#isInteger}} stopifnot(is.numeric(`{{baseName}}`), length(`{{baseName}}`) == 1) {{/isInteger}} @@ -89,8 +89,8 @@ {{^isPrimitiveType}} stopifnot(R6::is.R6(`{{baseName}}`)) {{/isPrimitiveType}} - {{/isListContainer}} - {{#isListContainer}} + {{/isContainer}} + {{#isContainer}} {{#isPrimitiveType}} stopifnot(is.vector(`{{baseName}}`), length(`{{baseName}}`) != 0) sapply(`{{baseName}}`, function(x) stopifnot(is.character(x))) @@ -99,7 +99,7 @@ stopifnot(is.vector(`{{baseName}}`), length(`{{baseName}}`) != 0) sapply(`{{baseName}}`, function(x) stopifnot(R6::is.R6(x))) {{/isPrimitiveType}} - {{/isListContainer}} + {{/isContainer}} self$`{{baseName}}` <- `{{baseName}}` } {{/optionalVars}} @@ -109,22 +109,32 @@ {{#vars}} if (!is.null(self$`{{baseName}}`)) { {{classname}}Object[['{{baseName}}']] <- - {{#isListContainer}} - {{#isPrimitiveType}} + {{#isContainer}} + {{#isListContainer}} + {{#isPrimitiveType}} self$`{{baseName}}` + {{/isPrimitiveType}} + {{^isPrimitiveType}} + lapply(self$`{{baseName}}`, function(x) x$toJSON()) {{/isPrimitiveType}} - {{^isPrimitiveType}} - sapply(self$`{{baseName}}`, function(x) x$toJSON()) - {{/isPrimitiveType}} - {{/isListContainer}} - {{^isListContainer}} - {{#isPrimitiveType}} + {{/isListContainer}} + {{#isMapContainer}} + {{#isPrimitiveType}} self$`{{baseName}}` - {{/isPrimitiveType}} - {{^isPrimitiveType}} + {{/isPrimitiveType}} + {{^isPrimitiveType}} + lapply(self$`{{baseName}}`, function(x) x$toJSON()) + {{/isPrimitiveType}} + {{/isMapContainer}} + {{/isContainer}} + {{^isContainer}} + {{#isPrimitiveType}} + self$`{{baseName}}` + {{/isPrimitiveType}} + {{^isPrimitiveType}} self$`{{baseName}}`$toJSON() - {{/isPrimitiveType}} - {{/isListContainer}} + {{/isPrimitiveType}} + {{/isContainer}} } {{/vars}} @@ -156,6 +166,7 @@ if (!is.null(self$`{{baseName}}`)) { sprintf( '"{{baseName}}": + {{#isContainer}} {{#isListContainer}} {{#isPrimitiveType}} {{#isNumeric}}[%d]{{/isNumeric}}{{^isNumeric}}[%s]{{/isNumeric}} @@ -163,31 +174,49 @@ {{^isPrimitiveType}}[%s] {{/isPrimitiveType}} {{/isListContainer}} - {{^isListContainer}} + {{#isMapContainer}} + {{#isPrimitiveType}} + {{#isNumeric}}%d{{/isNumeric}}{{^isNumeric}}"%s"{{/isNumeric}} + {{/isPrimitiveType}} + {{^isPrimitiveType}}%s + {{/isPrimitiveType}} + {{/isMapContainer}} + {{/isContainer}} + {{^isContainer}} {{#isPrimitiveType}} {{#isNumeric}}%d{{/isNumeric}}{{^isNumeric}}"%s"{{/isNumeric}} {{/isPrimitiveType}} {{^isPrimitiveType}}%s {{/isPrimitiveType}} - {{/isListContainer}}', + {{/isContainer}}', + {{#isContainer}} {{#isListContainer}} {{#isPrimitiveType}} 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, digits = NA))), collapse=",") + paste(sapply(self$`{{{baseName}}}`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox=TRUE, digits = NA)), collapse=",") {{/isPrimitiveType}} {{/isListContainer}} - {{^isListContainer}} + {{#isMapContainer}} + {{#isPrimitiveType}} + jsonlite::toJSON(lapply(self$`{{{baseName}}}`, function(x){ x }), auto_unbox = TRUE, digits=NA) + {{/isPrimitiveType}} + {{^isPrimitiveType}} + jsonlite::toJSON(lapply(self$`{{{baseName}}}`, function(x){ x$toJSON() }), auto_unbox = TRUE, digits=NA) + {{/isPrimitiveType}} + {{/isMapContainer}} + {{/isContainer}} + {{^isContainer}} {{#isPrimitiveType}} self$`{{baseName}}` {{/isPrimitiveType}} {{^isPrimitiveType}} jsonlite::toJSON(self$`{{baseName}}`$toJSON(), auto_unbox=TRUE, digits = NA) {{/isPrimitiveType}} - {{/isListContainer}} + {{/isContainer}} )}{{#hasMore}},{{/hasMore}} - {{/vars}} + {{/vars}} ) jsoncontent <- paste(jsoncontent, collapse = ",") paste('{', jsoncontent, '}', sep = "") diff --git a/samples/client/petstore/R/R/pet.R b/samples/client/petstore/R/R/pet.R index fd38160a957a..1b2f6161dd8c 100644 --- a/samples/client/petstore/R/R/pet.R +++ b/samples/client/petstore/R/R/pet.R @@ -84,7 +84,7 @@ Pet <- R6::R6Class( } if (!is.null(self$`tags`)) { PetObject[['tags']] <- - sapply(self$`tags`, function(x) x$toJSON()) + lapply(self$`tags`, function(x) x$toJSON()) } if (!is.null(self$`status`)) { PetObject[['status']] <- @@ -151,7 +151,7 @@ Pet <- R6::R6Class( '"tags": [%s] ', - paste(unlist(lapply(self$`tags`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox=TRUE, digits = NA))), collapse=",") + paste(sapply(self$`tags`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox=TRUE, digits = NA)), collapse=",") )}, if (!is.null(self$`status`)) { sprintf( diff --git a/samples/client/petstore/R/R/pet_api.R b/samples/client/petstore/R/R/pet_api.R index 7b653e00c9bb..7b038534f040 100644 --- a/samples/client/petstore/R/R/pet_api.R +++ b/samples/client/petstore/R/R/pet_api.R @@ -336,6 +336,8 @@ PetApi <- R6::R6Class( resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { apiResponse$content + } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { + apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { apiResponse } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { @@ -384,6 +386,8 @@ PetApi <- R6::R6Class( resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { apiResponse$content + } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { + apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { apiResponse } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { @@ -432,6 +436,8 @@ PetApi <- R6::R6Class( resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { apiResponse$content + } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { + apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { apiResponse } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { @@ -482,6 +488,8 @@ PetApi <- R6::R6Class( resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { apiResponse$content + } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { + apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { apiResponse } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { @@ -532,6 +540,8 @@ PetApi <- R6::R6Class( resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { apiResponse$content + } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { + apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { apiResponse } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { @@ -586,6 +596,8 @@ PetApi <- R6::R6Class( resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { apiResponse$content + } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { + apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { apiResponse } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { @@ -634,6 +646,8 @@ PetApi <- R6::R6Class( resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { apiResponse$content + } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { + apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { apiResponse } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { @@ -685,6 +699,8 @@ PetApi <- R6::R6Class( resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { apiResponse$content + } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { + apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { apiResponse } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { diff --git a/samples/client/petstore/R/R/store_api.R b/samples/client/petstore/R/R/store_api.R index e15d156052c6..d46e165c71bd 100644 --- a/samples/client/petstore/R/R/store_api.R +++ b/samples/client/petstore/R/R/store_api.R @@ -179,6 +179,8 @@ StoreApi <- R6::R6Class( resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { apiResponse$content + } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { + apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { apiResponse } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { @@ -223,6 +225,8 @@ StoreApi <- R6::R6Class( resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { apiResponse$content + } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { + apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { apiResponse } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { @@ -269,6 +273,8 @@ StoreApi <- R6::R6Class( resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { apiResponse$content + } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { + apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { apiResponse } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { @@ -319,6 +325,8 @@ StoreApi <- R6::R6Class( resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { apiResponse$content + } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { + apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { apiResponse } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { diff --git a/samples/client/petstore/R/R/user_api.R b/samples/client/petstore/R/R/user_api.R index f6a685f4de86..8eb742c60365 100644 --- a/samples/client/petstore/R/R/user_api.R +++ b/samples/client/petstore/R/R/user_api.R @@ -296,6 +296,8 @@ UserApi <- R6::R6Class( resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { apiResponse$content + } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { + apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { apiResponse } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { @@ -342,6 +344,8 @@ UserApi <- R6::R6Class( resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { apiResponse$content + } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { + apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { apiResponse } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { @@ -389,6 +393,8 @@ UserApi <- R6::R6Class( resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { apiResponse$content + } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { + apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { apiResponse } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { @@ -436,6 +442,8 @@ UserApi <- R6::R6Class( resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { apiResponse$content + } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { + apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { apiResponse } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { @@ -480,6 +488,8 @@ UserApi <- R6::R6Class( resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { apiResponse$content + } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { + apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { apiResponse } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { @@ -530,6 +540,8 @@ UserApi <- R6::R6Class( resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { apiResponse$content + } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { + apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { apiResponse } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { @@ -584,6 +596,8 @@ UserApi <- R6::R6Class( resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { apiResponse$content + } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { + apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { apiResponse } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { @@ -620,6 +634,8 @@ UserApi <- R6::R6Class( resp <- apiResponse$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { apiResponse$content + } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { + apiResponse } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { apiResponse } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {