Something beautiful is on the way.

.net9 openapi是用scalar的ui

相关:

微软文档:
https://learn.microsoft.com/zh-cn/aspnet/core/fundamentals/openapi/using-openapi-documents?view=aspnetcore-9.0#use-scalar-for-interactive-api-documentation

scalar官网
https://scalar.com/

实例

1.引入库

Scalar.AspNetCore

2. 修改Program

using Scalar.AspNetCore;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.MapOpenApi();
    app.MapScalarApiReference();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.MapGet("/extension-methods", () => "Hello world!")
    .WithSummary("extension-methods This is a summary.")
    .WithDescription("This is a description.");

app.MapGet("/attributes",
    [EndpointSummary("attributes This is a summary.")]
    [EndpointDescription("This is a description.")]
    () => "Hello world!");

app.Run();

3. 访问路径

http://localhost:5084/scalar/

image

posted @ 2025-09-06 19:15  张朋举  阅读(44)  评论(0)    收藏  举报