在ASPNET Core 2.1中生成Swashbuckle实施说明

时间:2018-08-20 11:03:19

标签: c# asp.net-core swagger swagger-ui swashbuckle

我正在使用Swashbuckle生成详尽的文档。不幸的是,根据所附图片,我找不到如何添加实施说明。

This is a sample picture of swagger generated documentation

贝洛摘录自我的代码,以生成一些标签。

/// <summary>
    /// User login for given application
    /// </summary>
    /// <description>
    /// Test description
    /// </description>
    /// <remarks>
    /// Sample request:
    /// 
    ///     POST /login
    ///     {
    ///         "email": "jon@nighwatch.com",
    ///         "password": "jonLov3sDaenarys"
    ///         "productId": "5e7en-k1ngd0m5"
    ///     }
    ///     
    /// </remarks>
    /// <param name="model">Login model</param>
    /// <returns>JWT Token</returns>
    /// <response code="200">Returns the newly created auth response, containing token with user information</response>
    /// <response code="400">If the request is invalid or productId doesn't exist</response>
    /// <response code="403">If the account is locked out or role is inactive</response>
    [HttpPost]
    [Produces("application/json")]
    [Consumes("application/json")]
    [ProducesResponseType(typeof(AuthResponseModel), 200)]
    [ProducesResponseType(400)]
    [ProducesResponseType(403)]
    [Route("login")]
    public async Task<IActionResult> Login([FromBody]LoginModel model)
    {
        if (ModelState.IsValid)
        {

知道我在做什么错吗?

谢谢

2 个答案:

答案 0 :(得分:1)

您必须生成XML文档文件。

项目属性> 构建> 输出 =>选中XML Documentation file。示例:bin\netcoreapp2.1\MyProject.xml

ConfigureServices的{​​{1}}中,包含生成的文件:

services.AddSwaggerGen(...)

如果这两件事到位,则xml注释应包含在文档中。

答案 1 :(得分:0)

您错过了招摇的属性吗?

    [SwaggerOperation("Get_Whatever")]
    [SwaggerResponse(StatusCodes.Status200OK, typeof(List<string>), "An array of strings.")]
    [SwaggerResponse(StatusCodes.Status403Forbidden, null, "Forbidden")]
    public async Task<IActionResult> Login([FromBody]LoginModel model){