问题描述
我们有一个包含 2 个项目的 .NET 解决方案:
We have a .NET solution with 2 projects:
- ASP.NET MVC 门户项目
- OWIN 主机 API 项目(带有自定义控制器选择器)
我们正在尝试向基于 OWIN 的 API 项目中的一些 API 控制器公开一个公共文档我们想为 API 项目中的控制器展示 Portal 项目中的 Swagger UI
We are trying to expose a public documentation to a few API controllers in the OWIN-based API projectWe would like to show the Swagger UI from the Portal project for controllers in the API project
到目前为止,所有尝试都没有成功.将 Swagger UI 添加到 Portal 项目时,它只想显示有关 Portal 项目中控制器的文档,而不是来自 API 项目的文档.
So far, all attempts have not been successful. When adding Swagger UI to the Portal project, it only wants to show documentation about controllers in the Portal project, not from the API project.
将 Swagger UI 添加到 API 项目时(不是首选解决方案),它根本不起作用,可能是因为自定义控制器选择器
When adding Swagger UI to the API project (not preferred solution), it doesn't work at all, probably because of the custom controller selector
但是,我认为我遗漏了一些明显的东西,因为这感觉像是我们遗漏的一个非常基本的配置设置
However, I think I'm missing something obvious as this feels like a very basic configuration setting that we're missing
推荐答案
Swagger UI 只是一套静态文件渲染 OpenAPI (fka. Swagger) 规范文件.这些规范文件可以由应用程序生成,也可以简单地手动编写.
Swagger UI is only a set a static file rendering OpenAPI (fka. Swagger) Specification files. These specification files can be produced by an application or simply manually written.
您可以修改原始的 Swagger UI 以创建您自己的版本并替换 URL字段(在 Authorize 按钮附近的顶部),下拉列表指向您的 2 个不同的应用程序,这些应用程序生成 OpenAPI(fka. Swagger)规范.
You could modify the original Swagger UI to create your own version and replace the URL field (on top near the Authorize button) by a drop list pointing to your 2 different applications producing OpenAPI (fka. Swagger) specification.
这篇关于在不同的项目中显示 API 的 Swagger UI (Swashbuckle)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!