I am using swagger ui and I have action like this in my controller:
[HttpGet("{id}")]
[AllowAnonymous]
[ProducesResponseType(typeof(PublicDto), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(PrivateDto), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(string), StatusCodes.Status403Forbidden)]
[ProducesResponseType(typeof(string), StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetUser(string id)
{
try
{
...
if (...)
{
var dto = _mapper.Map<PrivateDto>(user);
return Ok(dto);
}
else
{
var dto = _mapper.Map<PublicDto>(user);
return Ok(dto);
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error inside action");
return StatusCode(500, "Internal server error");
}
}
The problem is that on my swagger UI page I can see only one of them in Responses area, and got scheme for only one. Is there a way to have more than one objects for response for one status code?