Original address: Http://www.cnblogs.com/Arrays/p/5146194.html?utm_source=tuicool&utm_medium=referral
1. Preface 1.1 Swaggerui
Swaggerui is a simple restful API testing and documentation tool. Simple, beautiful, easy to use (official demo). Displays the API by reading the JSON configuration. The project itself only relies on some html,css.js static files. You can use them on almost any web container.
1.2 Swashbuckle
Swashbuckle is a. NET class library that generates a JSON configuration corresponding to Swaggerui for all WEBAPI open controller methods. and show it through Swaggerui. The class library already contains Swaggerui. So no additional installation is required.
2. Versions and resources
You can get instructions from the following connections.
Swashbuckle Project Address:
Https://github.com/domaindrivendev/Swashbuckle
Swagger-ui Project Address:
Https://github.com/swagger-api/swagger-ui
Swagger-ui website Address:
http://swagger.io/swagger-ui/
3. Quick Start
WebAPI installation Swashbuckle
Install-Package Swashbuckle
Browser access
http://<yourhostname>.com/swagger/ui/index
Display if not unexpected
4. The code comment generates a document description.Swashbuckle is a description of the generated Swaggerui,json configuration that reads the comments from the generated XML file.
At installation, a SwaggerConfig.cs profile is generated under the project directory App_start folder for configuring Swaggerui related display behavior.
Take the 99th line of the configuration file, remove the comment, and change it to
c.IncludeXmlComments(GetXmlCommentsPath(thisAssembly.GetName().Name));
and add the following code to the current class
///<summary>///</summary>/// <param name= "name" ></param> ///<returns></returns>protected static string GetXmlCommentsPath ( string name) {return string. Format (@ "{0}\bin\{1}. XML ", AppDomain.CurrentDomain.BaseDirectory, name);}
Then you select the "XML document file" In this Web project property selection, generate the selection card
Open Control "Valuescontroller" to add comments
Using System;Using System.Collections.Generic;Using System.Linq;Using System.Net;Using System.Net.Http;Using System.Web.Http;Using ClassLibrary1;Namespacewebapplication1.controllers{[Authorize]PublicClassValuescontroller:Apicontroller {Some code .....///<summary>Get a value by ID///</summary> ///<param name=" id "> Value id</param> Span class= "hljs-comment" >///<remarks> the current method gets a value based on the ID Span class= "Hljs-doctag" ></remarks> ///<returns> return </returns> public string get ( int ID) {return "value";} //Some code ...}}
Save the rewrite build.
Go WEBAPI automatically generate online documentation Swashbuckle