gpt4 book ai didi

swagger - 无法在 Swagger 中注入(inject) Javascript

转载 作者:行者123 更新时间:2023-12-04 18:29:10 25 4
gpt4 key购买 nike

我试图在我的 Swagger 中注入(inject)一个 JavaScript 文件的 404。以下是我的 Swagger 配置

var thisAssembly = typeof(SwaggerConfig).Assembly;

GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "A title for your API");
})
.EnableSwaggerUi(c =>
{
c.InjectJavaScript(thisAssembly,"MyApi.Api.SwaggerExtensions.inject.js");
});

对于 inject.js 构建操作设置为嵌入资源并且逻辑路径是正确的,因为我的项目名称是 MyApi.Api 并且文件位于项目中名为 SwaggerExtensions 的文件夹中

最佳答案

我花了很多时间试图弄清楚同名的方法有不同的行为。 Startup.Configure 中的配置需要来自 wwwroot 的相对路径:

public void Configure(IApplicationBuilder app) {
//
app.UseSwagger();
app.UseSwaggerUI(c => {
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Salon API v1");
c.InjectJavascript("/SwaggerExtension.js");
});
}
Get started with Swashbuckle and ASP.NET Core

关于swagger - 无法在 Swagger 中注入(inject) Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41493764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com