【问题标题】:Build swagger dynamically In .Net Core在 .Net Core 中动态构建 swagger
【发布时间】:2023-01-24 14:23:50
【问题描述】:

I have a list of APIs and when one of the APIs is selected, I want to display the Swagger page for that API only.

在 Program.cs 文件中

    if (app.Environment.IsDevelopment())
    {
        app.UseSwagger(options =>
    
        {
        });
        app.UseSwaggerUI(options =>
        {
    
        });
    }

and there is a link to the project here.

【问题讨论】:

  • 所以您只想更改 Swagger 文档页面的外观/交互性?因为你的问题的标题表明你想构建一个 Swagger服务定义在运行时,这不是你所描述的。
  • Program.cs 中提到的代码将在启动时执行一次,而不是在运行时执行。

标签: c# swagger-ui


【解决方案1】:

这段代码正在检查当前环境是否设置为开发,如果是,则在 .Net Core 应用程序中配置 Swagger 和 Swagger UI 的使用。 “UseSwagger”方法用于配置Swagger中间件的选项,而“UseSwaggerUI”方法用于配置Swagger UI中间件的选项。如果选项 lambda 中没有其他代码,将使用 Swagger 和 Swagger UI 的默认配置。

【讨论】:

    猜你喜欢
    • 2020-04-02
    • 2019-08-29
    • 2017-08-06
    • 1970-01-01
    • 1970-01-01
    • 2021-10-22
    • 2017-10-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多