From c90576089800096551d5ea82fd2e063babac021b Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 28 Jul 2022 16:31:12 +0800 Subject: [PATCH] fix query, header params (#13034) --- .../src/main/resources/r/api.mustache | 8 +++---- samples/client/petstore/R/R/fake_api.R | 4 ++++ samples/client/petstore/R/R/pet_api.R | 6 +++++ samples/client/petstore/R/R/user_api.R | 4 ++++ samples/client/petstore/R/test_petstore.R | 24 +++++++++++-------- .../petstore/R/tests/testthat/test_petstore.R | 7 +++++- 6 files changed, 38 insertions(+), 15 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index 9f187780fdb3..48c8aea4b7fe 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -251,14 +251,14 @@ } {{/requiredParams}} - {{#header_params}} + {{#headerParams}} header_params["{{baseName}}"] <- `{{paramName}}` - {{/header_params}} - {{#query_params}} + {{/headerParams}} + {{#queryParams}} query_params["{{baseName}}"] <- {{paramName}} - {{/query_params}} + {{/queryParams}} {{#hasFormParams}} local_var_body <- list( {{#formParams}} diff --git a/samples/client/petstore/R/R/fake_api.R b/samples/client/petstore/R/R/fake_api.R index 1ec35a7d6b87..ac5d3955bc18 100644 --- a/samples/client/petstore/R/R/fake_api.R +++ b/samples/client/petstore/R/R/fake_api.R @@ -134,6 +134,10 @@ FakeApi <- R6::R6Class( reason = "Missing required parameter `dummy`.")) } + header_params["dummy"] <- `dummy` + + header_params["data_file"] <- `var_data_file` + local_var_body <- NULL local_var_url_path <- "/fake/data_file" diff --git a/samples/client/petstore/R/R/pet_api.R b/samples/client/petstore/R/R/pet_api.R index 1aa88939fd13..a26ff9ad251a 100644 --- a/samples/client/petstore/R/R/pet_api.R +++ b/samples/client/petstore/R/R/pet_api.R @@ -689,6 +689,8 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `pet_id`.")) } + header_params["api_key"] <- `api_key` + local_var_body <- NULL local_var_url_path <- "/pet/{petId}?streaming" if (!missing(`pet_id`)) { @@ -786,6 +788,8 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `status`.")) } + query_params["status"] <- status + local_var_body <- NULL local_var_url_path <- "/pet/findByStatus" # OAuth token @@ -892,6 +896,8 @@ PetApi <- R6::R6Class( reason = "Missing required parameter `tags`.")) } + query_params["tags"] <- tags + local_var_body <- NULL local_var_url_path <- "/pet/findByTags" # OAuth token diff --git a/samples/client/petstore/R/R/user_api.R b/samples/client/petstore/R/R/user_api.R index 958faf50b9c0..81bc3c10db92 100644 --- a/samples/client/petstore/R/R/user_api.R +++ b/samples/client/petstore/R/R/user_api.R @@ -984,6 +984,10 @@ UserApi <- R6::R6Class( reason = "Missing required parameter `password`.")) } + query_params["username"] <- username + + query_params["password"] <- password + local_var_body <- NULL local_var_url_path <- "/user/login" diff --git a/samples/client/petstore/R/test_petstore.R b/samples/client/petstore/R/test_petstore.R index ed6479680ee5..f5c7843bc4fc 100644 --- a/samples/client/petstore/R/test_petstore.R +++ b/samples/client/petstore/R/test_petstore.R @@ -8,6 +8,8 @@ var_pet <- Pet$new("name_example", list("photoUrls_example"), 56, Category$new(5 api_instance <- PetApi$new() # Configure OAuth2 access token for authorization: petstore_auth api_instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN'; +api_instance$api_client$username <- 'username'; +api_instance$api_client$password <- 'password'; result <- tryCatch( # to save the result into a file, simply add the optional `data_file` parameter, e.g. # api_instance$AddPet(var_pet, data_file = "result.txt"), @@ -17,16 +19,18 @@ result <- tryCatch( var_pet_id <- 56 # integer | ID of pet to return -#Find pet by ID (streaming) -api_instance <- PetApi$new() -# Configure API key authorization: api_key -api_instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY'; -result <- tryCatch( - # to save the result into a file, simply add the optional `data_file` parameter, e.g. - # api_instance$GetPetByIdStreaming(var_pet_id, data_file = "result.txt"), - api_instance$GetPetByIdStreaming(var_pet_id, stream_callback = function(x) { print(x) }), - ApiException = function(ex) ex - ) +result <- api_instance$FindPetsByStatus("available") +dput(result) +##Find pet by ID (streaming) +#api_instance <- PetApi$new() +## Configure API key authorization: api_key +#api_instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY'; +#result <- tryCatch( +# # to save the result into a file, simply add the optional `data_file` parameter, e.g. +# # api_instance$GetPetByIdStreaming(var_pet_id, data_file = "result.txt"), +# api_instance$GetPetByIdStreaming(var_pet_id, stream_callback = function(x) { print(x) }), +# ApiException = function(ex) ex +# ) # In case of error, print the error object #if (!is.null(result$ApiException)) { # cat(result$ApiException$toString()) diff --git a/samples/client/petstore/R/tests/testthat/test_petstore.R b/samples/client/petstore/R/tests/testthat/test_petstore.R index a9af6a95c561..e9d6090e393c 100644 --- a/samples/client/petstore/R/tests/testthat/test_petstore.R +++ b/samples/client/petstore/R/tests/testthat/test_petstore.R @@ -15,11 +15,16 @@ pet_api$api_client$username <- "username123" pet_api$api_client$password <- "password123" result <- pet_api$AddPet(pet) -test_that("AddPet", { +test_that("Test toJSONString", { expect_equal(pet_id, 123321) expect_equal(pet$toJSONString(), '{"id":123321,"category":{"id":450,"name":"test_cat"},"name":"name_test","photoUrls":["photo_test","second test"],"tags":[{"id":123,"name":"tag_test"},{"id":456,"name":"unknown"}],"status":"available"}') }) +test_that("Test FindPetByStatus", { + result <- pet_api$FindPetsByStatus("available") + expect_equal(result[[1]]$status, "available") +}) + test_that("Test toJSON toJSONString fromJSON fromJSONString", { pet0 <- Pet$new() jsonpet <- pet0$toJSON()