Go WEBAPI automatically generate online documentation Swashbuckle

Source: Internet
Author: User

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

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.