SwaggerGeneratorException: неоднозначный метод HTTP для действия — WebApplication5.Controllers.WeatherForecastController.GetWeatherB (WebApplication5). Для действий требуется явная привязка HttpMethod для Swagger/OpenAPI 3.0.
Это пример API из VS 2022.
Код: Выделить всё
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger _logger;
public WeatherForecastController(ILogger logger)
{
_logger = logger;
}
[HttpGet(Name = "TestB")]
[Route("/TestRouteB")]
public IEnumerable GetWeatherB([FromQuery] QueryParameters queryParam)
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
[HttpGet(Name = "TestA")]
[Route("/TestRouteA")]
public IEnumerable GetWeatherA([FromQuery] QueryParameters queryParam)
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
Подробнее здесь: https://stackoverflow.com/questions/761 ... en-the-nam