Galosys.Foundation.Swashbuckle
26.7.2.1
dotnet add package Galosys.Foundation.Swashbuckle --version 26.7.2.1
NuGet\Install-Package Galosys.Foundation.Swashbuckle -Version 26.7.2.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Galosys.Foundation.Swashbuckle" Version="26.7.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Galosys.Foundation.Swashbuckle" Version="26.7.2.1" />Directory.Packages.props
<PackageReference Include="Galosys.Foundation.Swashbuckle" />Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Galosys.Foundation.Swashbuckle --version 26.7.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Galosys.Foundation.Swashbuckle, 26.7.2.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Galosys.Foundation.Swashbuckle@26.7.2.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Galosys.Foundation.Swashbuckle&version=26.7.2.1Install as a Cake Addin
#tool nuget:?package=Galosys.Foundation.Swashbuckle&version=26.7.2.1Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Galosys.Foundation.Swashbuckle
成熟度: 🟢 稳定 — 生产可用,测试充分,活跃维护
简介
基于 Swashbuckle 的 Swagger/OpenAPI 集成模块,为 ASP.NET Core API 提供自动化的在线文档生成、认证支持和自定义头部扩展。
特性
- 自动生成 RESTful API 和 gRPC 在线文档
- 支持 JWT/Bearer、Basic、ApiKey 三种认证方式
- 自动注入业务头部(租户ID、应用ID、语言、客户端类型)
- 支持请求签名验证(防篡改、防重放)
- 枚举自动显示
DescriptionAttribute注释 - 支持 Basic 认证保护 Swagger UI
- 自动发现 XML 文档注释
- 支持
[NonSwaggerGen]特性隐藏指定接口
安装
dotnet add package Galosys.Foundation.Swashbuckle
使用
基础配置
在 appsettings.json 中添加配置:
{
"Application": {
"Name": "MyAPI"
},
"Swagger": {
"DisplaySchema": false,
"AuthEnabled": true,
"Users": {
"admin": "admin123"
}
}
}
注册服务
// Program.cs
builder.Services.AddSwaggerGen(builder.Configuration);
// 或手动指定名称
builder.Services.AddSwaggerGen("MyAPI");
启用中间件
app.UseSwaggerGen();
// 自定义 UI 配置
app.UseSwaggerGen(opt =>
{
opt.DefaultModelsExpandDepth(-1);
});
隐藏接口
[NonSwaggerGen]
[ApiController]
public class InternalController : ControllerBase
{
// 此控制器将不出现在文档中
}
gRPC 文档
自动集成 gRPC Swagger,无需额外配置。
核心类
| 类/扩展方法 | 说明 |
|---|---|
AddSwaggerGen() |
注册 Swagger 服务 |
UseSwaggerGen() |
启用 Swagger 中间件 |
SwaggerOptions |
配置选项(鉴权、Schema显示) |
NonSwaggerGenAttribute |
标记隐藏的控制器/方法 |
SwaggerAuthMiddleware |
Basic 认证中间件 |
AuthOperationFilter |
自动添加认证安全要求 |
TenantIdHeaderOperationFilter |
注入 x-tenant-id 头部 |
AppIdHeaderOperationFilter |
注入 x-app-id 头部 |
LocalizationHeaderOperationFilter |
注入 Accept-Language 头部 |
ClientTypeHeaderOperationFilter |
注入 x-client-type 头部 |
SignatureHeaderOperationFilter |
注入签名验证头部 |
EnumSchemaFilter |
枚举显示 Description 注释 |
依赖
- Swashbuckle.AspNetCore.Swagger
- Swashbuckle.AspNetCore.SwaggerGen
- Swashbuckle.AspNetCore.SwaggerUI
- Microsoft.AspNetCore.Grpc.Swagger
- Galosys.Foundation.Core
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Galosys.Foundation.Core (>= 26.7.2.1)
- microsoft.aspnetcore.grpc.jsontranscoding (>= 10.0.0)
- swashbuckle.aspnetcore.swagger (>= 6.5.0)
- swashbuckle.aspnetcore.swaggergen (>= 6.5.0)
- swashbuckle.aspnetcore.swaggerui (>= 6.5.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Galosys.Foundation.Swashbuckle:
| Package | Downloads |
|---|---|
|
Galosys.Foundation.AspNetCore.MultiTenancy
Galosys.Foundation快速开发库 |
|
|
Galosys.AspNetCore.App
Galosys.Foundation快速开发库 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 26.7.2.1 | 51 | 7/2/2026 |
| 26.7.1.2 | 47 | 7/1/2026 |
| 26.5.20.1 | 127 | 5/20/2026 |
| 26.5.19.1 | 117 | 5/19/2026 |
| 26.5.18.1 | 122 | 5/18/2026 |
| 26.5.15.1 | 115 | 5/15/2026 |
| 26.5.12.3 | 120 | 5/12/2026 |
| 26.5.12.2 | 113 | 5/12/2026 |
| 26.4.27.1-rc1 | 118 | 4/26/2026 |
| 26.4.25.1-rc1 | 124 | 4/25/2026 |
| 26.4.22.2-rc7 | 116 | 4/22/2026 |
| 26.4.22.2-rc6 | 118 | 4/22/2026 |
| 26.4.22.2-rc4 | 113 | 4/22/2026 |
| 26.4.22.2-rc3 | 113 | 4/22/2026 |
| 26.4.12.8-rc1 | 120 | 4/12/2026 |
| 26.4.12.7-rc1 | 118 | 4/12/2026 |
| 26.1.30.1-rc1 | 166 | 1/30/2026 |
| 26.1.29.1 | 182 | 1/29/2026 |
| 26.1.28.5 | 176 | 1/28/2026 |
| 26.1.28.4 | 167 | 1/28/2026 |
Loading failed