Skip to content

Commit 56dddec

Browse files
swagger docs
1 parent d7d743d commit 56dddec

File tree

6 files changed

+57
-8
lines changed

6 files changed

+57
-8
lines changed

gin-web-app/docs/docs.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@ const docTemplate = `{
99
"info": {
1010
"description": "{{escape .Description}}",
1111
"title": "{{.Title}}",
12-
"contact": {},
12+
"termsOfService": "https://tos.santoshk.dev",
13+
"contact": {
14+
"name": "Santosh Kumar",
15+
"url": "https://twitter.com/sntshk",
16+
"email": "[email protected]"
17+
},
18+
"license": {
19+
"name": "Apache 2.0",
20+
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
21+
},
1322
"version": "{{.Version}}"
1423
},
1524
"host": "{{.Host}}",
@@ -19,12 +28,12 @@ const docTemplate = `{
1928

2029
// SwaggerInfo holds exported Swagger Info so clients can modify it
2130
var SwaggerInfo = &swag.Spec{
22-
Version: "",
23-
Host: "",
31+
Version: "1.0",
32+
Host: "localhost:3001",
2433
BasePath: "",
2534
Schemes: []string{},
26-
Title: "",
27-
Description: "",
35+
Title: "Gin Book Service",
36+
Description: "A book management service API in Go using Gin framework.",
2837
InfoInstanceName: "swagger",
2938
SwaggerTemplate: docTemplate,
3039
LeftDelim: "{{",

gin-web-app/docs/swagger.json

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
{
22
"swagger": "2.0",
33
"info": {
4-
"contact": {}
4+
"description": "A book management service API in Go using Gin framework.",
5+
"title": "Gin Book Service",
6+
"termsOfService": "https://tos.santoshk.dev",
7+
"contact": {
8+
"name": "Santosh Kumar",
9+
"url": "https://twitter.com/sntshk",
10+
"email": "[email protected]"
11+
},
12+
"license": {
13+
"name": "Apache 2.0",
14+
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
15+
},
16+
"version": "1.0"
517
},
18+
"host": "localhost:3001",
619
"paths": {}
720
}

gin-web-app/docs/swagger.yaml

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1+
host: localhost:3001
12
info:
2-
contact: {}
3+
contact:
4+
5+
name: Santosh Kumar
6+
url: https://twitter.com/sntshk
7+
description: A book management service API in Go using Gin framework.
8+
license:
9+
name: Apache 2.0
10+
url: http://www.apache.org/licenses/LICENSE-2.0.html
11+
termsOfService: https://tos.santoshk.dev
12+
title: Gin Book Service
13+
version: "1.0"
314
paths: {}
415
swagger: "2.0"

gin-web-app/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ require (
1919
github.com/go-openapi/swag v0.22.7 // indirect
2020
github.com/go-playground/locales v0.14.1 // indirect
2121
github.com/go-playground/universal-translator v0.18.1 // indirect
22-
github.com/go-playground/validator/v10 v10.16.0 // indirect
22+
github.com/go-playground/validator/v10 v10.17.0 // indirect
2323
github.com/goccy/go-json v0.10.2 // indirect
2424
github.com/josharian/intern v1.0.0 // indirect
2525
github.com/json-iterator/go v1.1.12 // indirect

gin-web-app/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
3939
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
4040
github.com/go-playground/validator/v10 v10.16.0 h1:x+plE831WK4vaKHO/jpgUGsvLKIqRRkz6M78GuJAfGE=
4141
github.com/go-playground/validator/v10 v10.16.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
42+
github.com/go-playground/validator/v10 v10.17.0 h1:SmVVlfAOtlZncTxRuinDPomC2DkXJ4E5T9gDA0AIH74=
43+
github.com/go-playground/validator/v10 v10.17.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
4244
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
4345
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
4446
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=

gin-web-app/main.go

+14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ import (
88
ginSwagger "github.com/swaggo/gin-swagger"
99
)
1010

11+
// @title Gin Book Service
12+
// @version 1.0
13+
// @description A book management service API in Go using Gin framework.
14+
// @termsOfService https://tos.santoshk.dev
15+
16+
// @contact.name Santosh Kumar
17+
// @contact.url https://twitter.com/sntshk
18+
// @contact.email [email protected]
19+
20+
// @license.name Apache 2.0
21+
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
22+
23+
// @host localhost:3001
1124
func main() {
1225

1326
router := gin.Default()
@@ -20,6 +33,7 @@ func main() {
2033
router.GET("/user", getUsers)
2134
router.POST("/user", addUser)
2235
router.GET("/userData/:id", getUserByID)
36+
2337
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
2438

2539
router.Run(":3001")

0 commit comments

Comments
 (0)