master
wanggaofeng 1 year ago
parent b97733e9fe
commit 00200061c0

@ -5,14 +5,29 @@ using System.Threading.Tasks;
namespace SwaggerStudy namespace SwaggerStudy
{ {
/// <summary>
/// 接口返回基类
/// </summary>
public class ResultBase public class ResultBase
{ {
public static ResultBase Default => new ResultBase() { Code=-1,Message=string.Empty}; /// <summary>
/// 获取默认基类的静态方法
/// </summary>
public static ResultBase Default => new ResultBase() { Code = -1, Message = string.Empty };
/// <summary>
/// 编码
/// </summary>
public int Code { get; set; } = 0; public int Code { get; set; } = 0;
/// <summary>
/// 消息
/// </summary>
public string Message { get; set; } = string.Empty; public string Message { get; set; } = string.Empty;
/// <summary>
/// 数据(动态类型)
/// </summary>
public dynamic Data { get; set; } public dynamic Data { get; set; }
} }
} }

@ -1,5 +1,6 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Collections.Generic; using System.Collections.Generic;
@ -17,9 +18,9 @@ using Swashbuckle.AspNetCore.Swagger;
using Swashbuckle.AspNetCore.SwaggerGen; using Swashbuckle.AspNetCore.SwaggerGen;
using Swashbuckle.AspNetCore.SwaggerUI; using Swashbuckle.AspNetCore.SwaggerUI;
using SwaggerStudy.Services; using SwaggerStudy.Services;
namespace SwaggerStudy namespace SwaggerStudy
{ {
/// <summary> /// <summary>
@ -67,7 +68,7 @@ namespace SwaggerStudy
#endregion #endregion
#region 包含xml注释 #region 包含xml注释
var xmlCommentFiles = System.IO.Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, $"SwaggerStudy*.xml", System.IO.SearchOption.TopDirectoryOnly); var xmlCommentFiles = System.IO.Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}*.xml", System.IO.SearchOption.TopDirectoryOnly);
foreach (var xmlFile in xmlCommentFiles) foreach (var xmlFile in xmlCommentFiles)
{ {
//includeControllerXmlComments参数是否启用控制器上的xml注释 //includeControllerXmlComments参数是否启用控制器上的xml注释

@ -65,7 +65,8 @@ namespace SwaggerStudy
#endregion #endregion
#region 包含xml注释 #region 包含xml注释
var xmlCommentFiles = System.IO.Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, $"SwaggerStudy*.xml", System.IO.SearchOption.TopDirectoryOnly); //var xmlCommentFiles = System.IO.Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, $"SwaggerStudy*.xml", System.IO.SearchOption.TopDirectoryOnly);
var xmlCommentFiles = System.IO.Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, $"{System.Reflection.Assembly.GetExecutingAssembly().GetName().Name}*.xml", System.IO.SearchOption.TopDirectoryOnly);
foreach (var xmlFile in xmlCommentFiles) foreach (var xmlFile in xmlCommentFiles)
{ {
//includeControllerXmlComments参数是否启用控制器上的xml注释 //includeControllerXmlComments参数是否启用控制器上的xml注释

@ -19,6 +19,7 @@ using Swashbuckle.AspNetCore.SwaggerUI;
using SwaggerStudy.Services; using SwaggerStudy.Services;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
using System.Reflection;
namespace SwaggerStudy namespace SwaggerStudy
{ {
@ -61,7 +62,8 @@ namespace SwaggerStudy
#endregion #endregion
#region 包含xml注释 #region 包含xml注释
var xmlCommentFiles = System.IO.Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, $"SwaggerStudy*.xml", System.IO.SearchOption.TopDirectoryOnly); //var xmlCommentFiles = System.IO.Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, $"SwaggerStudy*.xml", System.IO.SearchOption.TopDirectoryOnly);
var xmlCommentFiles = System.IO.Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}*.xml", System.IO.SearchOption.TopDirectoryOnly);
foreach (var xmlFile in xmlCommentFiles) foreach (var xmlFile in xmlCommentFiles)
{ {
//includeControllerXmlComments参数是否启用控制器上的xml注释 //includeControllerXmlComments参数是否启用控制器上的xml注释

@ -22,6 +22,7 @@ using Swashbuckle.AspNetCore.SwaggerGen;
using Swashbuckle.AspNetCore.SwaggerUI; using Swashbuckle.AspNetCore.SwaggerUI;
using SwaggerStudy.Services; using SwaggerStudy.Services;
using System.Reflection;
namespace SwaggerStudy namespace SwaggerStudy
{ {
@ -93,7 +94,8 @@ namespace SwaggerStudy
}); });
//包含xml注释 //包含xml注释
var xmlCommentFiles = System.IO.Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, $"SwaggerStudy*.xml", System.IO.SearchOption.TopDirectoryOnly); //var xmlCommentFiles = System.IO.Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, $"SwaggerStudy*.xml", System.IO.SearchOption.TopDirectoryOnly);
var xmlCommentFiles = System.IO.Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}*.xml", System.IO.SearchOption.TopDirectoryOnly);
foreach (var xmlFile in xmlCommentFiles) foreach (var xmlFile in xmlCommentFiles)
{ {
setup.IncludeXmlComments(xmlFile, true); setup.IncludeXmlComments(xmlFile, true);
@ -120,7 +122,7 @@ namespace SwaggerStudy
//配置SwaggerGen //配置SwaggerGen
services.ConfigureSwaggerGen(setup => services.ConfigureSwaggerGen(setup =>
{ {
}); });
services.AddTransient<StudentServer>(); services.AddTransient<StudentServer>();
@ -160,6 +162,7 @@ namespace SwaggerStudy
setup.DisplayRequestDuration(); setup.DisplayRequestDuration();
setup.ShowCommonExtensions(); setup.ShowCommonExtensions();
setup.ShowExtensions(); setup.ShowExtensions();
setup.DocumentTitle = "Swagger 在线文档";
//swagger 访问页面前缀默认swagger //swagger 访问页面前缀默认swagger
//SwaggerUi首页地址baseUrl+前辍+index.html 默认:/swagger/index.html //SwaggerUi首页地址baseUrl+前辍+index.html 默认:/swagger/index.html

@ -18,8 +18,4 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Swagger\" />
</ItemGroup>
</Project> </Project>

Loading…
Cancel
Save