首页 > 编程语言 >ASP.NET Core 接口参数Example怎么设定

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

时间:2022-10-09 11:22:20浏览次数:57  
标签:Core ASP 接口 参数 NET 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

标签:Core,ASP,接口,参数,NET,Example
From: https://www.cnblogs.com/wuhailong/p/16771483.html

相关文章