zoukankan      html  css  js  c++  java
  • AbpZero的Swagger汉化之旅

    做汉化主要是为了出一份前后端都能看得懂的在线文档,废话不多说,我们开始准备,

    我们要在启动项目的Startup.cs中重定向一下swagger的读取方式

    1、在这个类下面,新增一个方法:

     1    public  static System.Collections.Generic.List<string> GetXmlCommentPath()
     2         {
     3             var baseDirectory = AppDomain.CurrentDomain.BaseDirectory + @"xmls";
     4             if (!Directory.Exists(baseDirectory))
     5             {
     6                 Directory.CreateDirectory(baseDirectory);
     7             }
     8             var docs = Directory.GetFiles(baseDirectory, "*.xml", SearchOption.TopDirectoryOnly).ToList();
     9             return docs;
    10         }
    View Code

    2、Ctrl+F用关键词AddSwaggerGen找到调用swagger的代码,把下面的代码覆盖上去

     1   var xmls = GetXmlCommentPath();
     2             services.AddSwaggerGen(options =>
     3             {
     4                 options.SwaggerDoc("v1", new Info { Title = "Hitouch API", Version = "v1" });
     5                 options.DocInclusionPredicate((docName, description) => true);
     6                 options.OperationFilter<FormFileOperationFilter>();
     7                 options.AddSecurityDefinition("Bearer", new ApiKeyScheme
     8                 {
     9                     Description = "Authorization format : Bearer {token}",
    10                     Name = "Authorization",
    11                     In = "header",
    12                     Type = "apiKey"
    13                 });
    14                 options.AddSecurityDefinition("Abp.TenantId", new ApiKeyScheme
    15                 {
    16                     Description = "Abp.TenantId: {Int}",
    17                     Name = "Abp.TenantId",
    18                     In = "header",
    19                     Type = "apiKey"
    20                 });
    21                 foreach (var xml in xmls)
    22                 {
    23                     if (File.Exists(xml))
    24                     {
    25                         options.IncludeXmlComments(xml);
    26                     }
    27                 }
    28 
    29                 //api界面新增authorize按钮
    30             });
    View Code

    3、在启动项目的binDebug etcoreapp2.1的文件夹下新建一个名字为xmls的文件夹

    4、把接口层的生成文件定向到上面的文件夹

    打完收工,美滋滋。

  • 相关阅读:
    20145221 《信息安全系统设计基础》实验四 外设驱动程序设计
    20145221 《信息安全系统设计基础》第11周学习总结
    第09组 Alpha冲刺(4/6)
    第09组 Alpha冲刺(3/6)
    第09组 Alpha冲刺(2/6)
    第09组 Alpha冲刺(1/6)
    第09组 团队Git现场编程实战
    第09组 团队项目-需求分析报告
    团队项目-选题报告
    第二次结对编程作业
  • 原文地址:https://www.cnblogs.com/LmuQuan/p/9442464.html
Copyright © 2011-2022 走看看