好吧,我有一个控制器和两个功能,但是当我尝试在URL中大摇大摆时,我无法加载json文件,但我认为它与多个动作相同是相同的
产生错误
获取错误内部服务器错误/swagger/v1/swagger.json
我尝试了另一行提出的建议
c.ResolveConflictingActions(apiDescriptions =>apiDescriptions.First());
但是那把方法从招摇的文档视图中隐藏了起来,所以一个人将如何对其进行测试。我在控制器中做错了吗?
public class BmiInformationsController : ControllerBase
{
private readonly AppManagerDBContext _context;
public BmiInformationsController(AppManagerDBContext context)
{
_context = context;
}
[HttpGet]
public async Task<ActionResult<IEnumerable<BmiInformation>>> GetBmiInformation() {
return await _context.BmiInformation.ToListAsync();
}
// GET: api/BmiInformations
[HttpGet]
public async Task<ActionResult<IEnumerable<BmiInformation>>> GetBmiInformationByUserId(string id)
{
return await _context.BmiInformation.Where(w => w.TennentId == new Guid(id)).ToListAsync();
}
}
这是配置我的大摇大摆的方式
services.AddSwaggerGen(c => {
c.SwaggerDoc("v1", new OpenApiInfo { Title = "App Manager - Running Buddies", Version = "v1" });
c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme {
Description = "JWT Authorization header using the Bearer scheme.",
Name = "Authorization",
In = ParameterLocation.Header,
Type = SecuritySchemeType.Http,
Scheme = "bearer",
BearerFormat = "JWT"
});
我的启动文件中的我的路线。
app.UseEndpoints(endpoints => {
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapRazorPages();
});
在控制器方法上方放置显式[Route]
-属性,如下所示: