SyZero.Swagger
1.1.4
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package SyZero.Swagger --version 1.1.4
NuGet\Install-Package SyZero.Swagger -Version 1.1.4
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="SyZero.Swagger" Version="1.1.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SyZero.Swagger" Version="1.1.4" />
<PackageReference Include="SyZero.Swagger" />
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 SyZero.Swagger --version 1.1.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SyZero.Swagger, 1.1.4"
#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 SyZero.Swagger@1.1.4
#: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=SyZero.Swagger&version=1.1.4
#tool nuget:?package=SyZero.Swagger&version=1.1.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SyZero.Swagger
SyZero 框架的 Swagger API 文档模块。
📦 安装
dotnet add package SyZero.Swagger
✨ 特性
- 🚀 自动文档 - 自动生成 RESTful API 文档
- 🔒 JWT 支持 - 内置 Bearer Token 认证支持
- 📖 XML 注释 - 自动加载 XML 文档注释
🚀 快速开始
1. 配置 appsettings.json
{
"Swagger": {
"Title": "My API",
"Version": "v1"
}
}
2. 注册服务
// Program.cs
var builder = WebApplication.CreateBuilder(args);
// 添加SyZero
builder.AddSyZero();
// 注册服务方式1 - 使用默认配置
builder.Services.AddSwagger();
// 注册服务方式2 - 使用委托配置
builder.Services.AddSwagger(options =>
{
options.Title = "My API";
options.Version = "v1";
});
// 注册服务方式3 - 添加多版本支持
builder.Services.AddSwagger(options =>
{
options.Versions = new[] { "v1", "v2" };
});
var app = builder.Build();
// 使用SyZero
app.UseSyZero();
// 使用 Swagger
app.UseSwagger();
app.UseSwaggerUI();
app.Run();
3. 使用示例
/// <summary>
/// 用户控制器
/// </summary>
[ApiController]
[Route("api/[controller]")]
public class UserController : ControllerBase
{
/// <summary>
/// 获取用户信息
/// </summary>
/// <param name="id">用户ID</param>
/// <returns>用户信息</returns>
[HttpGet("{id}")]
public async Task<UserDto> GetAsync(long id)
{
// 实现逻辑
}
}
📖 配置选项
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
Title |
string |
服务名称 |
API 文档标题 |
Version |
string |
"v1" |
API 版本 |
EnableAuth |
bool |
true |
启用认证按钮 |
📖 API 说明
Swagger 配置
| 特性 | 说明 |
|---|---|
[ApiController] |
标记 API 控制器 |
[HttpGet] / [HttpPost] 等 |
HTTP 方法标记 |
| XML 注释 | 自动解析为 API 描述 |
确保项目启用 XML 文档生成
🔧 高级用法
启用 XML 文档
在项目文件中添加:
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
自定义 UI
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
options.RoutePrefix = "docs";
});
⚠️ 注意事项
- XML 文档 - 必须启用 XML 文档生成才能显示注释
- 生产环境 - 建议生产环境禁用或限制访问
- 认证配置 - 使用 Authorize 按钮测试需要认证的接口
📄 许可证
MIT License - 详见 LICENSE
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- Swashbuckle.AspNetCore (>= 6.4.0)
- SyZero (>= 1.1.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.5-dev.1 | 29 | 1/29/2026 |
| 1.1.4 | 97 | 1/2/2026 |
| 1.1.4-dev.2 | 42 | 1/2/2026 |
| 1.1.4-dev.1 | 44 | 12/30/2025 |
| 1.1.3 | 95 | 12/30/2025 |
| 1.1.3-dev.6 | 46 | 12/30/2025 |
| 1.1.3-dev.3 | 110 | 1/19/2024 |
| 1.1.3-dev.2 | 174 | 11/3/2023 |
| 1.1.3-dev.1 | 189 | 3/21/2023 |
| 1.1.2 | 374 | 3/15/2023 |
| 1.1.2-dev.108.29344 | 181 | 3/15/2023 |
| 1.1.2-dev.108.28054 | 183 | 3/15/2023 |
| 1.1.2-dev.108.27487 | 181 | 3/15/2023 |
| 1.1.1 | 327 | 3/15/2023 |
| 1.1.1-dev.108.14980 | 172 | 3/15/2023 |
| 1.1.1-dev.108.13289 | 187 | 3/15/2023 |
| 1.1.1-dev.107.27144 | 174 | 3/14/2023 |
| 1.1.0 | 326 | 3/14/2023 |
| 1.1.0-workflow-dev.107.22552 | 184 | 3/14/2023 |
| 1.1.0-workflow-dev.107.21746 | 178 | 3/14/2023 |
| 1.1.0-workflow-dev.107.21506 | 178 | 3/14/2023 |
| 1.1.0-workflow-dev.107.20979 | 174 | 3/14/2023 |
| 1.1.0-dev.107.26364 | 183 | 3/14/2023 |
| 1.1.0-dev.107.24396 | 173 | 3/14/2023 |
| 1.1.0-dev.107.22787 | 186 | 3/14/2023 |
| 1.0.6 | 433 | 3/5/2022 |