Swashbuckle.AspNetCore: Doesn't generate summary doc when the controller class has overload methods.

Swashbuckle.AspNetCore 6.5.0 .net 7.0

Project.csproj

        <GenerateDocumentationFile>true</GenerateDocumentationFile>

Controller class:

[ApiController]
[Route("api/[controller]")]
public class MyController : MyBaseController<MyModel>
{
    public MyController(MyBuzService service):base(service){}
   
    /// <summary>
    /// Find by single id
    /// </summary>
    /// <param name="id">ID</param>
    /// <returns></returns>
    [HttpGet]
    [Route("Find/{id}")]
   public async Task<IActionResult> Find([FromRoute] string id) => await Find(new[] { id });

    /// <summary>
    /// Find by multi id
    /// </summary>
    /// <param name="id">ID</param>
    /// <returns></returns>
    [HttpPost]
    [Route("Find")]
   public async Task<IActionResult> Find([FromQuery] [FromBody] string[] id)
   {
        return Ok(await Service.GetModelAsync(id));
   }
}

public abstract class MyBaseController<TModel>
{
    private MyBuzService Service;
    public MyController(MyBuzService service)
   {
        Service = service;
   }
   

    /// <summary>
    /// Add some models
    /// </summary>
    /// <param name="models">Models to add</param>
    /// <returns></returns>
   [HttpPost]
    [Route("AddRange")]
   public async Task<IActionResult> AddRange([FromBody] TModel[] models)
   {
       return Ok(await Service.AddRange(models));
   }
}

I’ve checked the generated XML documentation file, it’s generated correctly. But summary document are missing in the swagger.json. I’ve created a class that implements IOperationFilter interface, when I’m debugging, I found OpenApiOperation.Summary property with value null.

update issue: The method public async Task<IActionResult> AddRange([FromBody] TModel[] models) takes one parameter of TModel[] type which is array type doesn’t generate summary doc too!.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 15 (4 by maintainers)

Most upvoted comments

Thank you, this worked!

You can test it now with 6.7.1 package

It should be fixed on MyGet latest version @codelovercc could you test it and if it’s working close the issue? Thanks

I am reviewing this issue 😃

Thanks, I will check

@Havunen Thank you for your work. There still is a problem with overloaded method in this case:


public abstract class BaseModelController<TKey, TModel> : Controller
{
     /// <summary>
    /// Delete by Id
    /// </summary>
    /// <param name="id">deleting Id</param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    /// <response code="200">Deleted</response>
    /// <response code="404">Failed</response>
    [HttpDelete($"{nameof(Delete)}/{{{nameof(id)}}}")]
    [ProducesResponseType(typeof(SuccessResponse), StatusCodes.Status200OK)]
    [ProducesResponseType(typeof(NotFoundResponse), StatusCodes.Status404NotFound)]
    public virtual async Task<IActionResult> Delete([Required, FromRoute] TKey id, CancellationToken cancellationToken)
    {
        return Ok();
    }
   
    
     /// <summary>
    /// Delete by Ids
    /// </summary>
    /// <param name="ids">deleting Ids</param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    /// <response code="200">Deleted</response>
    /// <response code="404">Failed</response>
    [HttpDelete(nameof(Delete))]
    [ProducesResponseType(typeof(SuccessResponse<int>), StatusCodes.Status200OK)]
    [ProducesResponseType(typeof(NotFoundResponse), StatusCodes.Status404NotFound)]
    public virtual async Task<IActionResult> Delete([Required, FromBody] TKey[] ids, CancellationToken cancellationToken)
    {
        return Ok(new SuccessResponse<int>(10));
    }
 
     /// <summary>
    /// List all of <typeparamref name="TModel" />
    /// </summary>
    public virtual async Task<IActionResult> List()
    {
        return Ok();
    }
}

[ApiController]
[Route("[controller]")]
public ArticleController : BaseModelController<Guid, Article>
{
    
}

XML documents file generated will. Method List with full documented in swagger, but method Delete([Required, FromRoute] TKey id, CancellationToken cancellationToken) and Delete([Required, FromBody] TKey[] ids, CancellationToken cancellationToken) lost all of xml comment docs in swagger.

FYI. This is supported in DotSwashbuckle image