RicoSuter/NSwag

Dynamic support broken

Open

#1,341 创建于 2018年5月23日

在 GitHub 查看
 (6 评论) (0 反应) (0 负责人)C# (6,291 star) (1,189 fork)batch import
help wantedtype: enhancement

描述

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.

贡献者指南