Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Swagger as Interface document in Web API Program

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to use Swagger in the Web API program to do interface documentation, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to know about it.

Create a Web API program

Create an ASP.NET Web application in VS2019, select Web API to create RESTful's HTTP service project, and construct MVC and Web API core references.

Install Swashbuckle

Using the NuGet package manager, look for the installation of Swashbuckle, the Swagger plug-in.

Configure SwaggerConfig

Find SwaggerConfig in APP_START, and there is a comment on c.IncludeXmlComments around line 105. add the configuration here:

C.IncludeXmlComments (GetXmlCommentsPath (thisAssembly.GetName () .Name))

At the end of the SwaggerConfig, add methods to the class:

Protected static string GetXmlCommentsPath (string name) {return string.Format (@ "{0}\ bin\ {1} .xml", System.AppDomain.CurrentDomain.BaseDirectory, name);} maintains the Summary of interface methods

Maintain the summary comments of each controller interface method in the controller path.

Generate the XML document file for the project

In the build settings of the API project, select generate XML document files.

Compile and run the program

Compile and run the program, add swagger after the open Web address, you can see the automatically generated interface documents and summary information, you can test the interface.

Thank you for reading this article carefully. I hope the article "how to use Swagger to do Interface document in Web API Program" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report