Tenon.AspNetCore.OpenApi.Extensions
0.0.1-alpha-202502241449
This is a prerelease version of Tenon.AspNetCore.OpenApi.Extensions.
dotnet add package Tenon.AspNetCore.OpenApi.Extensions --version 0.0.1-alpha-202502241449
NuGet\Install-Package Tenon.AspNetCore.OpenApi.Extensions -Version 0.0.1-alpha-202502241449
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="Tenon.AspNetCore.OpenApi.Extensions" Version="0.0.1-alpha-202502241449" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tenon.AspNetCore.OpenApi.Extensions --version 0.0.1-alpha-202502241449
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Tenon.AspNetCore.OpenApi.Extensions, 0.0.1-alpha-202502241449"
#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.
// Install Tenon.AspNetCore.OpenApi.Extensions as a Cake Addin #addin nuget:?package=Tenon.AspNetCore.OpenApi.Extensions&version=0.0.1-alpha-202502241449&prerelease // Install Tenon.AspNetCore.OpenApi.Extensions as a Cake Tool #tool nuget:?package=Tenon.AspNetCore.OpenApi.Extensions&version=0.0.1-alpha-202502241449&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Tenon.AspNetCore.OpenApi.Extensions
Scalar UI OpenAPI 扩展包,提供了更美观的 API 文档界面和更灵活的配置选项。
功能特性
- 集成 Scalar UI 作为 OpenAPI 文档界面
- 支持 JWT Bearer 认证
- 支持数组参数的逗号分隔格式
- 提供完整的 XML 文档注释
- 环境感知配置
- 主题定制支持
示例项目
完整的使用示例请参考 OpenApiSample 项目,其中包含:
- JWT Bearer 认证示例
- 数组参数处理示例
- 主题定制示例
快速开始
- 安装 NuGet 包:
dotnet add package Tenon.AspNetCore.OpenApi.Extensions
- 注册服务:
// 添加 OpenAPI 服务
builder.Services.AddScalarOpenApi(builder.Configuration.GetSection("ScalarUI"));
// 使用 OpenAPI 中间件(仅在开发环境)
if (app.Environment.IsDevelopment())
{
app.UseScalarOpenApi();
}
配置说明
appsettings.json 配置示例
{
"ScalarUI": {
"Title": "API 文档",
"Version": "v1",
"Description": "API 接口文档",
"Theme": {
"DarkMode": true,
"Colors": {
"primary": "#1976d2",
"secondary": "#424242",
"success": "#2e7d32",
"error": "#d32f2f",
"warning": "#ed6c02",
"info": "#0288d1"
}
}
}
}
配置方式
- 环境感知配置:
if (app.Environment.IsDevelopment())
{
app.UseScalarOpenApi();
}
- 配置文件配置:
builder.Services.AddScalarOpenApi(builder.Configuration.GetSection("ScalarUI"));
- 代码配置:
builder.Services.AddScalarOpenApi(options =>
{
options.Title = "My API";
options.Version = "v1";
options.Theme.DarkMode = true;
});
高级功能
数组参数支持
- URL 查询参数:
[HttpGet]
public IEnumerable<string> Get(
[FromQuery][ModelBinder(typeof(CommaDelimitedArrayModelBinder))]
int[] ids)
{
// 支持 ?ids=1,2,3 格式
}
- 请求体数组:
public class BatchRequest
{
[Required]
public int[] Ids { get; set; } = Array.Empty<int>();
}
[HttpPost("batch")]
public IActionResult Post([FromBody] BatchRequest request)
{
// 支持标准 JSON 数组格式
}
认证配置
- JWT Bearer 认证:
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer();
最佳实践
环境配置:
- 开发环境启用 OpenAPI 文档
- 生产环境禁用 OpenAPI 文档
- 不同环境使用不同的认证配置
安全配置:
- 使用 HTTPS
- 配置适当的认证方式
- 启用 CORS 策略
文档优化:
- 添加完整的 XML 注释
- 提供清晰的示例
- 使用适当的响应类型
许可证
MIT
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 9.0.0)
- Microsoft.AspNetCore.OpenApi (>= 9.0.1)
- Scalar.AspNetCore (>= 2.0.15)
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 |
---|---|---|
0.0.1-alpha-202502241449 | 51 | 2/24/2025 |
0.0.1-alpha-202502101554 | 44 | 2/10/2025 |
0.0.1-alpha-202502101448 | 40 | 2/10/2025 |
0.0.1-alpha-202502101434 | 46 | 2/10/2025 |
0.0.1-alpha-202501130258 | 37 | 1/13/2025 |
0.0.1-alpha-202412311524 | 72 | 12/31/2024 |
0.0.1-alpha-202412061617 | 53 | 12/6/2024 |
0.0.1-alpha-202412051527 | 65 | 12/5/2024 |
0.0.1-alpha-202412051432 | 47 | 12/5/2024 |
0.0.1-alpha-202412041445 | 48 | 12/4/2024 |
0.0.1-alpha-202412021409 | 48 | 12/2/2024 |