Configure Swagger

1. Add Nuget package (Swashbuckle.Core and Swagger.Net.UI)
-> Search Swashbuckle and Swagger keywords online
. 2. After installation, return to the project root directory to generate a SwaggerUI folder, which contains some css styles And js files, two files SwaggerConfig.cs and SwaggerNet.cs will be added under the App_Start folder. The main configuration is set here.
In SwaggerNet.cs add
//[assembly: WebActivator.PreApplicationStartMethod(typeof(TutorialSwagger.App_Start.SwaggerNet), "PreStart")]
//[assembly: WebActivator.PostApplicationStartMethod(typeof(TutorialSwagger.App_Start.SwaggerNet), "PostStart" )] If it is
blocked, an error will be reported when it runs.
Insert picture description here
3. Add the generated xml file, right click on the project -> Properties -> Generate
4. Add global configuration

c.SingleApiVersion("v1", "TutorialSwagger");
                        var XmlFile = string.Format("{0}/bin/TutorialSwagger.XML",System.AppDomain.CurrentDomain.BaseDirectory);
                        if (System.IO.File.Exists(XmlFile)) 
                        {
                            c.IncludeXmlComments(XmlFile);
                        }

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_39072819/article/details/103756345