RicoSuter/NSwag

Dynamic support broken

オープン

#1,341 opened on 2018/05/23

 (6 件のコメント) (0 件のリアクション) (0 人の担当者)C# (1,356 件のフォーク)batch import
help wantedtype: enhancement

Repository metrics

Stars
 (7,358 個のスター)
PR merge metrics
 (PR metrics pending)

説明

Related to https://github.com/RSuter/NSwag/issues/1216. The fix that removed ExpandoObject and used any instead worked for most of our cases, but surfaced another bug.

When generating TypeScript for a Web API method that accepts a dynamic, ExpandoObject, or object` parameter, the wrong code is generated.

It is generating this:

foo(bar: any | null): Observable<void> {
        let url_ = this.baseUrl + "/api/Baz/Foo?";
        if (bar === undefined)
            throw new Error("The parameter 'bar' must be defined.");
        else
            url_ += "bar=" + encodeURIComponent("" + bar) + "&"; 
...
}

Instead of this:

foo(bar: any | null): Observable<void> {
        let url_ = this.baseUrl + "/api/Baz/Foo";
        url_ = url_.replace(/[?&]$/, "");
 
        const content_ = JSON.stringify(bar);
...

In other words, its treating dynamic, ExpandoObject, or object parameters the same as it treats primitives. It instead should be calling JSON.stringify on them.

コントリビューターガイド