Use swagger to build high-readability ASP. NET WEBAPI Documents

Source: Internet
Author: User
First, preface

In a recent mall project, use WEBAPI to build the API project. However, in the development process, the front-end engineers for the use of communication interfaces, is very time-consuming. I've also worked with swagger to build WEBAPI documents before, but the API documentation is not very readable. In particular, there are no instructions for passing in parameters and outgoing results, which can lead to difficult communication between developers. In the garden saw an article about the optimization of the swagger, there is a great improvement. Solve the incoming parameters, API sub-regional filtering issues, thank Bo Master Jiang Xuanbing.

However, after practice, there are still some unresolved problems:

    1. interface returned by the object, no Chinese description
    2. Interface Authorization parameter (token) not uniformly passed in

So, decide on this basis, and then do some optimization

Two, 1. Sub-regional display

2. Interface parameter description

3. Authorization Parameters Unified Incoming Token

4. Interface Query

5. Interface Development Status

Three, the key Realization 1. Project property settings generate an XML document file

2. Modify the SwaggerConfig.cs file

3. Modify the WebApiConfig.cs file to configure the routing

4. Sub-region selection of key logic

Note: implement logical and namespace separators. Have a lot to do, see file SwaggerAreasSupportDocumentFilter.cs

Four, the demo source address

github:github.com/yinboxie/swagger-demo.git

Download the demo source code, if found not automatically download NuGet dependency package, please execute command update-package-projectname ' Swagger.demo.api'-reinstall

After starting the project, access the address Http://localhost:11008/apis/index

V. Summary

swashbuckle Source code is no comment description, more difficult to read. I also just on the basis of the great God Jiang Xuanbing , modified several swashbuckle source code.

swashbuckle Source code after the change Github:github.com/yinboxie/swashbuckleex.git

Vi. references
    • Webapi Document Description -swagger optimization
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.