自动为ASP.NET Core控制器生成TypeScript客户端代码 [英] Automatically generate TypeScript client code for ASP.NET Core controllers

查看:275
本文介绍了自动为ASP.NET Core控制器生成TypeScript客户端代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种从ASP.NET Core Web应用程序(当前使用Visual Studio 2017RC和webpack)自动生成TypesScript客户端代码的方法.

I'm searching for a way to automatically generate the TypesScript client code from a ASP.NET Core Web-Application (Currently using Visual Studio 2017RC and webpack).

在从Visual Studio或Webpack的构建管道中,是否存在任何用于生成TypeScript客户端的工具?我尝试使用swagger中间件,然后从swagger URL生成到客户端,但是我不确定中间的swagger生成是否适合该工作.同样,与构建工具断开连接也不是很理想.

Are there any existing tools to generate the TypeScript client either in the build pipeline from visual studio or with webpack? I tried to use swagger middleware and then generate to client from the swagger URL, but I'm not sure if the intermediate swagger generation is the right tool for the job. Also the disconnectedness from the build tools is not ideal.

推荐答案

  1. NSwag

  2. 打字机是另一个很棒的选择.

  1. Typewriter is another awesome option.

所以,这就是我做出决定的方式:

So, here is how I would take the decision:

  • 需要根据C#模型生成TypeScript模型,请使用TypeWriter
  • 需要使用命令行生成完整的客户端代码,您可以将其作为构建或发布步骤添加到Swagger Code Gen

  • Need to generate TypeScript Models as per the C# models, go for TypeWriter
  • Need to generate complete client side code with command line that you can add as a build or publish step go for Swagger Code Gen

需要使用生成的Swagger Spec或生成的代码来添加您的自定义-选择NSwag

Need to play with the generated Swagger Spec or Generated Code to add your customizations - go for NSwag

这篇关于自动为ASP.NET Core控制器生成TypeScript客户端代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆