-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NetCore 2.2 - Health Check Support #1058
Comments
Swashbuckle is built on top of If health-checks endpoints aren't surfaced by that, then they won't be surfaced by Swashbuckle. This is a fundamental aspect to the SB design and is unlikely to change anytime soon. IMO, this sounds like a perfect candidate for a community add-on package (see https://github.com/domaindrivendev/Swashbuckle.AspNetCore#community-packages). If there was a willing contributor, they could start a new project called |
For those interested in this, you can expose a pass-through API endpoint based on [Route("api/v1/health")]
public class HealthController : Controller
{
private readonly HealthCheckService _healthCheckService;
public HealthController(HealthCheckService healthCheckService)
{
_healthCheckService = healthCheckService;
}
/// <summary>
/// Get Health
/// </summary>
/// <remarks>Provides an indication about the health of the API</remarks>
[HttpGet]
[ProducesResponseType(typeof(HealthReport), (int)HttpStatusCode.OK)]
[SwaggerOperation(OperationId = "Health_Get")]
[SwaggerResponse((int)HttpStatusCode.OK, Description = "API is healthy")]
[SwaggerResponse((int)HttpStatusCode.ServiceUnavailable, Description = "API is not healthy")]
public async Task<IActionResult> Get()
{
var report = await _healthCheckService.CheckHealthAsync();
return report.Status == HealthStatus.Healthy ? Ok(report) : StatusCode((int)HttpStatusCode.ServiceUnavailable, report);
}
} |
I took a similar approach to @tomkerkhove, but since I wanted to retain the ability to customize the response using the HealthCheckOptions.ResponseWriter and use the ActionResult pattern, I created a HealthCheckActionResult
And then in my controller,
|
@tomkerkhove which version of Swashbuckle.AspNetCore are you running on? I am using your same approach, but I get a lot of errors resolving the response type. ` ``
and the UI reports Any clue? |
I'm using a variety of versions, which one are you using? Keep in mind that 5.x uses new serializer and might be due to that. |
@tomkerkhove I am running on 5.0.0, so I guess the serialiser might be an issue then. |
@tomkerkhove upgrading to 5.4.0 did the trick. However the example makes no sense, even though the model is correct. Not a big deal anyway. Thanks. |
Happy to help! |
@say25 (and others) can this be closed or is there still an outstanding issue? |
I mean I think to some extent we can close but I do think it would be cool if these HealthChecks were exposed in ApiExplorer but I think dotnet/aspnetcore#18153 covers it. |
I have created a package Swashbuckle.AspNetCore.HealthChecks that provides this functionality, although with a different interface from the one proposed. Currently in alpha although it's been running successfully for quite a while in a couple of my projects. The repo contains samples and documentation. Feedback welcome, please raise an issue in that repo if you would like to see a particular feature or have any other comments or questions. @domaindrivendev I took the liberty of calling it |
Feature Request
Support for NetCore 2.2 Health Checks
Description
I have health checks set up using the new NetCore 2.2 health checks yet they do not show in Swagger UI. Can we add support for this to
Swashbuckle.AspNetCore
?The text was updated successfully, but these errors were encountered: