如何使用 swagger-ui?
How do I use swagger-ui?
我在我的网络 api 项目中使用 Swashbuckle NuGet 包,我试图用这个替换默认的 Swagger UI
https://github.com/jensoleg/swagger-ui
但我不断收到此错误消息
<?xml version="1.0" encoding="ISO-8859-1"?>
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>Embedded resource not found - ReportsAPI.swagger-ui.Index.html</ExceptionMessage>
<ExceptionType>Swashbuckle.SwaggerUi.AssetNotFound</ExceptionType>
<StackTrace> at Swashbuckle.SwaggerUi.EmbeddedAssetProvider.GetEmbeddedResourceStreamFor(EmbeddedAssetDescriptor resourceDescriptor, String rootUrl) at Swashbuckle.SwaggerUi.EmbeddedAssetProvider.GetAsset(String rootUrl, String path) at Swashbuckle.Application.SwaggerUiHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)</StackTrace>
</Error>
我听从了这个 post 的建议
但是无法让它工作
我有一个基本的 ASP.Net Web API 2(简单的休息 api 没有网站或索引 html)
所以我从 swagger-GitHub 页面下载了 zip 文件-ui 并将 dist 文件夹复制到我的项目并将其包含为(尝试了内容和嵌入式资源)- 并重命名dist 文件夹到 swagger-ui
所以我的根项目文件夹现在看起来像
然后我更改了我的 Swagger 配置以添加以下内容
c.CustomAsset("index", thisAssembly, "ReportsAPI.swagger-ui.Index.html");
对吗?我不确定从这里去哪里
我是否必须将所有其他文件作为嵌入式资源包括在内?或者只是 Index.html?我如何将其他文件标记为“内容”?总是复制?
这是一个不需要您在项目中嵌入任何东西的替代方法:
如您所见,url 参数中提供了我的 swagger 规范。
您可以使用那个 raw.githack.com
或将 dist 文件夹复制到更方便的位置。
现在我想指出这是一个非常旧的 swagger-ui 版本并且看起来维护得不好,也许你应该看看:ReDoc https://github.com/Rebilly/ReDoc/blob/master/README.md
我在我的网络 api 项目中使用 Swashbuckle NuGet 包,我试图用这个替换默认的 Swagger UI https://github.com/jensoleg/swagger-ui
但我不断收到此错误消息
<?xml version="1.0" encoding="ISO-8859-1"?>
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>Embedded resource not found - ReportsAPI.swagger-ui.Index.html</ExceptionMessage>
<ExceptionType>Swashbuckle.SwaggerUi.AssetNotFound</ExceptionType>
<StackTrace> at Swashbuckle.SwaggerUi.EmbeddedAssetProvider.GetEmbeddedResourceStreamFor(EmbeddedAssetDescriptor resourceDescriptor, String rootUrl) at Swashbuckle.SwaggerUi.EmbeddedAssetProvider.GetAsset(String rootUrl, String path) at Swashbuckle.Application.SwaggerUiHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)</StackTrace>
</Error>
我听从了这个 post 的建议
但是无法让它工作
我有一个基本的 ASP.Net Web API 2(简单的休息 api 没有网站或索引 html)
所以我从 swagger-GitHub 页面下载了 zip 文件-ui 并将 dist 文件夹复制到我的项目并将其包含为(尝试了内容和嵌入式资源)- 并重命名dist 文件夹到 swagger-ui
所以我的根项目文件夹现在看起来像
然后我更改了我的 Swagger 配置以添加以下内容
c.CustomAsset("index", thisAssembly, "ReportsAPI.swagger-ui.Index.html");
对吗?我不确定从这里去哪里
我是否必须将所有其他文件作为嵌入式资源包括在内?或者只是 Index.html?我如何将其他文件标记为“内容”?总是复制?
这是一个不需要您在项目中嵌入任何东西的替代方法:
如您所见,url 参数中提供了我的 swagger 规范。
您可以使用那个 raw.githack.com
或将 dist 文件夹复制到更方便的位置。
现在我想指出这是一个非常旧的 swagger-ui 版本并且看起来维护得不好,也许你应该看看:ReDoc https://github.com/Rebilly/ReDoc/blob/master/README.md