❔ IHealthCheck and Swagger
Hello. I'm experimenting with the interface
IHealthCheck
in my Web Service.
I used to have a endpoint that would just return 200OK
called /health
, but I discovered that there was a Interface for this, and with many functionalities, so I want to try get it working.
I followed the documentation (https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-7.0) and it kinda works, except Swagger complains a lot.
This is what my Controller looks like (the health check part):
In Program.cs
I have the following code:
When I run the program, I get this message from Swagger: (attached image)11 Replies
This is the Log I get.
If I add a
[HttpGet("/healthz")]
to the Health Check in the Controller, Swagger stops complaining but the behaviour of the endpoint is very weird.It has this huge JSON that I have no clue what it's doing there.
If I try to access the endpoint manually I get this:
Any idea of what is going on?
when you do
(which is responsible for making the json file)
it's possible to change a lot by calling methods on the options. You might be able to exclude these endpoints, or add a default "HttpMethod binding"
this is the direction I would search in, not sure how to completely fix your issue
I think it's complaining that the public method on your controller, does not have a
[HttpGet]
or post or so
you could add a "IActionModelConvention" to the swagger pipeline that looks like:
Not sure if that fixes it (or if the name is a valid property)
Taken from https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/2031#issuecomment-785384452I took your direction and found this https://stackoverflow.com/questions/29701573/how-to-omit-methods-from-swagger-documentation-on-webapi-using-swashbuckle
Stack Overflow
How to omit methods from Swagger documentation on WebAPI using Swas...
I have a C# ASP.NET WebAPI application with API documentation being automatically generated using Swashbuckle. I want to be able to omit certain methods from the documentation but I can't seem to ...
I can add
[ApiExplorerSettings(IgnoreApi = true)]
to the endpoints I want to exclude and everyone is happy I think
Atleast I tested and it behaves as expected
Thank you for your suggestion!Perfect!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.