. Net Core Distributed microservices Framework-Jimu Add Swagger support

Source: Internet
Author: User

Series Articles
    1. Introduction to. Net Core Distributed micro-service framework-Jimu
    2. . Net Core Distributed microservices Framework-Jimu Add Swagger support
First, preface

Recently available to optimize the Jimu (a distributed micro-service framework based on. Net Core), considering the current development organization to the front and back of the separation of development, the front and back of each side, good API documentation can reduce the time cost of communication, so give priority to Jimu to add support for API document generation. The most famous and awesome API document generation framework on the market is non-swagger. It can be used to generate, describe, and invoke a visual Web service. It took more than two days to integrate it into Jimu's apigateway.

API List

API details

Second, the mode of use 1. Environment
    • Net Core 2.0
    • Apigateway based on the JIMU framework
2. Adding references
Install-Package Jimu.Client.ApiGateway.SwaggerIntegration
3. Startup code

Add Usejimuswagger () in Startup

        public void ConfigureServices(IServiceCollection services)        {             services.UseJimuSwagger(); // 添加 Swagger 支持         }         public void Configure(IApplicationBuilder app, IHostingEnvironment env)        {              app.UseJimuSwagger(); // 添加 Swagger 支持     
4. Defining interfaces (services/methods)

The interface definition can add three annotations that will eventually appear in the swagger generated document.

A. jimuservice annotations are definitions and descriptions of interface metadata, such as creator, time, description, Access role restrictions, and so on.
b. The jimufieldcomment Callout is a comment on the formal parameter.
c. jimureturncomment Annotations are comments on the return type of the interface.

        [JimuService(EnableAuthorization = true, CreatedBy = "grissom", CreatedDate = "2018-07-17", Comment = "根据新闻 id 获取新闻内容")]        [JimuFieldComment("id", "新闻id")]        [JimuReturnComment("一篇新闻内容")]        News GetNews(string id);
5. Defining Objects (DTOs)

If the interface parameter or return type is a user-defined class, the corresponding property can also add annotation callout jimufieldcomment, which will eventually appear in the swagger generated document.

    public class News    {        [JimuFieldComment("新闻id")]        public string Id { get; set; }        [JimuFieldComment("新闻标题")]        public string Title { get; set; }        [JimuFieldComment("作者")]        public string Director { get; set; }        [JimuFieldComment("发布时间")]        public string PostTime { get; set; }        [JimuFieldComment("新闻内容")]        public string Content { get; set; }    }
Three, illustrations

Iv. Summary

Support for open source is very tiring and time-consuming work, but the open source process, I also learned a lot of knowledge, hope can continue to persist.

Five, the source code

Https://github.com/grissomlau/jimu

Https://github.com/grissomlau/jimu.demo

. Net Core Distributed microservices Framework-Jimu Add Swagger support

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.