Generate Robust C# Code

オープン
#104 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
csharp, typescript
領域
devtools, tooling

調査の方向性

C# のスニペット生成のエントリーポイントから始め、現在の form-urlencoded 出力を issue の 2 つの例と比較し、パラメーター名と値がどのように表現されているかに注目します。生成された C# が、エンコード済みのリクエストボディ文字列を 1 つ埋め込むのではなく、実行時に安全な URL エンコードを用いたリクエストパラメーターを使用すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Improvement Suggestion:

I would have liked the following autogenerated C# for a HTTP POST request with the single parameter err of value + & serialized as x-www-form-urlencoded in the body.

var client = new RestClient("https://localhost");
var request = new RestRequest(Method.POST);
request.AddHeader("postman-token", "da4d0044-61a9-3943-40db-9e753aca6020");
request.AddHeader("cache-control", "no-cache");
Action<string,string> parameter = (name, value) => request.AddParameter(name, value);
parameter("err", "+ &");
IRestResponse response = client.Execute(request);

but what Postman did produce for me was the following C# code:

var client = new RestClient("https://localhost");
var request = new RestRequest(Method.POST);
request.AddHeader("postman-token", "da4d0044-61a9-3943-40db-9e753aca6020");
request.AddHeader("cache-control", "no-cache");
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter("application/x-www-form-urlencoded", "err=%2B%20%26", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

Rationale

  1. parameter("err", "+ &"); is more readable than "[..] err=%2B%20%26 [..]". The value, + &, is more recognizable.
  2. The code is more maintanable. At work, I tried the following development workflow:
    (a) Type a minimal working example request into to Postman.
    (b) Generate C# code.
    (c) Copy generated code to Visual Studio.
    (d) Replace example values by C# method parameters.
    This workflow failed, because the method parameters were not x-www-form-urlencoded at runtime. Generating UrlEncode() calls would make writing a consumer of a HTTP POST x-www-form-urlencoded API effortless.
  3. This usage of IRestRequest.AddParameter is encouraged, whereas the currently generated code depends on an internal hack not meant for 3rd party usage.
    /// - RequestBody: Used by AddBody() (not recommended to use directly)

App Details:

Postman for Windows
Version 5.3.2
win32 6.1.7601 / x64

Continuation of: https://github.com/postmanlabs/postman-app-support/issues/3870

主要言語
TypeScript
スター
1.2k
フォーク
242
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Kong/httpsnippet のほかの issue

Kong/httpsnippet の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。