如何在swagger UI中添加Swagger.json

问题描述 投票:0回答:1

我创建了一个 swagger 文档,但我不知道如何添加 json 文件

我需要添加类似的链接,重定向到新页面中的json文档

json .net visual-studio swagger openapi
1个回答
0
投票

您可以将 swagger 文档放在根目录中。

然后映射与设置为 swagger 端点相同的路由。

app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("https://localhost:7040/mypath/swaggerDoc", "customSwagger");
});

app.MapGet("/mypath/swaggerDoc", async context =>
{
    await context.Response.WriteAsync(await File.ReadAllTextAsync(Path.Combine(Directory.GetCurrentDirectory(), "swagger.json")));
});

结果

© www.soinside.com 2019 - 2024. All rights reserved.