新增SwaggerDemo
This commit is contained in:
104
电子展板/WebModule/HomeMetadataModule.cs
Normal file
104
电子展板/WebModule/HomeMetadataModule.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using Nancy.Metadata.Modules;
|
||||
using Nancy.Swagger;
|
||||
using Swagger.ObjectModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using 电子展板.Models;
|
||||
using 电子展板.Utility.Core;
|
||||
|
||||
namespace 电子展板.WebModule
|
||||
{
|
||||
public class HomeMetadataModule : MetadataModule<PathItem>
|
||||
{
|
||||
public HomeMetadataModule(ISwaggerModelCatalog modelCatalog)
|
||||
{
|
||||
//添加模型
|
||||
modelCatalog.AddModels(typeof(MyConfig));
|
||||
Describe["getConfig"] = description => description.AsSwagger(
|
||||
with => with.Operation(
|
||||
op =>
|
||||
{
|
||||
//设置操作id
|
||||
op.OperationId("getConfig");
|
||||
//设置tag
|
||||
op.Tag("getConfig");
|
||||
//备注
|
||||
op.Summary("获得当前配置");
|
||||
//参数配置
|
||||
//op.BodyParameter(p =>
|
||||
// p.Description("配置项")
|
||||
// .Name("Config")
|
||||
// .Schema<MyConfig>()
|
||||
//);
|
||||
//返回值配置
|
||||
op.Response(r =>
|
||||
r.Description("返回数据")
|
||||
//.Example("application/json", JsonHelper.ToJson(GlobalVariable.Config))
|
||||
.Schema<MyConfig>()
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
Describe["uploadImage"] = description => description.AsSwagger(
|
||||
with => with.Operation(
|
||||
op =>
|
||||
{
|
||||
//设置操作id
|
||||
op.OperationId("uploadImage");
|
||||
//设置tag
|
||||
op.Tag("uploadImage");
|
||||
//备注
|
||||
op.Summary("上传照片");
|
||||
//文件上传
|
||||
op.ConsumeMimeType("multipart/form-data");
|
||||
//参数配置
|
||||
op.Parameter(p =>
|
||||
p.In(ParameterIn.Form)
|
||||
.Name("file")//参数名
|
||||
.Type("file")//文件类型
|
||||
.Description("上传文件")
|
||||
.IsRequired()
|
||||
);
|
||||
//返回值配置
|
||||
op.Response(r =>
|
||||
r.Description("返回数据")
|
||||
.Example("application/json", new RetValue { state = 1, message = "上传成功", data = "/upload/123.png" }.ToJson())
|
||||
.Schema<RetValue>()
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
Describe["save"] = description => description.AsSwagger(
|
||||
with => with.Operation(
|
||||
op =>
|
||||
{
|
||||
//设置操作id
|
||||
op.OperationId("save");
|
||||
//设置tag
|
||||
op.Tag("save");
|
||||
//备注
|
||||
op.Summary("保存配置");
|
||||
//参数配置
|
||||
op.BodyParameter(p =>
|
||||
p.Description("配置项")
|
||||
.Name("Config")
|
||||
.Schema<MyConfig>()
|
||||
);
|
||||
//返回值配置
|
||||
op.Response(r =>
|
||||
r.Description("返回数据")
|
||||
.Example("application/json", new RetValue { state = 1, message = "保存成功" }.ToJson())
|
||||
.Schema<RetValue>()
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user