简体   繁体   中英

Swashbuckle/Swagger .NET Core Dictionary<int, MyModel>

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM