1
votes

I'm having some issues using Swashbuckle to generate Swagger documentation for an API that returns a custom type containing a property which is a Dictionary whose value is IEnumerable.

public class MyReturnModel
{
    public IDictionary<int, IEnumerable<MyModel>> Data { get; set;}

    public MyReturnModel()
    {
        Data = new Dictionary<int, IEnumerable<MyModel>>();
    }
}

public class MyModel
{
    public int Value { get; set; }
}

If I have an API endpoint like so:

[ProducesResponseType(typeof(MyReturnModel), (int)HttpStatusCode.OK)]
[HttpGet]
public async Task<IActionResult> GetAsync()
{
    var myReturn = await MyReturnModelRepository.GetAsync();
    return Ok(myReturn);
}

The Swagger UI I can see shows the response type like so:

MyReturnModel {
data (inline_model, optional)
}
inline_model {}

How can I get the Swagger gen to generate documentation for the collection and the inner model?

1
What if you put, [ProducesResponseType(typeof(Dictionary<int, IEnumerable<MyModel>>) - Jaliya Udagedara
If I do that (a) it's incorrect, because it returns MyReturnModel which has a member of that type (I have simplified it for the example but MyReturnModel has other members), and (b) it just says the method returns Inline_Model. - MrShoes
Would love to help... _ Do you have a minimal project reproducing this issue ? _ if not, can you create one on GitHub? - Helder Sepulveda
Never mind.. tried to reproduce but it worked... realised my new solution had swashbuckle 2.0.0 and my old had 1.2.0... updated, and it works. - MrShoes

1 Answers

1
votes

The answer was that I was on version 1.2.0 of Swashbuckle. Updating to version 2.0.0 fixed the issue.