https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-help-pages-using-swagger?view=aspnetcore-2.2

When consuming a Web API, understanding its various methods can be challenging for a developer. Swagger, also known as OpenAPI, solves the problem of generating useful documentation and help pages for Web APIs. It provides benefits such as interactive documentation, client SDK generation, and API discoverability.

In this article, the Swashbuckle.AspNetCore and NSwag .NET Swagger implementations are showcased:

  • Swashbuckle.AspNetCore is an open source project for generating Swagger documents for ASP.NET Core Web APIs.

  • NSwag is another open source project for generating Swagger documents and integrating Swagger UI or ReDoc into ASP.NET Core web APIs. Additionally, NSwag offers approaches to generate C# and TypeScript client code for your API.

What is Swagger / OpenAPI?

Swagger is a language-agnostic specification for describing REST APIs.

The Swagger project was donated to the OpenAPI Initiative, where it's now referred to as OpenAPI.

Both names are used interchangeably; however, OpenAPI is preferred.

It allows both computers and humans to understand the capabilities of a service without any direct access to the implementation (source code, network access, documentation).

One goal is to minimize the amount of work needed to connect disassociated services.

Another goal is to reduce the amount of time needed to accurately document a service.

Swagger specification (swagger.json)

The core to the Swagger flow is the Swagger specification—by default, a document named swagger.json.

It's generated by the Swagger tool chain (or third-party implementations of it) based on your service.

It describes the capabilities of your API and how to access it with HTTP.

It drives the Swagger UI and is used by the tool chain to enable discovery and client code generation.

Here's an example of a Swagger specification, reduced for brevity:

Swagger UI

Swagger UI offers a web-based UI that provides information about the service, using the generated Swagger specification.

Both Swashbuckle and NSwag include an embedded version of Swagger UI, so that it can be hosted in your ASP.NET Core app using a middleware registration call.

The web UI looks like this:

Each public action method in your controllers can be tested from the UI.

Click a method name to expand the section.

Add any necessary parameters, and click Try it out!.

The Swagger UI version used for the screenshots is version 2. For a version 3 example, see Petstore example.

web API help pages with Swagger / OpenAPI的更多相关文章

  1. ASP.NET Web API Help Pages using Swagger

    Understanding the various methods of an API can be a challenge for a developer when building a consu ...

  2. 利用Swashbuckle生成Web API Help Pages

    利用Swashbuckle生成Web API Help Pages 这系列文章是参考了.NET Core文档和源码,可能有人要问,直接看官方的英文文档不就可以了吗,为什么还要写这些文章呢? 原因如下: ...

  3. 利用Swashbuckle生成Web API Help Pages

    利用Swashbuckle生成Web API Help Pages 本文将通过Swagger的.NET Core的实现封装工具Swashbuckle来生成上一篇-<创建ASP.NET Core ...

  4. 使用ASP.NET Web API Help Pages 创建在线接口文档

    操作步骤 1.新建Web API项目 2.在项目Areas文件夹下找到以下文件,取消注释图中代码. 3.右键解决方案,属性,如图设置. 4.运行程序,点击右上角API 接口列表: 详情-无参数: 详情 ...

  5. Web Api 接口测试工具:Swagger

    前言:WebApi接口开发完毕后,交付给前端人员或手机端开发者时接口说明文档是必不可少的配套设备,如果公司流程不规范大家使用口口相传的交接方式,而且没有改进的欲望,那你可以到此为止了.Swagger是 ...

  6. 在.net core web api项目中安装swagger展示api接口(相当于生成api文档)

    1,  建立或打开项目后,在“程序包管理器控制台”中执行以下命令添加包引用: Install-Package Swashbuckle.AspNetCore 2,在项目中打开Startup.cs文件,找 ...

  7. ASP.NET Core 中文文档 第二章 指南 (09) 使用 Swagger 生成 ASP.NET Web API 在线帮助测试文档

    原文:ASP.NET Web API Help Pages using Swagger 作者:Shayne Boyer 翻译:谢炀(kiler) 翻译:许登洋(Seay) 对于开发人员来说,构建一个消 ...

  8. Swagger 生成 ASP.NET Web API

    使用 Swagger 生成 ASP.NET Web API 在线帮助测试文档 原文:ASP.NET Web API Help Pages using Swagger作者:Shayne Boyer翻译: ...

  9. Web API design

    Web API design 28 minutes to read Most modern web applications expose APIs that clients can use to i ...

随机推荐

  1. Activity公用跳转到主Activity

    public class VSession { private VSession() { } public static VSession getInstance() { if (session == ...

  2. 第一只python爬虫

    import urllib.request response = urllib.request.urlopen("http://www.baidu.com") html = res ...

  3. AngularJS 讲解,三 过滤器

    过滤器用来格式化需要展示给用户的数据.AngularJS有很多实用的内置过滤器,同时也提供了方便的途径可以自己创建过滤器. 在HTML中的模板绑定符号{{ }}内通过|符号来调用过滤器.例如:{{va ...

  4. SetForegroundWindow以及 如何将一个某个窗口提到最顶层(转)

    http://hi.baidu.com/gookings/item/2b7912ca8d5b3625a0b50aa2 SetForegroundWindow 函数功能:该函数将创建指定窗口的线程设置到 ...

  5. Android搜索控件的基本使用方法

    在Android中,搜索是一个非常核心的功能,我们可以通过它搜索到任意我们可以获得的信息.这些信息可以是存储在手机中的联系人.文件等信息,也可以是在网络上的资源. Android为了给用户提供良好的搜 ...

  6. 只有ReflectionOnlyLoadFrom才可以拯救与GAC冲突的强命名程序集

    先说结论,如果有两个拥有相同程序集名称的强命名程序集,一个在GAC里,一个不在.怎样动态加载那个不在GAC里的程序集?答案就是只有Assembly.ReflectionOnlyLoadFrom才可以加 ...

  7. 史上最易懂的大数据 OTO

    史上最易懂的大数据 OTO http://network.51cto.com/art/201503/467068.htm 终于有人把O2O.C2C.B2B.B2C的区别讲透了 http://tech. ...

  8. visual studio 下 C++生成dump文件

    1 lib配置 项目-->属性-->配置属性-->链接器-->输入-->附加依赖项 增加dbghelp.lib 2 头文件 #include <imagehlp.h ...

  9. Apache配置HTTPS的过程小记

    一.HTTPS的summery,综述,它的基本原理,扫肓. http://www.codeceo.com/article/https-knowledge.html 读过后,就明白https怎么加密的, ...

  10. Date、Calendar、Timestamp的区别与转换

    1.Java.util.Date 包含年.月.日.时.分.秒信息. // String转换为Date String dateStr="2013-8-13 23:23:23"; St ...