ASP.NET Core 接口参数Example怎么设定

提问

ASP.NET Core 接口参数Example怎么设定

回答

param xml注释增加 example="888"属性

 /// <summary>
 /// 查天气
 /// </summary>
 /// <param name="token">令牌</param>
 /// <param name="id" value="" example="888">参数</param>
 /// <returns example="666">返回值</returns>
 /// <remarks>
 /// 这是一个测试接口
 /// </remarks>
 /// <example>
 /// 这个接口这么要调用
 /// </example>
 [HttpGet("{id}", Name = "GetById")]
 public ActionResult<IEnumerable<WeatherForecast>> Get([FromHeader(Name = "Authorization")]
    [Required]
    string token,
    [FromRoute] int id)
{

    _=new OpenApimdGenerator().ReadYaml().Result;
    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();
}

swagger UI

swagger.json

posted @ 2022-10-09 11:13  喜爱糖葫芦  阅读(56)  评论(0编辑  收藏  举报