技工网,铁腕总裁猎冷妻,校园全能高手txt全集下载
最近有空就优化 (一个基于.Net Core 的分布式微服务框架),考虑到现在的开发组织都向前后端分离发展,前后端各司其职,好的 api 文档可以减少大家沟通的时间成本,所以优先给 Jimu 添加对 api 文档生成的支持。市面上非常著名和牛逼的的 api 文档生成框架非 swagger 莫属。 它可以用来生成、描述、调用可视化的 Web 服务。花了 二天多的时间把它集成到 Jimu 的 apigateway。
如图
api 列表
api 明细
Install-Package Jimu.Client.ApiGateway.SwaggerIntegration
在 Startup 里添加 UseJimuSwagger()
public void ConfigureServices(IServiceCollection services) { services.UseJimuSwagger(); // 添加 Swagger 支持 } public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseJimuSwagger(); // 添加 Swagger 支持
接口定义可以添加三种标注,这些标注最终会显示在 swagger 生成的文档。
a. JimuService 标注是对接口元数据的定义和描述,如创建人、时间、描述、访问角色限制等。
b. JimuFieldComment 标注是对形式参数的注释。
c. JimuReturnComment 标注是对接口的返回类型做注释。
[JimuService(EnableAuthorization = true, CreatedBy = "grissom", CreatedDate = "2018-07-17", Comment = "根据新闻 id 获取新闻内容")] [JimuFieldComment("id", "新闻id")] [JimuReturnComment("一篇新闻内容")] News GetNews(string id);
如果接口参数或返回类型是一个用户定义的类,对应的属性也可以添加注释标注 JimuFieldComment, 这些标注最终会显示在 swagger 生成的文档。
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; } }
支持开源是很累和很耗时间的活,不过开源过程中自己也学到很多知识,希望可以一直坚持下去。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Net Core Web Api项目与在NginX下发布的方法
asp.net core3.1 引用的元包dll版本兼容性问题解决方案
IdentityServer4实现.Net Core API接口权限认证(快速入门)
ASP.NET Core MVC通过IViewLocationExpander扩展视图搜索路径的实现
网友评论