ABP-SwaggerUI集成

项目结构如图:

WebApi 层通过Nuget包引入Swashbuckle.Core.dll

然后在SampleTaskSystemWebApiModule模块类文件中加入如下方法:

在模块初始化函数中加入:

以上操作基本完成Abp-Swagger的集成

有一下几点需要注意:

1、添加SwaggerUI文档注释

右键单击Application层-属性  点击生成

给应用服务接口IPersonAppService方法添加注释

2、SwaggerUI文档汉化

首先定义Swagger.js文件:将该文件的属性改为嵌入的资源

代码如下:

$(function () {

$("#logo").text("Demo");
$("#logo").attr("href", "http://www.Demo.com");

$("#explore").text("查询");

$(".options .toggleEndpointList").each(function () {
$(this).text("展开/隐藏");
});
$(".options .collapseResource").each(function () {
$(this).text("显示资源列表");
});

$(".options .expandResource").each(function () {
$(this).text("显示资源明细");
});

$(".operations .description-link").each(function () {
$(this).text("实体模型");
});

$(".operations .snippet-link").each(function () {
$(this).text("实体类型");
});

$(".operations .response-content-type label").each(function () {
$(this).text("请求方式");
});
$(".operations .sandbox h4").each(function () {
$(this).text("参数列表");
});

$(".operations .response_hider").each(function () {
$(this).text("隐藏响应界面");
});
$(".operations .response .curl").each(function () {
$(this).text("请求头");
});

$(".operations .response .curl").each(function () {
$(this).next().text("请求路径");
});

$(".response_body").each(function () {
$(this).prev().text("响应正文");
});

$("[class='block response_code']").each(function () {
$(this).prev().text("响应代码");
});

$("[class='block response_headers']").each(function () {
$(this).prev().text("响应标头");
});

$(".parameter-content-type div label").each(function () {
$(this).text("参数的内容类型︰");
});

$("small.notice").each(function () {
$(this).text("单击要设置为参数值");
});

$(".body-textarea").each(function () {
var op = $(this).attr("placeholder");

if (op === "(required)") {
$(this).attr("placeholder", "(不可为空)");
}
});

$(".body-textarea required");

$(".fullwidth thead tr th").each(function () {
var key = $(this).text();
switch (key) {
case "Parameter":
$(this).text("参数名");
break;
case "Value":
$(this).text("参数值");
break;
case "Description":
$(this).text("描述");
break;
case "Parameter Type":
$(this).text("参数类型");
break;
case "Data Type":
$(this).text("数据类型");
break;

default:
break;
}
});

$("input[type='submit']").val("测试");
})

然后运行Web项目,预览结果如图:

猜你喜欢

转载自www.cnblogs.com/haweisir/p/8931216.html
ABP