无法用 Swashbuckle/Swagger 注入 javascript
Unable to inject javascript with Swashbuckle/Swagger
我正在使用 Swashbuckle NuGet 包为我的 API 创建 Swagger 文档。 https://www.nuget.org/packages/Swashbuckle
我正在尝试对 UI 进行一些小改动 - 本质上只是在页眉中添加一些公司品牌。
我已将两个文件作为嵌入资源添加到我的项目中,位于名为 resources 的目录中。
这些通过以下方式注入 UI:
.EnableSwaggerUi(c =>
{
c.InjectStylesheet(thisAssembly, typeof(SwaggerConfig).Namespace + ".Resources.Swagger.css");
c.InjectJavaScript(thisAssembly, typeof(SwaggerConfig).Namespace + ".Resources.Swagger.js");
}
这导致以下 link 被添加到呈现的页面。
<link href="ext/ang_nav_api-Resources-Swagger-css" rel="stylesheet" type="text/css" media="screen">
一切正确,样式表按预期工作。
但是 .js 脚本没有出现在客户端上。
将 c.InjectJavaScript
更改为 c.InjectStylesheet
确实会将文件作为 <link>
注入 .. 所以我很高兴文件本身已正确嵌入等
这里可能有什么问题?
.js 脚本不会出现在客户端上。 (不是你期望的方式)
仔细看index.html的代码:
https://github.com/domaindrivendev/Swashbuckle/blob/8223bedae706fec612c98ebbcee6b2d7033ae349/Swashbuckle.Core/SwaggerUi/CustomAssets/index.html#L98
您的自定义脚本将在 onComplete 事件中动态加载
$.getScript(script);
我正在使用 Swashbuckle NuGet 包为我的 API 创建 Swagger 文档。 https://www.nuget.org/packages/Swashbuckle
我正在尝试对 UI 进行一些小改动 - 本质上只是在页眉中添加一些公司品牌。
我已将两个文件作为嵌入资源添加到我的项目中,位于名为 resources 的目录中。
这些通过以下方式注入 UI:
.EnableSwaggerUi(c =>
{
c.InjectStylesheet(thisAssembly, typeof(SwaggerConfig).Namespace + ".Resources.Swagger.css");
c.InjectJavaScript(thisAssembly, typeof(SwaggerConfig).Namespace + ".Resources.Swagger.js");
}
这导致以下 link 被添加到呈现的页面。
<link href="ext/ang_nav_api-Resources-Swagger-css" rel="stylesheet" type="text/css" media="screen">
一切正确,样式表按预期工作。
但是 .js 脚本没有出现在客户端上。
将 c.InjectJavaScript
更改为 c.InjectStylesheet
确实会将文件作为 <link>
注入 .. 所以我很高兴文件本身已正确嵌入等
这里可能有什么问题?
.js 脚本不会出现在客户端上。 (不是你期望的方式) 仔细看index.html的代码: https://github.com/domaindrivendev/Swashbuckle/blob/8223bedae706fec612c98ebbcee6b2d7033ae349/Swashbuckle.Core/SwaggerUi/CustomAssets/index.html#L98
您的自定义脚本将在 onComplete 事件中动态加载
$.getScript(script);