Asp.net core 昂首阔步地返回';规范中未定义任何操作';
我正在开发一个.NETCore3.1WebAPI应用程序,我正在关注一段时间 我已经在我的项目中安装了Asp.net core 昂首阔步地返回';规范中未定义任何操作';,asp.net-core,.net-core,swagger,swashbuckle,swashbuckle.aspnetcore,Asp.net Core,.net Core,Swagger,Swashbuckle,Swashbuckle.aspnetcore,我正在开发一个.NETCore3.1WebAPI应用程序,我正在关注一段时间 我已经在我的项目中安装了swashback.AspNetCore-Version 5.5.0,并进行了以下配置: Startup.cs public void ConfigureServices(IServiceCollection services) { services.AddMvc(options => { options.Filters.Add(typeof(DomainE
swashback.AspNetCore-Version 5.5.0
,并进行了以下配置:
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(options =>
{
options.Filters.Add(typeof(DomainExceptionFilter));
options.ModelBinderProviders.Insert(0, new ProviderModelBinder());
});
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Version = "v1",
Title = "Sample .NET Core DDD",
Description = "A .NET Core sample project based on DDD principles",
License = new OpenApiLicense
{
Name = "MIT License",
Url = new Uri("https://opensource.org/licenses/MIT")
}
});
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
services.AddControllers();
}
namespace Sample.Application.Controllers
{
[Route("Api/[controller]")]
[ApiController]
public class UserController : ControllerBase<User, UserEditViewModel, UserListViewModel>
{
private readonly IUserService _userService;
public UserController(IUserService service, IMapper mapper) : base(service, mapper)
{
_userService = service;
}
/// <summary>
/// Login the user in the system
/// </summary>
/// <param name="loginViewModel">Login information</param>
/// <returns>Token</returns>
[HttpPost("Login")]
[AllowAnonymous]
[ProducesResponseType(typeof(UserTokenViewModel), 200)]
public IActionResult Authenticate([FromBody]UserLoginViewModel loginViewModel)
{
// Do something
}
}
}
我在这些方法中有更多的东西,但我在这里只添加了我认为对这个问题有必要的东西
我的控制器是:
UserController.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(options =>
{
options.Filters.Add(typeof(DomainExceptionFilter));
options.ModelBinderProviders.Insert(0, new ProviderModelBinder());
});
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Version = "v1",
Title = "Sample .NET Core DDD",
Description = "A .NET Core sample project based on DDD principles",
License = new OpenApiLicense
{
Name = "MIT License",
Url = new Uri("https://opensource.org/licenses/MIT")
}
});
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
services.AddControllers();
}
namespace Sample.Application.Controllers
{
[Route("Api/[controller]")]
[ApiController]
public class UserController : ControllerBase<User, UserEditViewModel, UserListViewModel>
{
private readonly IUserService _userService;
public UserController(IUserService service, IMapper mapper) : base(service, mapper)
{
_userService = service;
}
/// <summary>
/// Login the user in the system
/// </summary>
/// <param name="loginViewModel">Login information</param>
/// <returns>Token</returns>
[HttpPost("Login")]
[AllowAnonymous]
[ProducesResponseType(typeof(UserTokenViewModel), 200)]
public IActionResult Authenticate([FromBody]UserLoginViewModel loginViewModel)
{
// Do something
}
}
}
我还有其他从基本控制器继承的方法
我做错了什么?有人面临同样的问题吗?我查看了构建中的文件,生成的XML包含了所有信息,但swagger似乎忽略了它