Skip to content

Commit

Permalink
fix: health swagger errors (#685)
Browse files Browse the repository at this point in the history
  • Loading branch information
alnr authored Apr 12, 2023
1 parent 44c4287 commit 2fa6e92
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
11 changes: 10 additions & 1 deletion healthx/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,11 @@ func (h *Handler) SetVersionRoutes(r router, opts ...Options) {
//
// Produces:
// - application/json
// - text/plain
//
// Responses:
// 200: healthStatus
// 500: genericError
// default: unexpectedError
func (h *Handler) Alive() http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
h.H.Write(rw, r, &swaggerHealthStatus{
Expand All @@ -132,6 +133,12 @@ func (h *Handler) Alive() http.Handler {
})
}

// swagger:model unexpectedError
//
//nolint:deadcode,unused
//lint:ignore U1000 Used to generate Swagger and OpenAPI definitions
type unexpectedError string

// Ready returns an ok status if the instance is ready to handle HTTP requests and all ReadyCheckers are ok.
//
// swagger:route GET /health/ready health isInstanceReady
Expand All @@ -149,10 +156,12 @@ func (h *Handler) Alive() http.Handler {
//
// Produces:
// - application/json
// - text/plain
//
// Responses:
// 200: healthStatus
// 503: healthNotReadyStatus
// default: unexpectedError
func (h *Handler) Ready(shareErrors bool) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
var notReady = swaggerNotReadyStatus{
Expand Down
4 changes: 2 additions & 2 deletions healthx/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package healthx
import (
"encoding/json"
"errors"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -67,7 +67,7 @@ func TestHealth(t *testing.T) {
response, err := c.Get(endpoint)
require.NoError(t, err)
require.EqualValues(t, http.StatusServiceUnavailable, response.StatusCode)
out, err := ioutil.ReadAll(response.Body)
out, err := io.ReadAll(response.Body)
require.NoError(t, err)
assert.Equal(t, "{\"error\":{\"code\":500,\"status\":\"Internal Server Error\",\"message\":\"not alive\"}}", strings.TrimSpace(string(out)))
return response
Expand Down
18 changes: 12 additions & 6 deletions healthx/openapi/patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
status:
description: Always "ok".
type: string
description: {{.ProjectHumanName}} is ready to accept connections.
'500':
description: '{{.ProjectHumanName}} is ready to accept connections.'
default:
content:
application/json:
text/plain:
schema:
"$ref": "#/components/schemas/genericError"
description: genericError
type: string
description: Unexpected error
summary: Check HTTP Server Status
tags: {{ .HealthPathTags | toJson }}
- op: replace
Expand Down Expand Up @@ -59,7 +59,7 @@
status:
description: Always "ok".
type: string
description: {{.ProjectHumanName}} is ready to accept requests.
description: '{{.ProjectHumanName}} is ready to accept requests.'
'503':
content:
application/json:
Expand All @@ -74,6 +74,12 @@
type: object
type: object
description: Ory Kratos is not yet ready to accept requests.
default:
content:
text/plain:
schema:
type: string
description: Unexpected error
summary: Check HTTP Server and Database Status
tags: {{ .HealthPathTags | toJson }}
- op: replace
Expand Down

0 comments on commit 2fa6e92

Please sign in to comment.