https://blog.rsuter.com/nswag-tutorial-integrate-the-nswag-toolchain-into-your-asp-net-web-api-project/

This tutorial shows how to integrate NSwag (Swagger toolchain for .NET) so that you can access your Web API actions with the Swagger UI and a generated C# client library.

The toolchain can be integrated into the following three types of Web API projects:

  • Global.asax-based Web projects (full .NET Framework)
  • OWIN-based Web projects (full .NET Framework)
  • ASP.NET Core based projects (full .NET Framework or .NET Core)

For each project, the integration is a little bit different, but this tutorial will provide links to all supported ways. Just follow the steps.

1. Create and setup a new Web API project

First we implement your Web API project:

  1. Open Visual Studio and create a new Web API project (either Global.asax-, OWIN- or ASP.NET Core-based).
  2. Register the NSwag Swagger middlewares:
  3. (optional) Globally register the Web API exception serialization filter

2. Run the Web API project

Run the project and navigate to the URL http://yourserver/swagger: Here you should see the Swagger UI.

Try calling your Web API actions and check the results.

3. Generate client code to access the Web API

The next steps show how to generate a client library to access the Web API actions in the Web project. In this tutorial we use the C# client generator (there is also a TypeScript client generator).

Setup tooling and create client project:

  1. Install NSwagStudio.
  2. Create a new C# library project in your solution (the service client library).
  3. Add the required assembly dependencies to the library project.

Generate code:

  1. Start NSwagStudio and select “Swagger Specification” as input.
  2. Enter the Swagger specification URL (default: http://yourserver/swagger/v1/swagger.json, the server must be running).
  3. Click “Generate Outputs” and select the tab “CSharpClient”.
  4. Copy the source code into your client project.
  5. Now you should change generator settings in the NSwagStudio to improve and customize the generated code (e.g. define the correct namespace, etc.).

Automate script generation:

  1. Save the .nswag file in NSwagStudio
  2. Open a command prompt and cd to the directory with the .nswag file
  3. Run nswag run to execute all .nswag files (the NSwag command line tool is automatically registered by the MSI installer)

NSwag Tutorial: Integrate the NSwag toolchain into your ASP.NET Web API project的更多相关文章

  1. NSwag在asp.net web api中的使用,基于Global.asax

    https://github.com/NSwag/NSwag/wiki/OwinGlobalAsax This page explains how to use the NSwag OWIN midd ...

  2. nswag vs swashbuckle

    https://www.reddit.com/r/dotnet/comments/a2181x/swashbuckle_vs_nswag/ Swashbuckle https://github.com ...

  3. Getting Started with ASP.NET Web API 2 (C#)

    By Mike Wasson|last updated May 28, 2015 7556 of 8454 people found this helpful Print   Download Com ...

  4. webAPI---发布(IIS)--发布遇到问题(500.19,500.21,404.8,404.3)

    WebAPI的内容部分直接转自官方文档,英语水平有限,不做翻译, 发布网站在本文的后半部分 HTTP is not just for serving up web pages. It is also ...

  5. Unity文档阅读 第三章 依赖注入与Unity

    Introduction 简介In previous chapters, you saw some of the reasons to use dependency injection and lea ...

  6. [转]Getting Started with ASP.NET Web API 2 (C#)

    http://www.asp.net/web-api 本文转自:http://www.asp.net/web-api/overview/getting-started-with-aspnet-web- ...

  7. NSwag给api加上说明

    参考http://petstore.swagger.io 给controller加上description https://github.com/RSuter/NSwag/issues/1803 xm ...

  8. Microsoft Azure Tutorial: Build your first movie inventory web app with just a few lines of code

    Editor’s Note: The following is a guest post from Mustafa Mahmutović, a Microsoft Student Partner wh ...

  9. Tutorial 1: Serialization

    转载自:http://www.django-rest-framework.org/tutorial/1-serialization/#tutorial-1-serialization Tutorial ...

随机推荐

  1. boost::interprocess::managed_shared_memory(2)(std::deque)

    struct shareDataEx : shareData { int index; int total_size; }; typedef managed_shared_memory::segmen ...

  2. linux时间格式化

    echo `date +'[%Y-%m-%d %H:%M:%S]'`

  3. 02、微信小程序的数据绑定

    02.微信小程序的数据绑定 目录结构: 模板内容: 使用bindtap绑定事件 <!--index.wxml--> <view class="container" ...

  4. 支付宝SDK的使用方法

    前奏 现在随着移动开发的快速发展,越来越多的应用要求在线支付功能.最近做了一个关于支付宝支付功能的应用,在使用支付宝的过程中,遇到一些不必要的弯路,因此,写了这篇文章总结一下关于ios开发如何使用支付 ...

  5. 【推荐】CentOS安装vsftpd-3.0.3+安全配置

    注:以下所有操作均在CentOS 6.5 x86_64位系统下完成. FTP的登录一般有三种方式,分别是: 匿名用户形式:默认安装的情况下,系统只提供匿名用户访问,只需要输入用户anonymous/f ...

  6. Storm-源码分析- spout (backtype.storm.spout)

    1. ISpout接口 ISpout作为实现spout的核心interface, spout负责feeding message, 并且track这些message. 如果需要Spout track发出 ...

  7. Java基础 - 字符串 String

    字符串就是用字符拼接成的文本值,字符串在存储上类似数组,在java语言中把字符串当做对象进行处理 创建字符串 package com.mingri.chapter_02; public class d ...

  8. MyBatis 映射文件详解

    1. MyBatis 映射文件之<select>标签 <select>用来定义查询操作; "id": 唯一标识符,需要和接口中的方法名一致; paramet ...

  9. RT-Thread内核之线程调度(三)

    4.RT-Thread中的线程? /**  * 线程结构  */ struct rt_thread {     /** Object对象 */     char        name[RT_NAME ...

  10. 什么是EJB

    学习EJB可以加深对J2EE平台的认识. 百科定义EJB: 被称为java企业bean,服务器端组件,核心应用是部署分布式应用程序.用它部署的系统不限定平台.实际上ejb是一种产品,描述了应用组件要解 ...