小编lam*_*ama的帖子

通过NSwag代码生成器下载文件的正确方法是什么(angular 2 typescript)

我尝试通过角度2打字稿客户端下载文件.Swagger UI中生成的链接工作正常,但生成的typescript客户端没有.

控制器看起来像这样:

    [HttpGet("export")]
    [SwaggerResponse((int) HttpStatusCode.OK, Type = typeof(FileContentResult))]
    [ProducesResponseType(typeof(FileResult), (int) HttpStatusCode.OK)]
    [Produces("text/csv")]
    public virtual FileResult Export(int Id, string fileType, CsvFormat format, bool includeHeader)
    {
        .
        .
        .
        FileStreamResult file = new FileStreamResult(s, "text/csv");
        file.FileDownloadName = ts.Name + "." + fileType;

        return file;
    }
Run Code Online (Sandbox Code Playgroud)

Swagger UI:Swagger UI下载

生成的typescript客户端看起来像这样.如您所见,设置了responseText但从未返回.我错过了什么?

protected processRestTimeSeriesExportGet(response: Response): Observable<void> {
    const status = response.status; 

    if (status === 200) {
        const responseText = response.text();
        return Observable.of<void>(<any>null);
    } else if (status !== 200 && status !== 204) {
        const responseText …
Run Code Online (Sandbox Code Playgroud)

typescript swagger-ui .net-core nswag

10
推荐指数
2
解决办法
2036
查看次数

NSwag Typescript Proxy 自定义属性注释/装饰器

我正在使用 NSwag.CodeGeneration.Typescript 从 .net-core 后端和 swagger.json 生成一个 angular 2 typescript 代理。这就像一个魅力。

现在我希望能够为我的打字稿客户端自动生成自定义装饰器。像这样的东西:

C# 类:

public class Point {
   // a configurable annotation here
   [configurable]
   private int X
   {
      get; set;
   }
   // a configurable annotation here
   [configurable]
   private int Y
   {
      get; set;
   }        
}
Run Code Online (Sandbox Code Playgroud)

生成的打字稿代理...

class Point {
private _x: number;
private _y: number;
constructor(data?: any) {
    // set data
}

@configurable(false)
get x() { return this._x; }

@configurable(false)
get y() { return this._y; }
}
Run Code Online (Sandbox Code Playgroud)

...使用自定义装饰器功能

function configurable(value: …
Run Code Online (Sandbox Code Playgroud)

c# typescript asp.net-core nswag angular

5
推荐指数
0
解决办法
596
查看次数

标签 统计

nswag ×2

typescript ×2

.net-core ×1

angular ×1

asp.net-core ×1

c# ×1

swagger-ui ×1