基于 Swagger 增强 UI,FytApi.MUI 1.0.8 发布

FytApi.MUI  支持 netcore 3.1/5.0/6.0

更新内容

【新增】返回值Jsno示例,支持多层级嵌套

【新增】返回值可视化表格数据注释信息,支持多层级嵌套

【优化】提交Body数据中,支持数组,默认值为:[]

演示地址:fytapiui

介绍

基于 swagger 的轻量级,注入化的 api-ui 组件

特点

零浸入、轻量、简单、好看、好用

可配置权限认证以及 Header,支持数组

支持 主题切换 ** 暗黑 / 亮白 **

使用说明

  1. 通过 nuget 搜索  FytApi.MUI

  2. 添加引用到 API 项目中

  3. 打开 Program.cs 配置

// 默认 swagger 不要删除
app.UseSwagger();
// 兼容 默认 SwaggerUI  可保留可删除
app.UseSwaggerUI();
// [增加]  配置UI HTTP请求管道,及相关中间件处理 ,这里配置和Swagger默认配置一样
app.UseFytApiUI(c =>
{
   c.SwaggerEndpoint("/swagger/v1/swagger.json", "devault","v1");
});
// 增加支持静态资源访问 
app.UseStaticFiles();
  1. 增加 XML 注释
在项目中右击,增加XML生成
参考如下代码
builder.Services.AddSwaggerGen(options =>
{
    // 配置相关组
    options.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "天气", Version = "v1" });
    options.SwaggerDoc("v2", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "用户", Version = "v1" });
    // 增加项目xml注释显示,如果有多个类库要显示,可以继续增加
    options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "TestApi.xml"),true);
    // [示例]-增加Model xml显示
    options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "TestApi.Model.xml"),true);
});

// UI 和 Swagger配置一样一样滴
app.UseFytApiUI(c =>
{
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "天气","v1");
    c.SwaggerEndpoint("/swagger/v2/swagger.json", "用户","v2");
});
// 增加支持静态资源访问
app.UseStaticFiles();
  1. 设置访问默认页
netcore6.0  启动配置默认访问的是swagger , 而本项目默认地址为 fytapiui

修改如下文件可设置默认访问
项目根目录 Properties/launchSettings.json
 "profiles": {
    "SwaggerApi": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "launchUrl": "fytapiui/index.html",  //将swagger 修改为 fytapiui/index.html
      "applicationUrl": "https://localhost:7106;http://localhost:5106",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "fytapiui/index.html", //将swagger 修改为 fytapiui/index.html
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }

重新启动项目即可 
https://localhost:7235/fytapiui/index.html

UI 预览

猜你喜欢

转载自www.oschina.net/news/197464/fytapi-mui-1-0-8-released