NSwag
NSwag copied to clipboard
Multiple [ProducesResponseType] no longer produce multiple schemas since v11.20
I've noticed that since v11.20, I've had a regression in one of my projects:
Using multiple [ProducesResponseType]
attributes does no longer produce multiple schemas. While upgrading to 11.20, I've also replaced UseSwaggerUi3(Assembly ...)
with UseSwaggerUi3WithApiExplorer()
, so this might be related.
The documentation does not mention a difference between the ASP.NET Core built-in attribute and the NSwag.Annotations.SwaggerResponseAttribute
, though it works fine with the NSwag one.
To give you a bit of context, this gist contains some more example code: https://gist.github.com/GeorgDangl/acecc279b2cbf7f366a6487eb50d3833
The following controller definition:
[HttpGet("")]
[LightQuery]
[Authorize(Policy = DanglIdentityConstants.Authorization.AUTHENTICATION_CONNECTOR_OR_ADMIN_POLICY_NAME)]
[ProducesResponseType(typeof(PaginationResult<ClientGet>), 200)]
[ProducesResponseType(typeof(ClientGet), 200)]
public IActionResult GetAllClients(string filter = null)
{
var clientsQuery = _identityServerClientsRepository.GetAllClients()
.ProjectTo<ClientGet>();
if (!string.IsNullOrWhiteSpace(filter))
{
clientsQuery = clientsQuery.Where(c => c.ClientName.Contains(filter) || c.ClientUri.Contains(filter));
}
return Ok(clientsQuery);
}
produces this wrong (shortened) Swagger document:
{
"operationId": "Clients_GetAllClients",
"responses": {
"200": {
"x-nullable": true,
"description": "",
"schema": {
"$ref": "#/definitions/PaginationResultOfClientGet"
}
}
}
}
When I switch to the NSwag.Annotations.SwaggerResponseAttribute
, it is generated correctly:
{
"operationId": "Clients_GetAllClients",
"responses": {
"200": {
"x-nullable": true,
"description": "",
"schema": {},
"x-expectedSchemas": [
{
"description": "",
"schema": {
"$ref": "#/definitions/PaginationResultOfClientGet"
}
},
{
"description": "",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/ClientGet"
}
}
}
]
}
}
}
I've summed it up in a blog post. The error is not critical, since it's easy to just replace the ASP.NET Core attribute with the one from NSwag, but I didn't find anything in the code / wiki / issues pointing to this (whether it's intentional or already reported).
I'd be happy to help and take a deeper look if you could guide me a bit about where in the code I would start. Thank you for the great work with NSwag!