From 17e8fc52ad82f401a6a33b6c0dd7555861708e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E7=9B=8A?= Date: Thu, 15 Jan 2026 22:09:14 +0800 Subject: [PATCH] =?UTF-8?q?Microsoft=20OpenApi=20=E8=BF=98=E5=8E=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Directory.Build.targets | 6 ++-- NuGet.Config | 2 +- host/JiShe.IoT.HttpApi.Host/GlobalUsings.cs | 2 +- .../IoTHttpApiHostModule.Configure.cs | 33 +++++++++++-------- .../IoTHttpApiHostModule.cs | 4 ++- .../JiShe.IoT.HttpApi.Host.csproj | 4 ++- 6 files changed, 31 insertions(+), 20 deletions(-) diff --git a/Directory.Build.targets b/Directory.Build.targets index 6a3c318..ca2e715 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -63,9 +63,9 @@ - - - + + + diff --git a/NuGet.Config b/NuGet.Config index 0852dfa..3a983bb 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -2,7 +2,7 @@ - + diff --git a/host/JiShe.IoT.HttpApi.Host/GlobalUsings.cs b/host/JiShe.IoT.HttpApi.Host/GlobalUsings.cs index 12c56af..c55cd9d 100644 --- a/host/JiShe.IoT.HttpApi.Host/GlobalUsings.cs +++ b/host/JiShe.IoT.HttpApi.Host/GlobalUsings.cs @@ -36,7 +36,7 @@ global using Microsoft.Extensions.Logging; global using Microsoft.Extensions.Logging.Abstractions; global using Microsoft.Extensions.Options; global using Microsoft.IdentityModel.Tokens; -global using Microsoft.OpenApi; +global using Microsoft.OpenApi.Models; global using JiShe.IoT; global using Serilog; global using StackExchange.Redis; diff --git a/host/JiShe.IoT.HttpApi.Host/IoTHttpApiHostModule.Configure.cs b/host/JiShe.IoT.HttpApi.Host/IoTHttpApiHostModule.Configure.cs index 88d1662..aa55d35 100644 --- a/host/JiShe.IoT.HttpApi.Host/IoTHttpApiHostModule.Configure.cs +++ b/host/JiShe.IoT.HttpApi.Host/IoTHttpApiHostModule.Configure.cs @@ -148,16 +148,13 @@ public partial class IoTHttpApiHostModule context.Services.AddSwaggerGen( options => { - // 隐藏ABP默认的端点 - options.HideAbpEndpoints(); - // 文件下载类型 - options.MapType(() => new OpenApiSchema() { Type = JsonSchemaType.String, Format = "binary" }); + options.MapType(() => new OpenApiSchema() { Type = "file" }); options.SwaggerDoc("AbpPro", new OpenApiInfo { Title = "AbpPro API", Version = "v1" }); var configuration = context.Services.GetConfiguration(); - var groupNames = System.EnumExtensions.GetEnumTypeValueNameList(); + var groupNames = EnumExtensions.GetEnumTypeValueNameList(); var excludeSwaggerGroups = configuration.GetSection("ExcludeSwaggerGroup").Get>() ?? new List(); groupNames.ForEach(group => @@ -210,12 +207,18 @@ public partial class IoTHttpApiHostModule Scheme = JwtBearerDefaults.AuthenticationScheme, BearerFormat = "JWT" }); - options.AddSecurityRequirement(document => new OpenApiSecurityRequirement + options.AddSecurityRequirement(new OpenApiSecurityRequirement { - { - new OpenApiSecuritySchemeReference(JwtBearerDefaults.AuthenticationScheme, document), - new List() - } + { + new OpenApiSecurityScheme + { + Reference = new OpenApiReference + { + Type = ReferenceType.SecurityScheme, Id = "Bearer" + } + }, + new List() + } }); options.AddSecurityDefinition("ApiKey", new OpenApiSecurityScheme() @@ -226,11 +229,15 @@ public partial class IoTHttpApiHostModule Description = "多语言设置,系统预设语言有zh-Hans、en,默认为zh-Hans", }); - options.AddSecurityRequirement(document => new OpenApiSecurityRequirement + options.AddSecurityRequirement(new OpenApiSecurityRequirement { { - new OpenApiSecuritySchemeReference("ApiKey", document), - new List() + new OpenApiSecurityScheme + { + Reference = new OpenApiReference + { Type = ReferenceType.SecurityScheme, Id = "ApiKey" } + }, + Array.Empty() } }); }); diff --git a/host/JiShe.IoT.HttpApi.Host/IoTHttpApiHostModule.cs b/host/JiShe.IoT.HttpApi.Host/IoTHttpApiHostModule.cs index c5e9707..854155d 100644 --- a/host/JiShe.IoT.HttpApi.Host/IoTHttpApiHostModule.cs +++ b/host/JiShe.IoT.HttpApi.Host/IoTHttpApiHostModule.cs @@ -6,7 +6,9 @@ using System.Text.Encodings.Web; using System.Text.Json; using System.Text.Json.Serialization; using System.Text.Unicode; +using Volo.Abp.Autofac; using Volo.Abp.BlobStoring.FileSystem; +using Volo.Abp.EntityFrameworkCore.PostgreSql; using Volo.Abp.Swashbuckle; namespace JiShe.IoT @@ -25,7 +27,7 @@ namespace JiShe.IoT typeof(AbpCachingStackExchangeRedisModule), typeof(AbpBlobStoringFileSystemModule), typeof(AbpDistributedLockingModule), - typeof(AbpSwashbuckleModule) + typeof(AbpEntityFrameworkCorePostgreSqlModule) //typeof(AbpBackgroundJobsHangfireModule) )] public partial class IoTHttpApiHostModule : AbpModule diff --git a/host/JiShe.IoT.HttpApi.Host/JiShe.IoT.HttpApi.Host.csproj b/host/JiShe.IoT.HttpApi.Host/JiShe.IoT.HttpApi.Host.csproj index fcc1bfe..156e868 100644 --- a/host/JiShe.IoT.HttpApi.Host/JiShe.IoT.HttpApi.Host.csproj +++ b/host/JiShe.IoT.HttpApi.Host/JiShe.IoT.HttpApi.Host.csproj @@ -20,7 +20,6 @@ - @@ -44,6 +43,9 @@ + + +