英文:
Swagger UI Endless Spinner On Load
问题
我正在尝试将 Swashbuckle Swagger 集成到一个 .NET 7 项目中。然而,当我加载 Swagger UI 时,我得到一个无休止的旋转图标。看起来它进入了一个无限循环,可能是试图创建 swagger.json,如果我让它运行足够长的时间,可以看到我的机器内存被填满,然后崩溃。
在审查对 swagger.json 文件的调用时,它只显示正在获取该文件。
以下是在 Startup.cs 的 Configure 方法中的代码。我已经尝试更改 JSON 路径为 swagger/v1/swagger.json
、/v1/swagger.json
、v1/swagger.json
甚至 ../swagger/v1/swagger.json
,都表现出相同的行为。
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "RackEmApp API V1");
});
并且这是从 Startup.cs 中的 ConfigureServices 方法中摘录的内容。
services.AddSwaggerGen(c =>
{
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
c.SwaggerDoc("v1", new OpenApiInfo
{
Version = "v1",
Title = "RackEmApp API",
Description = "A Web API for developers to interact with the RackEmApp dataset for a given league/organization. This is in development and has limited support.",
});
});
英文:
I am trying to implement Swashbuckle Swagger to a .NET 7 project. However, when I load the Swagger UI, I get an endless spinner. It appears to be going into some endless loop, presumably trying to create the swagger.json, as if i leave it for long enough and can watch my machine's memory get filled and then crash.
And when reviewing the call to the swagger.json file it just shows it is being fetched.
Here is the code in the Configure method of Startup.cs. I have tried altering the json path to swagger/v1/swagger.json
, /v1/swagger.json
, v1/swagger.json
and event ../swagger/v1/swagger.json
, all exhibit the same behaviour.
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "RackEmApp API V1");
});
And this is taken from the ConfigureServices method in Startup.cs
services.AddSwaggerGen(c =>
{
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
c.SwaggerDoc("v1", new OpenApiInfo
{
Version = "v1",
Title = "RackEmApp API",
Description = "A Web API for developers to interact with the RackEmApp dataset for a given league/organization. This is in development and has limited support.",
});
});
答案1
得分: 1
通过试错删除我的控制器,我确定问题出在我在控制器上添加了这个注解:
[ApiExplorerSettings(IgnoreApi = true)]
而在同一个控制器中的一个操作中,我有这个:
[ApiExplorerSettings(IgnoreApi = false)]
显然,这让Swagger陷入了一个无限循环。从操作中移除它解决了这个问题。
英文:
Through a trial and error of deleting my controllers I identified that the issue was that I had this annotation on the Controller
[ApiExplorerSettings(IgnoreApi = true)]
And in an action within that same controller I had this
[ApiExplorerSettings(IgnoreApi = false)]
This obviously sent swagger into an endless loop. Removing it from the action fixed it.
答案2
得分: 0
app.UseSwagger(c =>
{
c.RouteTemplate = "/swagger/{documentName}/swagger.json";
});
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API"));
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "API");
c.RoutePrefix = "swagger";
});
英文:
app.UseSwagger(c =>
{
c.RouteTemplate = "/swagger/{documentName}/swagger.json";
});
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API"));
app.UseSwaggerUI(c => {
c.SwaggerEndpoint("/swagger/v1/swagger.json", "API");
c.RoutePrefix = "swagger";
});
答案3
得分: 0
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
options.RoutePrefix = string.Empty;
});
英文:
Try :
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
options.RoutePrefix = string.Empty;
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论