"Go" C # configure swagger in the WEBAPI project

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.