iis - 在 IIS 上托管 NetCore 3.1 Web Api 时找不到 openapi.json
问题描述
我使用带有以下命令的 openapi 生成器为 ASP.NET Core 3.1 生成了我的服务器存根:
npx @openapitools/openapi-generator-cli generate -i myapi.json -g aspnetcore -o C:\myapi --additional-properties aspnetCoreVersion=3.1
在 Visual Studio 2019 中打开该项目并运行它后,我会得到一个招摇页面,我可以在其中尝试不同的端点。到目前为止还可以。
但是:在我们的 IIS 服务器上发布它并访问正确的 URL 后,swagger 页面正在加载错误:
未找到:/swagger/1.0.0/openapi.json
可以到达端点本身(GET 请求)。
startup.cs 中的 Swagger Endpoint 代码是由 open-api 生成器生成的默认代码:
app.UseSwagger(c =>
{
c.RouteTemplate = "swagger/{documentName}/openapi.json";
})
.UseSwaggerUI(c =>
{
//TODO: Either use the SwaggerGen generated Swagger contract (generated from C# classes)
c.SwaggerEndpoint("/swagger/1.0.0/openapi.json", "Swagger WP RUH Delivery");
//TODO: Or alternatively use the original Swagger contract that's included in the static files
// c.SwaggerEndpoint("/openapi-original.json", "Swagger WP RUH Delivery Original");
});
为什么这个 Swagger 页面在我的机器上工作,但在 IIS 上却出错了?我发现了一些关于在 startup.cs 中更改 c.SwaggerEndpoint 的提示,但没有任何帮助。
解决方案
尝试/swagger/
从 URL 路径中删除:
c.SwaggerEndpoint("1.0.0/openapi.json", "Swagger WP RUH Delivery")
推荐阅读
- javascript - console.log 在烧瓶中使用 javasript
- javascript - JavaScript vm.Script 对象在 WebDriver 堆栈跟踪中丢失“文件名”上下文
- module - 根据 Nuxt 中的棱镜数据生成站点地图
- reactjs - 如何使用 React 完全禁用 TabPanel 组件(并使文本变灰)并默认为索引中的第二个选项卡
- opencv - 寻找箭头方向的鲁棒算法OpenCV
- python - 使用带有自定义功能的 Pandas Groupby
- java - 无法在 docker 容器中调试 Playframework 应用程序
- r - R - 从数据框中删除仅在数字列中包含零的行、基本 R 和管道友好方法?
- c - OpenCL - 通过蒙特卡罗模拟逼近 Pi - 错误值
- python - 为什么叶子中的样本数与 DecisionTreeClassifier 的父节点中的值数不匹配?