From 7085ab5a5ff1f980502741b61c4f7013cf743de8 Mon Sep 17 00:00:00 2001 From: Michael Welch Date: Sun, 15 Sep 2024 13:06:14 -0500 Subject: [PATCH] correct the casing of Method enums in RestSharp snippets Ensure that code snippets use enum members that are pascal cased and not upper cased. For example use `Method.Get` instead of `Method.GET` to ensure the snippets can compile. fixes #365 --- src/targets/csharp/restsharp/client.ts | 9 ++++++++- .../restsharp/fixtures/application-form-encoded.cs | 2 +- .../csharp/restsharp/fixtures/application-json.cs | 2 +- src/targets/csharp/restsharp/fixtures/cookies.cs | 2 +- src/targets/csharp/restsharp/fixtures/full.cs | 2 +- src/targets/csharp/restsharp/fixtures/headers.cs | 2 +- src/targets/csharp/restsharp/fixtures/https.cs | 2 +- .../csharp/restsharp/fixtures/jsonObj-multiline.cs | 2 +- .../csharp/restsharp/fixtures/jsonObj-null-value.cs | 2 +- src/targets/csharp/restsharp/fixtures/multipart-data.cs | 2 +- src/targets/csharp/restsharp/fixtures/multipart-file.cs | 2 +- .../restsharp/fixtures/multipart-form-data-no-params.cs | 2 +- .../csharp/restsharp/fixtures/multipart-form-data.cs | 2 +- src/targets/csharp/restsharp/fixtures/nested.cs | 2 +- src/targets/csharp/restsharp/fixtures/query.cs | 2 +- src/targets/csharp/restsharp/fixtures/short.cs | 2 +- src/targets/csharp/restsharp/fixtures/text-plain.cs | 2 +- 17 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/targets/csharp/restsharp/client.ts b/src/targets/csharp/restsharp/client.ts index 15f2a6e83..8ee8b77a6 100644 --- a/src/targets/csharp/restsharp/client.ts +++ b/src/targets/csharp/restsharp/client.ts @@ -20,8 +20,15 @@ export const restsharp: Client = { return 'Method not supported'; } + function toPascalCase(str: string): string { + return str.replace( + /\w+/g, + word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(), + ); + } + push(`var client = new RestClient("${fullUrl}");`); - push(`var request = new RestRequest(Method.${method.toUpperCase()});`); + push(`var request = new RestRequest(Method.${toPascalCase(method)});`); // Add headers, including the cookies diff --git a/src/targets/csharp/restsharp/fixtures/application-form-encoded.cs b/src/targets/csharp/restsharp/fixtures/application-form-encoded.cs index 4e4744d01..78fc435e5 100644 --- a/src/targets/csharp/restsharp/fixtures/application-form-encoded.cs +++ b/src/targets/csharp/restsharp/fixtures/application-form-encoded.cs @@ -1,5 +1,5 @@ var client = new RestClient("http://mockbin.com/har"); -var request = new RestRequest(Method.POST); +var request = new RestRequest(Method.Post); request.AddHeader("content-type", "application/x-www-form-urlencoded"); request.AddParameter("application/x-www-form-urlencoded", "foo=bar&hello=world", ParameterType.RequestBody); IRestResponse response = client.Execute(request); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/application-json.cs b/src/targets/csharp/restsharp/fixtures/application-json.cs index 2ee8c46f1..8861f11cf 100644 --- a/src/targets/csharp/restsharp/fixtures/application-json.cs +++ b/src/targets/csharp/restsharp/fixtures/application-json.cs @@ -1,5 +1,5 @@ var client = new RestClient("http://mockbin.com/har"); -var request = new RestRequest(Method.POST); +var request = new RestRequest(Method.Post); request.AddHeader("content-type", "application/json"); request.AddParameter("application/json", "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}],\"boolean\":false}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/cookies.cs b/src/targets/csharp/restsharp/fixtures/cookies.cs index f0489b650..dd39375cb 100644 --- a/src/targets/csharp/restsharp/fixtures/cookies.cs +++ b/src/targets/csharp/restsharp/fixtures/cookies.cs @@ -1,5 +1,5 @@ var client = new RestClient("http://mockbin.com/har"); -var request = new RestRequest(Method.POST); +var request = new RestRequest(Method.Post); request.AddCookie("foo", "bar"); request.AddCookie("bar", "baz"); IRestResponse response = client.Execute(request); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/full.cs b/src/targets/csharp/restsharp/fixtures/full.cs index 14b52d976..019f3a7ff 100644 --- a/src/targets/csharp/restsharp/fixtures/full.cs +++ b/src/targets/csharp/restsharp/fixtures/full.cs @@ -1,5 +1,5 @@ var client = new RestClient("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value"); -var request = new RestRequest(Method.POST); +var request = new RestRequest(Method.Post); request.AddHeader("accept", "application/json"); request.AddHeader("content-type", "application/x-www-form-urlencoded"); request.AddCookie("foo", "bar"); diff --git a/src/targets/csharp/restsharp/fixtures/headers.cs b/src/targets/csharp/restsharp/fixtures/headers.cs index 9a02c6db5..0da9625bd 100644 --- a/src/targets/csharp/restsharp/fixtures/headers.cs +++ b/src/targets/csharp/restsharp/fixtures/headers.cs @@ -1,5 +1,5 @@ var client = new RestClient("http://mockbin.com/har"); -var request = new RestRequest(Method.GET); +var request = new RestRequest(Method.Get); request.AddHeader("accept", "application/json"); request.AddHeader("x-foo", "Bar"); request.AddHeader("quoted-value", "\"quoted\" 'string'"); diff --git a/src/targets/csharp/restsharp/fixtures/https.cs b/src/targets/csharp/restsharp/fixtures/https.cs index 05a369073..79b0351e4 100644 --- a/src/targets/csharp/restsharp/fixtures/https.cs +++ b/src/targets/csharp/restsharp/fixtures/https.cs @@ -1,3 +1,3 @@ var client = new RestClient("https://mockbin.com/har"); -var request = new RestRequest(Method.GET); +var request = new RestRequest(Method.Get); IRestResponse response = client.Execute(request); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs b/src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs index 14fbe7778..ac63fd6f5 100644 --- a/src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs +++ b/src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs @@ -1,5 +1,5 @@ var client = new RestClient("http://mockbin.com/har"); -var request = new RestRequest(Method.POST); +var request = new RestRequest(Method.Post); request.AddHeader("content-type", "application/json"); request.AddParameter("application/json", "{\n \"foo\": \"bar\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs b/src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs index 36b092c94..c4ac17706 100644 --- a/src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs +++ b/src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs @@ -1,5 +1,5 @@ var client = new RestClient("http://mockbin.com/har"); -var request = new RestRequest(Method.POST); +var request = new RestRequest(Method.Post); request.AddHeader("content-type", "application/json"); request.AddParameter("application/json", "{\"foo\":null}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/multipart-data.cs b/src/targets/csharp/restsharp/fixtures/multipart-data.cs index 7c95fe632..bebd0f4eb 100644 --- a/src/targets/csharp/restsharp/fixtures/multipart-data.cs +++ b/src/targets/csharp/restsharp/fixtures/multipart-data.cs @@ -1,5 +1,5 @@ var client = new RestClient("http://mockbin.com/har"); -var request = new RestRequest(Method.POST); +var request = new RestRequest(Method.Post); request.AddHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001"); request.AddParameter("multipart/form-data; boundary=---011000010111000001101001", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody); IRestResponse response = client.Execute(request); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/multipart-file.cs b/src/targets/csharp/restsharp/fixtures/multipart-file.cs index 47758542c..89cc6d024 100644 --- a/src/targets/csharp/restsharp/fixtures/multipart-file.cs +++ b/src/targets/csharp/restsharp/fixtures/multipart-file.cs @@ -1,5 +1,5 @@ var client = new RestClient("http://mockbin.com/har"); -var request = new RestRequest(Method.POST); +var request = new RestRequest(Method.Post); request.AddHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001"); request.AddParameter("multipart/form-data; boundary=---011000010111000001101001", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody); IRestResponse response = client.Execute(request); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/multipart-form-data-no-params.cs b/src/targets/csharp/restsharp/fixtures/multipart-form-data-no-params.cs index be2fcac1f..cb4d580e6 100644 --- a/src/targets/csharp/restsharp/fixtures/multipart-form-data-no-params.cs +++ b/src/targets/csharp/restsharp/fixtures/multipart-form-data-no-params.cs @@ -1,4 +1,4 @@ var client = new RestClient("http://mockbin.com/har"); -var request = new RestRequest(Method.POST); +var request = new RestRequest(Method.Post); request.AddHeader("Content-Type", "multipart/form-data"); IRestResponse response = client.Execute(request); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/multipart-form-data.cs b/src/targets/csharp/restsharp/fixtures/multipart-form-data.cs index 9eb6893b6..67bb00172 100644 --- a/src/targets/csharp/restsharp/fixtures/multipart-form-data.cs +++ b/src/targets/csharp/restsharp/fixtures/multipart-form-data.cs @@ -1,5 +1,5 @@ var client = new RestClient("http://mockbin.com/har"); -var request = new RestRequest(Method.POST); +var request = new RestRequest(Method.Post); request.AddHeader("Content-Type", "multipart/form-data; boundary=---011000010111000001101001"); request.AddParameter("multipart/form-data; boundary=---011000010111000001101001", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody); IRestResponse response = client.Execute(request); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/nested.cs b/src/targets/csharp/restsharp/fixtures/nested.cs index e28bf3190..7c75a7329 100644 --- a/src/targets/csharp/restsharp/fixtures/nested.cs +++ b/src/targets/csharp/restsharp/fixtures/nested.cs @@ -1,3 +1,3 @@ var client = new RestClient("http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value"); -var request = new RestRequest(Method.GET); +var request = new RestRequest(Method.Get); IRestResponse response = client.Execute(request); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/query.cs b/src/targets/csharp/restsharp/fixtures/query.cs index 3e3112c02..f08b37197 100644 --- a/src/targets/csharp/restsharp/fixtures/query.cs +++ b/src/targets/csharp/restsharp/fixtures/query.cs @@ -1,3 +1,3 @@ var client = new RestClient("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value"); -var request = new RestRequest(Method.GET); +var request = new RestRequest(Method.Get); IRestResponse response = client.Execute(request); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/short.cs b/src/targets/csharp/restsharp/fixtures/short.cs index b644539c4..fa5496771 100644 --- a/src/targets/csharp/restsharp/fixtures/short.cs +++ b/src/targets/csharp/restsharp/fixtures/short.cs @@ -1,3 +1,3 @@ var client = new RestClient("http://mockbin.com/har"); -var request = new RestRequest(Method.GET); +var request = new RestRequest(Method.Get); IRestResponse response = client.Execute(request); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/text-plain.cs b/src/targets/csharp/restsharp/fixtures/text-plain.cs index a0a672de6..cd74ea91e 100644 --- a/src/targets/csharp/restsharp/fixtures/text-plain.cs +++ b/src/targets/csharp/restsharp/fixtures/text-plain.cs @@ -1,5 +1,5 @@ var client = new RestClient("http://mockbin.com/har"); -var request = new RestRequest(Method.POST); +var request = new RestRequest(Method.Post); request.AddHeader("content-type", "text/plain"); request.AddParameter("text/plain", "Hello World", ParameterType.RequestBody); IRestResponse response = client.Execute(request); \ No newline at end of file