From 5ba35ecd31414ff7a841805ce86d77eda60a36ad Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 14 Mar 2019 20:54:10 +0800 Subject: [PATCH] [R] url-encode path parameters (#2397) * url encode path parameter * convert number to string before encoding --- .../openapi-generator/src/main/resources/r/api.mustache | 2 +- samples/client/petstore/R/R/pet_api.R | 8 ++++---- samples/client/petstore/R/R/store_api.R | 4 ++-- samples/client/petstore/R/R/user_api.R | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index 92d52e553fb..2612d6c838e 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -78,7 +78,7 @@ {{#hasPathParams}} {{#pathParams}} if (!missing(`{{paramName}}`)) { - urlPath <- gsub(paste0("\\{", "{{baseName}}", "\\}"), `{{paramName}}`, urlPath) + urlPath <- gsub(paste0("\\{", "{{baseName}}", "\\}"), URLencode(as.character(`{{paramName}}`), reserved = TRUE), urlPath) } {{/pathParams}} diff --git a/samples/client/petstore/R/R/pet_api.R b/samples/client/petstore/R/R/pet_api.R index 224ee31243a..a4ffb070fc3 100644 --- a/samples/client/petstore/R/R/pet_api.R +++ b/samples/client/petstore/R/R/pet_api.R @@ -104,7 +104,7 @@ PetApi <- R6::R6Class( urlPath <- "/pet/{petId}" if (!missing(`pet.id`)) { - urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet.id`, urlPath) + urlPath <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet.id`), reserved = TRUE), urlPath) } # OAuth token @@ -199,7 +199,7 @@ PetApi <- R6::R6Class( urlPath <- "/pet/{petId}" if (!missing(`pet.id`)) { - urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet.id`, urlPath) + urlPath <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet.id`), reserved = TRUE), urlPath) } # API key authentication @@ -274,7 +274,7 @@ PetApi <- R6::R6Class( urlPath <- "/pet/{petId}" if (!missing(`pet.id`)) { - urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet.id`, urlPath) + urlPath <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet.id`), reserved = TRUE), urlPath) } # OAuth token @@ -312,7 +312,7 @@ PetApi <- R6::R6Class( urlPath <- "/pet/{petId}/uploadImage" if (!missing(`pet.id`)) { - urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet.id`, urlPath) + urlPath <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet.id`), reserved = TRUE), urlPath) } # OAuth token diff --git a/samples/client/petstore/R/R/store_api.R b/samples/client/petstore/R/R/store_api.R index 9c6db7193a8..c2ba0834e3c 100644 --- a/samples/client/petstore/R/R/store_api.R +++ b/samples/client/petstore/R/R/store_api.R @@ -55,7 +55,7 @@ StoreApi <- R6::R6Class( urlPath <- "/store/order/{orderId}" if (!missing(`order.id`)) { - urlPath <- gsub(paste0("\\{", "orderId", "\\}"), `order.id`, urlPath) + urlPath <- gsub(paste0("\\{", "orderId", "\\}"), URLencode(as.character(`order.id`), reserved = TRUE), urlPath) } @@ -113,7 +113,7 @@ StoreApi <- R6::R6Class( urlPath <- "/store/order/{orderId}" if (!missing(`order.id`)) { - urlPath <- gsub(paste0("\\{", "orderId", "\\}"), `order.id`, urlPath) + 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 0c676509ed9..6dc59c0b44b 100644 --- a/samples/client/petstore/R/R/user_api.R +++ b/samples/client/petstore/R/R/user_api.R @@ -166,7 +166,7 @@ UserApi <- R6::R6Class( urlPath <- "/user/{username}" if (!missing(`username`)) { - urlPath <- gsub(paste0("\\{", "username", "\\}"), `username`, urlPath) + urlPath <- gsub(paste0("\\{", "username", "\\}"), URLencode(as.character(`username`), reserved = TRUE), urlPath) } @@ -197,7 +197,7 @@ UserApi <- R6::R6Class( urlPath <- "/user/{username}" if (!missing(`username`)) { - urlPath <- gsub(paste0("\\{", "username", "\\}"), `username`, urlPath) + urlPath <- gsub(paste0("\\{", "username", "\\}"), URLencode(as.character(`username`), reserved = TRUE), urlPath) } @@ -296,7 +296,7 @@ UserApi <- R6::R6Class( urlPath <- "/user/{username}" if (!missing(`username`)) { - urlPath <- gsub(paste0("\\{", "username", "\\}"), `username`, urlPath) + urlPath <- gsub(paste0("\\{", "username", "\\}"), URLencode(as.character(`username`), reserved = TRUE), urlPath) }