Skip to content

Commit 5ba35ec

Browse files
authored
[R] url-encode path parameters (#2397)
* url encode path parameter * convert number to string before encoding
1 parent 065bbc7 commit 5ba35ec

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

modules/openapi-generator/src/main/resources/r/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
{{#hasPathParams}}
7979
{{#pathParams}}
8080
if (!missing(`{{paramName}}`)) {
81-
urlPath <- gsub(paste0("\\{", "{{baseName}}", "\\}"), `{{paramName}}`, urlPath)
81+
urlPath <- gsub(paste0("\\{", "{{baseName}}", "\\}"), URLencode(as.character(`{{paramName}}`), reserved = TRUE), urlPath)
8282
}
8383

8484
{{/pathParams}}

samples/client/petstore/R/R/pet_api.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ PetApi <- R6::R6Class(
104104

105105
urlPath <- "/pet/{petId}"
106106
if (!missing(`pet.id`)) {
107-
urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet.id`, urlPath)
107+
urlPath <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet.id`), reserved = TRUE), urlPath)
108108
}
109109

110110
# OAuth token
@@ -199,7 +199,7 @@ PetApi <- R6::R6Class(
199199

200200
urlPath <- "/pet/{petId}"
201201
if (!missing(`pet.id`)) {
202-
urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet.id`, urlPath)
202+
urlPath <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet.id`), reserved = TRUE), urlPath)
203203
}
204204

205205
# API key authentication
@@ -274,7 +274,7 @@ PetApi <- R6::R6Class(
274274

275275
urlPath <- "/pet/{petId}"
276276
if (!missing(`pet.id`)) {
277-
urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet.id`, urlPath)
277+
urlPath <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet.id`), reserved = TRUE), urlPath)
278278
}
279279

280280
# OAuth token
@@ -312,7 +312,7 @@ PetApi <- R6::R6Class(
312312

313313
urlPath <- "/pet/{petId}/uploadImage"
314314
if (!missing(`pet.id`)) {
315-
urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet.id`, urlPath)
315+
urlPath <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet.id`), reserved = TRUE), urlPath)
316316
}
317317

318318
# OAuth token

samples/client/petstore/R/R/store_api.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ StoreApi <- R6::R6Class(
5555

5656
urlPath <- "/store/order/{orderId}"
5757
if (!missing(`order.id`)) {
58-
urlPath <- gsub(paste0("\\{", "orderId", "\\}"), `order.id`, urlPath)
58+
urlPath <- gsub(paste0("\\{", "orderId", "\\}"), URLencode(as.character(`order.id`), reserved = TRUE), urlPath)
5959
}
6060

6161

@@ -113,7 +113,7 @@ StoreApi <- R6::R6Class(
113113

114114
urlPath <- "/store/order/{orderId}"
115115
if (!missing(`order.id`)) {
116-
urlPath <- gsub(paste0("\\{", "orderId", "\\}"), `order.id`, urlPath)
116+
urlPath <- gsub(paste0("\\{", "orderId", "\\}"), URLencode(as.character(`order.id`), reserved = TRUE), urlPath)
117117
}
118118

119119

samples/client/petstore/R/R/user_api.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ UserApi <- R6::R6Class(
166166

167167
urlPath <- "/user/{username}"
168168
if (!missing(`username`)) {
169-
urlPath <- gsub(paste0("\\{", "username", "\\}"), `username`, urlPath)
169+
urlPath <- gsub(paste0("\\{", "username", "\\}"), URLencode(as.character(`username`), reserved = TRUE), urlPath)
170170
}
171171

172172

@@ -197,7 +197,7 @@ UserApi <- R6::R6Class(
197197

198198
urlPath <- "/user/{username}"
199199
if (!missing(`username`)) {
200-
urlPath <- gsub(paste0("\\{", "username", "\\}"), `username`, urlPath)
200+
urlPath <- gsub(paste0("\\{", "username", "\\}"), URLencode(as.character(`username`), reserved = TRUE), urlPath)
201201
}
202202

203203

@@ -296,7 +296,7 @@ UserApi <- R6::R6Class(
296296

297297
urlPath <- "/user/{username}"
298298
if (!missing(`username`)) {
299-
urlPath <- gsub(paste0("\\{", "username", "\\}"), `username`, urlPath)
299+
urlPath <- gsub(paste0("\\{", "username", "\\}"), URLencode(as.character(`username`), reserved = TRUE), urlPath)
300300
}
301301

302302

0 commit comments

Comments
 (0)