Swaggerui ASP. WebAPI2

Source: Internet
Author: User

Currently in the use of ASP WebAPI2 to do background interface development, in the test with the front desk, always need to send a demo to him, but this is very troublesome, he may not remember.

Then you think of Swaggerui to generate the test document.

Don't say much, take a look at its specific usage!

The first step:

In VS2015 (the latter is your own tool) open the Package management console input:

Install-package Swashbuckle

Wait for the installation, after completion will find that in the App_start folder will be more than a configuration file SwaggerConfig.cs

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/756707/201702/756707-20170220165729007-172291445. PNG "style=" margin:0px;padding:0px;border:none; "/>

Step Two:

Open this file and find C in the register () method. Includexmlcomments (), add a parameter, i.e. change to C. Includexmlcomments (Getxmlcommentspath (Thisassembly.getname (). Name));

Then add a method to the same place as the Register method

protected static string Getxmlcommentspath (string name) {return string. Format (@ "{0}\bin\{1}.        XML ", AppDomain.CurrentDomain.BaseDirectory, name); }

Then the configuration file ends here,

Step Three:

Continue to do the configuration for the project

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/756707/201702/756707-20170220170353757-1830263459. PNG "style=" margin:0px;padding:0px;border:none; "/>

Click Save file to create a tick (XML document file), properties-----project----right

Fourth Step:

Enter Access path

Http://localhost:15416/swagger/ui/index

Here the side about the host and port needs to be replaced by mail.

Final results

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/756707/201702/756707-20170220212111226-1110209949. PNG "style=" margin:0px;padding:0px;border:none; "/>

Here to make a note, found that each request will have comments behind, and after the opening of a note, this is your interface in the comments, it can be directly displayed.

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/756707/201702/756707-20170221092548898-1093429804. PNG "style=" margin:0px;padding:0px;border:none; "/>

<summary>///Send phone verification code///</summary>///<param name= "mobile" > Mobile phone number </param>


Swaggerui ASP. WebAPI2

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.