Skip to content

Commit

Permalink
Merge pull request #74 from EasilyNET/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
joesdu authored Apr 23, 2023
2 parents 3d32847 + 8dd25f8 commit ebed8d3
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 21 deletions.
1 change: 1 addition & 0 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ exec { & dotnet test -c Release --no-build -l trx --verbosity=normal }
# Core
exec { & dotnet pack .\src\EasilyNET.Core\EasilyNET.Core.csproj -c Release -o $artifacts --include-symbols -p:SymbolPackageFormat=snupkg --no-build }
exec { & dotnet pack .\src\EasilyNET.WebCore\EasilyNET.WebCore.csproj -c Release -o $artifacts --include-symbols -p:SymbolPackageFormat=snupkg --no-build }
#exec { & dotnet pack .\src\EasilyNET.WebCore.Swagger\EasilyNET.WebCore.Swagger.csproj -c Release -o $artifacts --include-symbols -p:SymbolPackageFormat=snupkg --no-build }

# Framework
exec { & dotnet pack .\src\EasilyNET.AutoDependencyInjection\EasilyNET.AutoDependencyInjection.csproj -c Release -o $artifacts --include-symbols -p:SymbolPackageFormat=snupkg --no-build }
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Project>

<PropertyGroup>
<Version>1.3.8.6</Version>
<Version>1.3.9</Version>
<LangVersion>preview</LangVersion>
<RepositoryUrl>https://github.com/EasilyNET/EasilyNET</RepositoryUrl>
<Nullable>enable</Nullable>
Expand Down
7 changes: 7 additions & 0 deletions EasilyNET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasilyNET.Security", "src\E
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasilyNET.RabbitBus.Core", "src\EasilyNET.RabbitBus.Core\EasilyNET.RabbitBus.Core.csproj", "{D39C32BF-85C7-41FA-968A-88CE4AEB41B9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasilyNET.WebCore.Swagger", "src\EasilyNET.WebCore.Swagger\EasilyNET.WebCore.Swagger.csproj", "{2DC8E076-CC8C-43FB-84A4-CB53E296DF8F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -118,6 +120,10 @@ Global
{D39C32BF-85C7-41FA-968A-88CE4AEB41B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D39C32BF-85C7-41FA-968A-88CE4AEB41B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D39C32BF-85C7-41FA-968A-88CE4AEB41B9}.Release|Any CPU.Build.0 = Release|Any CPU
{2DC8E076-CC8C-43FB-84A4-CB53E296DF8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2DC8E076-CC8C-43FB-84A4-CB53E296DF8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2DC8E076-CC8C-43FB-84A4-CB53E296DF8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2DC8E076-CC8C-43FB-84A4-CB53E296DF8F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -141,6 +147,7 @@ Global
{FDE3D67B-FA75-4806-8839-8B080893579C} = {2CB52E13-C7D0-4C8C-BFAD-F1A115AD5373}
{81F28F9F-77CF-43C2-8732-8B03B54F185F} = {BD6D1E2B-691E-4E8B-9E8D-E7FD2EDDF1F8}
{D39C32BF-85C7-41FA-968A-88CE4AEB41B9} = {BD6D1E2B-691E-4E8B-9E8D-E7FD2EDDF1F8}
{2DC8E076-CC8C-43FB-84A4-CB53E296DF8F} = {71FB9978-EB6D-4126-B5D1-FECED3C73D37}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {04F52789-9FF4-4AB9-9132-1789A00E7E4A}
Expand Down
2 changes: 1 addition & 1 deletion Test/WebApi.Test.Unit/Controllers/RabbitBusController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using EasilyNET.Core.Language;
using EasilyNET.RabbitBus.Core;
using EasilyNET.WebCore.Attributes;
using EasilyNET.WebCore.Swagger.Attributes;
using Microsoft.AspNetCore.Mvc;
using WebApi.Test.Unit.Events;

Expand Down
2 changes: 1 addition & 1 deletion Test/WebApi.Test.Unit/ServiceModules/SwaggerModule.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using EasilyNET.AutoDependencyInjection.Contexts;
using EasilyNET.AutoDependencyInjection.Extensions;
using EasilyNET.AutoDependencyInjection.Modules;
using EasilyNET.WebCore.Extensions;
using EasilyNET.WebCore.Swagger;
using Microsoft.OpenApi.Models;

namespace WebApi.Test.Unit;
Expand Down
2 changes: 1 addition & 1 deletion Test/WebApi.Test.Unit/WebApi.Test.Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<ProjectReference Include="..\..\src\EasilyNET.Mongo.GridFS\EasilyNET.Mongo.GridFS.csproj" />
<ProjectReference Include="..\..\src\EasilyNET.Mongo\EasilyNET.Mongo.csproj" />
<ProjectReference Include="..\..\src\EasilyNET.RabbitBus\EasilyNET.RabbitBus.csproj" />
<ProjectReference Include="..\..\src\EasilyNET.WebCore\EasilyNET.WebCore.csproj" />
<ProjectReference Include="..\..\src\EasilyNET.WebCore.Swagger\EasilyNET.WebCore.Swagger.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ReSharper disable MemberCanBePrivate.Global

namespace EasilyNET.WebCore.Attributes;
namespace EasilyNET.WebCore.Swagger.Attributes;

/// <summary>
/// 被此特性标记的控制器可在Swagger文档分组中发挥作用.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace EasilyNET.WebCore.Attributes;
namespace EasilyNET.WebCore.Swagger.Attributes;

/// <summary>
/// 被此特性标记的Action或者控制器可在Swagger文档中隐藏.
Expand Down
18 changes: 18 additions & 0 deletions src/EasilyNET.WebCore.Swagger/EasilyNET.WebCore.Swagger.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<PackageProjectUrl>https://www.nuget.org/packages/EasilyNET.WebCore.Swagger</PackageProjectUrl>
<Description>一些Swagger的一些配置.</Description>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EasilyNET.WebCore\EasilyNET.WebCore.csproj" />
</ItemGroup>

</Project>
49 changes: 49 additions & 0 deletions src/EasilyNET.WebCore.Swagger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
### EasilyNET.WebCore.Swagger

将Swagger的扩展独立出来,避免WebCore的过度依赖.

### 如何使用?

- [Swashbuckle.AspNetCore](https://github.com/domaindrivendev/Swashbuckle.AspNetCore)

```csharp
// 添加 Swagger 服务
private const string name = $"{title}-{version}";

private const string version = "v1";
private const string title = "WebApi.Test";

builder.Services.AddSwaggerGen(c =>
{
// 配置默认的文档信息
c.SwaggerDoc(name, new()
{
Title = title,
Version = version,
Description = "Console.WriteLine(\"🐂🍺\")"
});
// 这里使用EasilyNET提供的扩展配置.
c.EasilySwaggerGenOptions(name);
// 配置认证方式
c.AddSecurityDefinition("Bearer", new()
{
Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
Name = "Authorization",
In = ParameterLocation.Header,
Type = SecuritySchemeType.ApiKey,
Scheme = "Bearer"
});
});

...

// 注册 Swagger 中间件
app.UseSwagger().UseSwaggerUI(c =>
{
// 配置默认文档
c.SwaggerEndpoint($"/swagger/{name}/swagger.json", $"{title} {version}");
// 使用EasilyNET提供的扩展配置
c.EasilySwaggerUIOptions();
});

```
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using EasilyNET.Core.Misc;
using EasilyNET.WebCore.Attributes;
using EasilyNET.WebCore.SwaggerFilters;
using EasilyNET.WebCore.Swagger.Attributes;
using EasilyNET.WebCore.Swagger.SwaggerFilters;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Swashbuckle.AspNetCore.SwaggerGen;
Expand All @@ -10,7 +10,7 @@
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global

namespace EasilyNET.WebCore.Extensions;
namespace EasilyNET.WebCore.Swagger;

/// <summary>
/// Swagger扩展
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// ReSharper disable UnusedType.Global

namespace EasilyNET.WebCore.SwaggerFilters;
namespace EasilyNET.WebCore.Swagger.SwaggerFilters;

/// <summary>
/// 在Swagger文档中给需要Authorize的接口添加🔒
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using EasilyNET.WebCore.Attributes;
using EasilyNET.WebCore.Swagger.Attributes;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Reflection;

// ReSharper disable UnusedType.Global

namespace EasilyNET.WebCore.SwaggerFilters;
namespace EasilyNET.WebCore.Swagger.SwaggerFilters;

/// <summary>
/// 在Swagger文档中隐藏接口
Expand All @@ -23,10 +23,7 @@ public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
{
foreach (var apiDescription in context.ApiDescriptions)
{
#pragma warning disable IDE0048
if (!apiDescription.TryGetMethodInfo(out var method) || !method.ReflectedType!.IsDefined(typeof(HiddenApiAttribute)) && !method.IsDefined(typeof(HiddenApiAttribute)))
#pragma warning restore IDE0048
continue;
if (!apiDescription.TryGetMethodInfo(out var method) || (!method.ReflectedType!.IsDefined(typeof(HiddenApiAttribute)) && !method.IsDefined(typeof(HiddenApiAttribute)))) continue;
var key = $"/{apiDescription.RelativePath}";
if (key.Contains('?'))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

// ReSharper disable UnusedType.Global

namespace EasilyNET.WebCore.SwaggerFilters;
namespace EasilyNET.WebCore.Swagger.SwaggerFilters;

/// <summary>
/// 添加默认值显示
Expand Down
7 changes: 3 additions & 4 deletions src/EasilyNET.WebCore/EasilyNET.WebCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<PackageProjectUrl>https://www.nuget.org/packages/EasilyNET.WebCore</PackageProjectUrl>
<Description>实现统一接口返回,全局异常以及接口执行消耗时间等功能,以及添加一些Swagger的一些配置.</Description>
<Description>包含Swagger的一些扩展的WebCore扩展</Description>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.5.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
</ItemGroup>

<ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EasilyNET.Core\EasilyNET.Core.csproj" />
</ItemGroup>

Expand Down

0 comments on commit ebed8d3

Please sign in to comment.