Skip to content

Commit 172212d

Browse files
committed
feat: embedded swagger-ui, fixes #21
Adds an embedded swagger-ui using gin-swagger at `/swagger/index.html` Files under `docs` are generated using ``` swag init -g internal/api/api.go -d ./,./internal/api ``` Signed-off-by: Chris Gianelloni <[email protected]>
1 parent d411e0f commit 172212d

File tree

6 files changed

+317
-5
lines changed

6 files changed

+317
-5
lines changed

docs/docs.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Package docs GENERATED BY SWAG; DO NOT EDIT
2+
// This file was generated by swaggo/swag
3+
package docs
4+
5+
import "github.com/swaggo/swag"
6+
7+
const docTemplate = `{
8+
"schemes": {{ marshal .Schemes }},
9+
"swagger": "2.0",
10+
"info": {
11+
"description": "{{escape .Description}}",
12+
"title": "{{.Title}}",
13+
"contact": {
14+
"name": "CloudStruct",
15+
"url": "https://cloudstruct.net",
16+
"email": "[email protected]"
17+
},
18+
"license": {
19+
"name": "Apache 2.0",
20+
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
21+
},
22+
"version": "{{.Version}}"
23+
},
24+
"host": "{{.Host}}",
25+
"basePath": "{{.BasePath}}",
26+
"paths": {
27+
"/api/submit/tx": {
28+
"post": {
29+
"description": "Submit an already serialized transaction to the network.",
30+
"produces": [
31+
"application/json"
32+
],
33+
"summary": "Submit Tx",
34+
"parameters": [
35+
{
36+
"enum": [
37+
"application/cbor"
38+
],
39+
"type": "string",
40+
"description": "Content type",
41+
"name": "Content-Type",
42+
"in": "header",
43+
"required": true
44+
}
45+
],
46+
"responses": {
47+
"202": {
48+
"description": "Ok",
49+
"schema": {
50+
"type": "string"
51+
}
52+
},
53+
"400": {
54+
"description": "Bad Request",
55+
"schema": {
56+
"type": "string"
57+
}
58+
},
59+
"500": {
60+
"description": "Server Error",
61+
"schema": {
62+
"type": "string"
63+
}
64+
}
65+
}
66+
}
67+
}
68+
}
69+
}`
70+
71+
// SwaggerInfo holds exported Swagger Info so clients can modify it
72+
var SwaggerInfo = &swag.Spec{
73+
Version: "3.1.0",
74+
Host: "localhost:8090",
75+
BasePath: "/",
76+
Schemes: []string{"http"},
77+
Title: "go-cardano-submit-api",
78+
Description: "Cardano Submit API",
79+
InfoInstanceName: "swagger",
80+
SwaggerTemplate: docTemplate,
81+
}
82+
83+
func init() {
84+
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
85+
}

docs/swagger.json

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"schemes": [
3+
"http"
4+
],
5+
"swagger": "2.0",
6+
"info": {
7+
"description": "Cardano Submit API",
8+
"title": "go-cardano-submit-api",
9+
"contact": {
10+
"name": "CloudStruct",
11+
"url": "https://cloudstruct.net",
12+
"email": "[email protected]"
13+
},
14+
"license": {
15+
"name": "Apache 2.0",
16+
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
17+
},
18+
"version": "3.1.0"
19+
},
20+
"host": "localhost:8090",
21+
"basePath": "/",
22+
"paths": {
23+
"/api/submit/tx": {
24+
"post": {
25+
"description": "Submit an already serialized transaction to the network.",
26+
"produces": [
27+
"application/json"
28+
],
29+
"summary": "Submit Tx",
30+
"parameters": [
31+
{
32+
"enum": [
33+
"application/cbor"
34+
],
35+
"type": "string",
36+
"description": "Content type",
37+
"name": "Content-Type",
38+
"in": "header",
39+
"required": true
40+
}
41+
],
42+
"responses": {
43+
"202": {
44+
"description": "Ok",
45+
"schema": {
46+
"type": "string"
47+
}
48+
},
49+
"400": {
50+
"description": "Bad Request",
51+
"schema": {
52+
"type": "string"
53+
}
54+
},
55+
"500": {
56+
"description": "Server Error",
57+
"schema": {
58+
"type": "string"
59+
}
60+
}
61+
}
62+
}
63+
}
64+
}
65+
}

docs/swagger.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
basePath: /
2+
host: localhost:8090
3+
info:
4+
contact:
5+
6+
name: CloudStruct
7+
url: https://cloudstruct.net
8+
description: Cardano Submit API
9+
license:
10+
name: Apache 2.0
11+
url: http://www.apache.org/licenses/LICENSE-2.0.html
12+
title: go-cardano-submit-api
13+
version: 3.1.0
14+
paths:
15+
/api/submit/tx:
16+
post:
17+
description: Submit an already serialized transaction to the network.
18+
parameters:
19+
- description: Content type
20+
enum:
21+
- application/cbor
22+
in: header
23+
name: Content-Type
24+
required: true
25+
type: string
26+
produces:
27+
- application/json
28+
responses:
29+
"202":
30+
description: Ok
31+
schema:
32+
type: string
33+
"400":
34+
description: Bad Request
35+
schema:
36+
type: string
37+
"500":
38+
description: Server Error
39+
schema:
40+
type: string
41+
summary: Submit Tx
42+
schemes:
43+
- http
44+
swagger: "2.0"

go.mod

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,32 @@ require (
99
github.com/gin-gonic/gin v1.7.7
1010
github.com/kelseyhightower/envconfig v1.4.0
1111
github.com/penglongli/gin-metrics v0.1.10
12+
github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2
13+
github.com/swaggo/gin-swagger v1.4.3
14+
github.com/swaggo/swag v1.8.1
1215
go.uber.org/zap v1.21.0
1316
golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838
1417
gopkg.in/yaml.v2 v2.4.0
1518
)
1619

1720
require (
21+
github.com/KyleBanks/depth v1.2.1 // indirect
1822
github.com/beorn7/perks v1.0.1 // indirect
1923
github.com/bits-and-blooms/bitset v1.2.0 // indirect
2024
github.com/cespare/xxhash/v2 v2.1.2 // indirect
2125
github.com/gin-contrib/sse v0.1.0 // indirect
26+
github.com/go-openapi/jsonpointer v0.19.5 // indirect
27+
github.com/go-openapi/jsonreference v0.20.0 // indirect
28+
github.com/go-openapi/spec v0.20.6 // indirect
29+
github.com/go-openapi/swag v0.21.1 // indirect
2230
github.com/go-playground/locales v0.13.0 // indirect
2331
github.com/go-playground/universal-translator v0.17.0 // indirect
2432
github.com/go-playground/validator/v10 v10.4.1 // indirect
2533
github.com/golang/protobuf v1.5.2 // indirect
34+
github.com/josharian/intern v1.0.0 // indirect
2635
github.com/json-iterator/go v1.1.12 // indirect
2736
github.com/leodido/go-urn v1.2.0 // indirect
37+
github.com/mailru/easyjson v0.7.7 // indirect
2838
github.com/mattn/go-isatty v0.0.12 // indirect
2939
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
3040
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
@@ -38,6 +48,8 @@ require (
3848
github.com/x448/float16 v0.8.4 // indirect
3949
go.uber.org/atomic v1.7.0 // indirect
4050
go.uber.org/multierr v1.6.0 // indirect
41-
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
51+
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
52+
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect
53+
golang.org/x/tools v0.1.10 // indirect
4254
google.golang.org/protobuf v1.26.0 // indirect
4355
)

0 commit comments

Comments
 (0)