I have a asp.net core project with uses swashbuckle for JS-client generation. To use pagination we use PagedList from X.PagedList nuget. Controller implementation:
[HttpGet]
[ProducesResponseType(typeof(IPagedList<Model>), 200)]
[ProducesResponseType(typeof(void), 500)]
public async Task<IActionResult> Get([FromQuery]query)
{
var response = await this.mediator.Send(query);
return Ok(response.Results); // results is IPagedList<Model>
}
the result in JSON looks like this:
{
"count": 10,
"pageCount": 2,
"totalItemCount": 15,
"pageNumber": 1,
"pageSize": 10,
"hasPreviousPage": false,
"hasNextPage": true,
"isFirstPage": true,
"isLastPage": false,
"firstItemOnPage": 1,
"lastItemOnPage": 10,
"items": [
{
"guid": "dafa9d3b-9ee2-4cbc-b7d7-902b5bc9e887",
"name": "asdf",
"number": 1006,
}
]
}
but somehow swagger thinks the result looks like Array of Model:
[
{
"guid": "string",
"name": "string",
"number": 0,
}
]
I also tried with
[SwaggerResponse(200, Type = typeof(IPagedList<Model>))]
without success.
XPagedList 7.1.0 Swashbuckle.AspNetCore.Swagger 1.0.0
Is there a way I can overwrite the output? it makes client code generation useless if the code is wrong!
EDIT: There is a custom JsonConverter for PagedList
services.AddMvc().AddControllersAsServices().AddJsonOptions(options =>
{
options.SerializerSettings.NullValueHandling = NullValueHandling.Include;
options.SerializerSettings.Converters.Add(new CustomIEnumerableConverter(new[] {"X.PagedList"}));
});
But as I understand Swashbuckle should use the same JsonSerializer.