Skip to content

Commit f3a18e2

Browse files
authored
Merge pull request #24 from communitybridge/fixDocs
update docs and fix swagger importation issue
2 parents 0fccc08 + 11e4d51 commit f3a18e2

File tree

4 files changed

+58
-5
lines changed

4 files changed

+58
-5
lines changed

health/doc.go

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package health
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/go-openapi/runtime"
7+
)
8+
9+
// GetDocOKCode is the HTTP code returned for type GetDocOK
10+
const GetDocOKCode int = 200
11+
12+
// GetDocOK Success
13+
type GetDocOK struct {
14+
}
15+
16+
// NewGetDocOK creates GetDocOK with default headers values
17+
func NewGetDocOK() *GetDocOK {
18+
return &GetDocOK{}
19+
}
20+
21+
// WriteResponse to the client
22+
func (o *GetDocOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
23+
html := `<!DOCTYPE html>
24+
<html>
25+
<head>
26+
<title>Organization Service ReDoc</title>
27+
<!-- needed for adaptive design -->
28+
<meta charset="utf-8"/>
29+
<meta name="viewport" content="width=device-width, initial-scale=1">
30+
<link rel="shortcut icon" href="https://www.linuxfoundation.org/wp-content/uploads/2017/08/favicon.png">
31+
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">
32+
33+
<!--
34+
ReDoc doesn't change outer page styles
35+
-->
36+
<style>
37+
body {
38+
margin: 0;
39+
padding: 0;
40+
}
41+
</style>
42+
</head>
43+
<body>
44+
<redoc spec-url='/cbledger/swagger.json'></redoc>
45+
<script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"></script>
46+
</body>
47+
</html>`
48+
49+
rw.Header().Set("Content-Type", "text/html; charset=utf-8")
50+
rw.WriteHeader(GetDocOKCode)
51+
_, err := rw.Write([]byte(html))
52+
if err != nil {
53+
panic(err)
54+
}
55+
}

health/handlers.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package health
22

33
import (
44
"github.com/communitybridge/ledger/gen/restapi/operations"
5+
"github.com/communitybridge/ledger/gen/restapi/operations/doc"
56
"github.com/communitybridge/ledger/gen/restapi/operations/health"
67
log "github.com/communitybridge/ledger/logging"
78
"github.com/communitybridge/ledger/swagger"
@@ -14,7 +15,7 @@ func Configure(api *operations.LedgerAPI, service Service) {
1415
api.DocGetDocHandler = doc.GetDocHandlerFunc(func(params doc.GetDocParams) middleware.Responder {
1516
return NewGetDocOK()
1617
})
17-
18+
1819
api.HealthGetHealthHandler = health.GetHealthHandlerFunc(func(params health.GetHealthParams) middleware.Responder {
1920
log.Info("entered GetHealthHandler")
2021
result, err := service.GetHealth(params.HTTPRequest.Context())

main.go

-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"github.com/communitybridge/ledger/balance"
99
"github.com/communitybridge/ledger/cmd"
10-
"github.com/communitybridge/ledger/docs"
1110
"github.com/communitybridge/ledger/gen/restapi"
1211
"github.com/communitybridge/ledger/gen/restapi/operations"
1312
"github.com/communitybridge/ledger/health"
@@ -66,8 +65,6 @@ func main() {
6665
}
6766
api := operations.NewLedgerAPI(swaggerSpec)
6867

69-
docs.Configure(api)
70-
7168
// Health setup
7269
healthService := health.New()
7370
health.Configure(api, healthService)

swagger/ledger.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ paths:
3838
200:
3939
description: Success
4040
tags:
41-
- docs
41+
- doc
4242

4343
/balance/{entity_id}:
4444
get:

0 commit comments

Comments
 (0)