Used to do Webapi call test, has been using the Fiddler Test tool, and this is cumbersome to use, requires a variety of configurations, and not intuitive, and one thing is to understand the URL address and the parameters to be passed before it can be called. Recently new recruits, the company also used the WEBAPI call, but the use of the call tool let me bright, he used the swagger. This tool may have not been heard, it just refers to a package can be embedded in the project, when used to directly enter the URL to see the call interface. You have not used before, yes, then please see below introduction ~
1. First, create a WEBPAPI type of project Testswagger
2. Installing the Swashbuckle.core package with Nuget
After the installation is complete, you can see that these classes and files are swagger added when the installation is complete.
3. Open the XML document file
Right-click Project Properties, generate, tick XML document file
4. Add comments
We found that when the installation was complete, the write comment did not increase on the swagger page, so we now turn on the comment
In the Swaggerconfig class, add the following XML parsing when Enableswagger
usingSystem.Web.Http;usingWebactivatorex;usingTestswagger;usingswashbuckle.application; [Assembly:preapplicationstartmethod (typeof(Swaggerconfig),"Register")]namespacetestswagger{ Public classSwaggerconfig { Public Static voidRegister () {varthisassembly =typeof(Swaggerconfig). Assembly; Globalconfiguration.configuration. Enableswagger (c={c.singleapiversion ("v1","Testswagger"); //Add XML parsingc.includexmlcomments (Getxmlcommentspath ()); }) . Enableswaggerui (c= { }); } //Add XML parsing Private Static stringGetxmlcommentspath () {return string. Format ("{0}/bin/testswagger.xml", System.AppDomain.CurrentDomain.BaseDirectory); } }}
Note Modify the corresponding XML name.
Source:https://www.cnblogs.com/alunchen/p/6888002.html
"Go" C # configure swagger in the WEBAPI project