优化swagger.json生成

pull/3/head
zhontai 2 years ago
parent 847074cf67
commit 1513cfaed9

1
.gitignore vendored

@ -342,7 +342,6 @@ healthchecksdb
# wwwroot/images
*images/
.1YourProject
!Admin.Core.Webapi.Template.1.0.0.nupkg
/Admin.Core/.config

@ -41,7 +41,7 @@
"routePrefix": "",
//
"footer": {
"enable": true,
"enable": false,
"content": "Copyright<a-icon type=\"copyright\" /> 2022-<a target=\"_blank\" href=\"https://www.zhontai.net\">中台Admin</a>"
}
},

@ -137,7 +137,7 @@ public class SwaggerFooterConfig
/// <summary>
/// 启用
/// </summary>
public bool Enable { get; set; } = true;
public bool Enable { get; set; } = false;
/// <summary>
/// 内容

@ -12,7 +12,6 @@ public class EnumSchemaFilter : ISchemaFilter
{
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
{
//CommonUtils.GetProperyCommentBySummary
var type = context.Type;
if (type.IsEnum)
{
@ -23,10 +22,12 @@ public class EnumSchemaFilter : ISchemaFilter
if (items?.Count > 0)
{
string description = string.Join(",", items);
schema.Extensions.Add("extensions", new OpenApiObject
{
["description"] = new OpenApiString(description)
});
//schema.Extensions.Add("extensions", new OpenApiObject
//{
// ["description"] = new OpenApiString(description)
//});
//CommonUtils.GetProperyCommentBySummary
schema.Description = string.IsNullOrEmpty(schema.Description) ? description : $"{schema.Description}:{description}";
}
}

@ -304,8 +304,6 @@ public class HostApp
//c.OrderActionsBy(o => o.RelativePath);
});
options.SchemaFilter<EnumSchemaFilter>();
options.CustomOperationIds(apiDesc =>
{
var controllerAction = apiDesc.ActionDescriptor as ControllerActionDescriptor;
@ -313,7 +311,7 @@ public class HostApp
});
options.ResolveConflictingActions(apiDescription => apiDescription.First());
options.CustomSchemaIds(x => x.FullName);
//options.CustomSchemaIds(x => x.FullName);
//options.DocInclusionPredicate((docName, description) => true);
string[] xmlFiles = Directory.GetFiles(AppContext.BaseDirectory, "*.xml");
@ -330,12 +328,17 @@ public class HostApp
Url = appConfig.Swagger.Url,
Description = ""
};
server.Extensions.Add("extensions", new OpenApiObject
if (appConfig.ApiUI.Footer.Enable)
{
["copyright"] = new OpenApiString(appConfig.ApiUI.Footer.Content)
});
server.Extensions.Add("extensions", new OpenApiObject
{
["copyright"] = new OpenApiString(appConfig.ApiUI.Footer.Content)
});
}
options.AddServer(server);
options.SchemaFilter<EnumSchemaFilter>();
#region 添加设置Token的按钮
if (appConfig.IdentityServer.Enable)

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Loading…
Cancel
Save