在aspnet core 2.1中生成Swashbuckle实现笔记

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

http://img3.mukewang.com/61ac62410001fe6011990981.jpg

Bellow 是从我的代码中摘录来生成一些标签的。


/// <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)

        {

知道我做错了什么吗?


紫衣仙女
浏览 200回答 2
2回答

慕田峪7331174

您必须生成 XML 文档文件。项目属性>构建>输出=> 检查XML Documentation file。例子:bin\netcoreapp2.1\MyProject.xml在 中ConfigureServices,您所做的services.AddSwaggerGen(...)包括生成的文件:services.AddSwaggerGen(options =>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MyProject.xml");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; options.IncludeXmlComments(filePath);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });如果这两件事都到位,则应该在文档中包含 xml 注释。

守候你守候我

您是否错过了 swagger 的属性?&nbsp;&nbsp;&nbsp;&nbsp;[SwaggerOperation("Get_Whatever")] &nbsp;&nbsp;&nbsp;&nbsp;[SwaggerResponse(StatusCodes.Status200OK,&nbsp;typeof(List<string>),&nbsp;"An&nbsp;array&nbsp;of&nbsp;strings.")] &nbsp;&nbsp;&nbsp;&nbsp;[SwaggerResponse(StatusCodes.Status403Forbidden,&nbsp;null,&nbsp;"Forbidden")]&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;async&nbsp;Task<IActionResult>&nbsp;Login([FromBody]LoginModel&nbsp;model){
打开App,查看更多内容
随时随地看视频慕课网APP