Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full typing with TypeScript and ASP.Net WebApi

Is there any approaches to auto-generate OpenAPI/Swagger metadata for WebApi methods or maybe even to generate client typescript models?

I found Swashbuckle and Swagger to JS & Typescript Codegen to be nice but I wonder to find out any other libs.

It would be perfect if you can give pros and cons of each approach.

like image 489
SGP Avatar asked Jun 01 '16 09:06

SGP


2 Answers

You can also check out NSwag, a Swagger toolchain for .NET and TypeScript.

The tool generates Swagger specs from existing Web API controllers and client code based on these Swagger specs. You can generate TypeScript client code for JQuery with Callbacks or Promises, AngularJS or Angular2. The generated DTOs (request/response types) can either be interfaces or classes (with date conversion, lower camel casing, etc..)

The project can be used with a simple to use desktop GUI, build scripts or a command line tool.

enter image description here

Disclaimer: I'm one of the contributors of NSwag.

like image 56
Rico Suter Avatar answered Nov 17 '22 17:11

Rico Suter


Please try Swagger-Codegen, which is a free and open-source code generator to generate REST API clients (e.g. C#, TypeScript, Javascript and more) or server stubs (ASP.NET5) given an OpenAPI/Swagger spec.

Here is a good starting point: https://github.com/swagger-api/swagger-codegen#getting-started

For typescript, Swagger Codegen supports different libraries: typescript-node, typescript-angular, typescript-angular2 and typescript-fetch

like image 2
William Cheng Avatar answered Nov 17 '22 17:11

William Cheng