Swagger is a RESTful API document generation tool, when the swagger is added, the Publish API automatically generates swagger pages, records the corresponding interface information, and can test the interface directly on the page.
This article records how the. NET Core WEBAPI Project introduces swagger
1. Create the ASP. Output Type Select Console Application (default)
2. Introducing the swagger package via NuGet, in the Package Manager console input: Install-package swashbuckle.aspnetcore installation.
3. Right-click on the project selection properties to enter the Settings page, select the Build page, the output item to "XML document File" check, save
4. Add comments to each of the Valuescontroller interface methods
5. Open Startup.cs, add swagger Configuration code
Add the following code in the Configureservices method
Services. Addswaggergen (c =
{
C.swaggerdoc ("v1", new Swashbuckle.AspNetCore.Swagger.Info
{
Title = "Swagger XML API Demo",
Version = "V1",
});
var xmlpath=system.io.path.combine (appcontext.basedirectory, "swagdemo.xml");
C.includexmlcomments (Xmlpath);
});
Add the code in the Configure method
App. Useswagger ();
App. Useswaggerui (c =
{
C.swaggerendpoint ("/swagger/v1/swagger.json", "Swagger CML API Demo v1");
});
Run the project, go to page Http://localhost:55680/swagger (can go to Launchsettings.json file adjustment port and start page), see the specific effect
In addition, you can choose a specific method to debug
By adding swagger, you can see the API documentation and debug it intuitively.
. NET Core Learning Journal II: adding Swagger support