我有下面的控制器(测试目的,它不遵循REST与2个GET):
[ApiController]
[Route("api/[controller]")]
public class WeatherForecastController : ControllerBase
{
private readonly ILogger<WeatherForecastController> _logger;
private readonly IWeatherService _weatherService;
public WeatherForecastController(ILogger<WeatherForecastController> logger, IWeatherService weatherService)
{
_logger = logger;
_weatherService = weatherService;
}
[HttpGet(Name = "GetWeatherSummary")]
[Route("getweatherforecast")]
public IEnumerable<WeatherForecast> Get()
{
return _weatherService.GetWeatherSummary();
}
[HttpGet(Name = "Error")]
[Route("error")]
public Task<IActionResult> Error()
{
throw new Exception("some error message");
}
}
我有两个GET方法,都没有任何参数。我尝试为每个方法添加一个Route和Name,但Swagger仍然显示错误:
异常错误:冲突的方法/路径组合“GET api/WeatherForecast”
我可以在 Postman 中使用以下两种方法:
天气预报网站
天气预报错误
swagger是否不允许这样做,因为它们都是GET,并且都不带任何参数,所以无法区分它们?名称或路由不够?
1条答案
按热度按时间jljoyd4f1#
你可以试试
或者