自定义索引 Swashbuckle/Swagger
Custom Index Swashbuckle/Swagger
这是我第一次使用 Swagger,我目前正在使用 Swashbuckle.AspNetCore v2.4.0 并尝试实现自定义索引页面。在这个版本中,他们已经消除了注入 javascript 的可能性,而我基本上坚持制作自定义 index.html 页面的唯一选择,只是为了编辑一些 links(最具体的是导航图标 link)。我正在尝试让我的自定义索引页面正常工作,但我无法加载它。
app.UseSwaggerUI(c =>
{
c.IndexStream = () => GetType().GetTypeInfo().Assembly
.GetManifestResourceStream("customSwaggerIndex.html"); // requires file to be added as an embedded resource
});
我的代码中有以下内容,customSwaggerIndex.html
保存在 wwwroot 文件夹中,其构建操作设置为嵌入式资源,但我将 运行 保留在错误 System.ArgumentNullException: Value cannot be null
中。这很可能是由于我没有正确编写 GetManifestResourceStream("string")。有帮助吗?
弄清楚为什么它不起作用。第一件事是它需要解决方案的名称,而不是 \
它的 .
因此,例如,位于我的 wwwroot 文件夹中的文件将如下所示。
c.IndexStream = () => GetType().GetTypeInfo().Assembly
.GetManifestResourceStream("MySolution.wwwroot.customSwaggerIndex.html");
这是我第一次使用 Swagger,我目前正在使用 Swashbuckle.AspNetCore v2.4.0 并尝试实现自定义索引页面。在这个版本中,他们已经消除了注入 javascript 的可能性,而我基本上坚持制作自定义 index.html 页面的唯一选择,只是为了编辑一些 links(最具体的是导航图标 link)。我正在尝试让我的自定义索引页面正常工作,但我无法加载它。
app.UseSwaggerUI(c =>
{
c.IndexStream = () => GetType().GetTypeInfo().Assembly
.GetManifestResourceStream("customSwaggerIndex.html"); // requires file to be added as an embedded resource
});
我的代码中有以下内容,customSwaggerIndex.html
保存在 wwwroot 文件夹中,其构建操作设置为嵌入式资源,但我将 运行 保留在错误 System.ArgumentNullException: Value cannot be null
中。这很可能是由于我没有正确编写 GetManifestResourceStream("string")。有帮助吗?
弄清楚为什么它不起作用。第一件事是它需要解决方案的名称,而不是 \
它的 .
因此,例如,位于我的 wwwroot 文件夹中的文件将如下所示。
c.IndexStream = () => GetType().GetTypeInfo().Assembly
.GetManifestResourceStream("MySolution.wwwroot.customSwaggerIndex.html");