From 7644f3ee834fda937809f0e40ed33760c6f5cdc2 Mon Sep 17 00:00:00 2001 From: Robert Pyke Date: Thu, 3 Dec 2020 00:21:08 -0800 Subject: [PATCH] [R] Bug - Invalid code generated for POST with no request object (#8067) * Default body to NULL * update samples * Update to set body to NULL only when no hasBodyParam * Revert any whitespace changes. * Makes defaulting body conditional on hasFormParams also not being set Co-authored-by: William Cheng Co-authored-by: Robert Pyke --- modules/openapi-generator/src/main/resources/r/api.mustache | 5 +++++ samples/client/petstore/R/R/pet_api.R | 4 ++++ samples/client/petstore/R/R/store_api.R | 3 +++ samples/client/petstore/R/R/user_api.R | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index 24f2ef793a2..2e76b2419c5 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -226,6 +226,11 @@ {{/bodyParams}} {{/hasBodyParam}} + {{^hasBodyParam}} + {{^hasFormParams}} + body <- NULL + {{/hasFormParams}} + {{/hasBodyParam}} urlPath <- "{{path}}" {{#hasPathParams}} {{#pathParams}} diff --git a/samples/client/petstore/R/R/pet_api.R b/samples/client/petstore/R/R/pet_api.R index 3940dca6bf8..1df44f5795a 100644 --- a/samples/client/petstore/R/R/pet_api.R +++ b/samples/client/petstore/R/R/pet_api.R @@ -406,6 +406,7 @@ PetApi <- R6::R6Class( headerParams['api_key'] <- `api.key` + body <- NULL urlPath <- "/pet/{petId}" if (!missing(`pet.id`)) { urlPath <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet.id`), reserved = TRUE), urlPath) @@ -456,6 +457,7 @@ PetApi <- R6::R6Class( queryParams['status'] <- status + body <- NULL urlPath <- "/pet/findByStatus" # OAuth token headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ") @@ -508,6 +510,7 @@ PetApi <- R6::R6Class( queryParams['tags'] <- tags + body <- NULL urlPath <- "/pet/findByTags" # OAuth token headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ") @@ -558,6 +561,7 @@ PetApi <- R6::R6Class( stop("Missing required parameter `pet.id`.") } + body <- NULL urlPath <- "/pet/{petId}" if (!missing(`pet.id`)) { urlPath <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet.id`), reserved = TRUE), urlPath) diff --git a/samples/client/petstore/R/R/store_api.R b/samples/client/petstore/R/R/store_api.R index 7145e5b09f4..4199d1146ba 100644 --- a/samples/client/petstore/R/R/store_api.R +++ b/samples/client/petstore/R/R/store_api.R @@ -197,6 +197,7 @@ StoreApi <- R6::R6Class( stop("Missing required parameter `order.id`.") } + body <- NULL urlPath <- "/store/order/{orderId}" if (!missing(`order.id`)) { urlPath <- gsub(paste0("\\{", "orderId", "\\}"), URLencode(as.character(`order.id`), reserved = TRUE), urlPath) @@ -239,6 +240,7 @@ StoreApi <- R6::R6Class( queryParams <- list() headerParams <- c() + body <- NULL urlPath <- "/store/inventory" # API key authentication if ("api_key" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["api_key"]) > 0) { @@ -291,6 +293,7 @@ StoreApi <- R6::R6Class( stop("Missing required parameter `order.id`.") } + body <- NULL urlPath <- "/store/order/{orderId}" if (!missing(`order.id`)) { urlPath <- gsub(paste0("\\{", "orderId", "\\}"), URLencode(as.character(`order.id`), reserved = TRUE), urlPath) diff --git a/samples/client/petstore/R/R/user_api.R b/samples/client/petstore/R/R/user_api.R index 1a6b13363aa..31a229ee2f8 100644 --- a/samples/client/petstore/R/R/user_api.R +++ b/samples/client/petstore/R/R/user_api.R @@ -460,6 +460,7 @@ UserApi <- R6::R6Class( stop("Missing required parameter `username`.") } + body <- NULL urlPath <- "/user/{username}" if (!missing(`username`)) { urlPath <- gsub(paste0("\\{", "username", "\\}"), URLencode(as.character(`username`), reserved = TRUE), urlPath) @@ -506,6 +507,7 @@ UserApi <- R6::R6Class( stop("Missing required parameter `username`.") } + body <- NULL urlPath <- "/user/{username}" if (!missing(`username`)) { urlPath <- gsub(paste0("\\{", "username", "\\}"), URLencode(as.character(`username`), reserved = TRUE), urlPath) @@ -566,6 +568,7 @@ UserApi <- R6::R6Class( queryParams['password'] <- password + body <- NULL urlPath <- "/user/login" resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), @@ -610,6 +613,7 @@ UserApi <- R6::R6Class( queryParams <- list() headerParams <- c() + body <- NULL urlPath <- "/user/logout" resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),