Skip to content

Commit 9bd89d0

Browse files
authored
Merge pull request #57 from GaballaGit/main
Add swagger documentation
2 parents 3714dff + 2d0f4c6 commit 9bd89d0

File tree

14 files changed

+647
-19
lines changed

14 files changed

+647
-19
lines changed

cmd/api/main.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import (
1414
"github.com/acmcsufoss/api.acmcsuf.com/internal/db/models"
1515
"github.com/gin-gonic/gin"
1616
_ "modernc.org/sqlite"
17+
18+
"github.com/acmcsufoss/api.acmcsuf.com/docs"
19+
"github.com/swaggo/files"
20+
"github.com/swaggo/gin-swagger"
1721
)
1822

1923
func main() {
@@ -40,6 +44,7 @@ func main() {
4044
eventsService := services.NewEventsService(queries)
4145
announcementService := services.NewAnnouncementService(queries)
4246
router := gin.Default()
47+
4348
router.SetTrustedProxies([]string{
4449
"127.0.0.1/32",
4550
})
@@ -55,6 +60,22 @@ func main() {
5560
log.Fatalf("Failed to start server: %v", err)
5661
}
5762
}()
63+
//Setup swagger
64+
// TODO: Implement swagger documentation
65+
// Info:
66+
docs.SwaggerInfo.Title = "ACM CSUF API"
67+
docs.SwaggerInfo.Description = "This is a documentation of current API avaliable."
68+
docs.SwaggerInfo.Host = "localhost:8080"
69+
docs.SwaggerInfo.BasePath = "/"
70+
docs.SwaggerInfo.Schemes = []string{"http", "https"}
71+
documentation := router.Group("/")
72+
{
73+
eg := documentation.Group("/")
74+
eg.GET("/events_handler")
75+
eg.GET("/announcement_handler")
76+
}
77+
// Gin swagger serves api docs, or something like that
78+
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
5879

5980
<-ctx.Done()
6081
log.Println("Server shut down.")

docs/docs.go

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
// Package docs Code generated by swaggo/swag. DO NOT EDIT
2+
package docs
3+
4+
import "github.com/swaggo/swag"
5+
6+
const docTemplate = `{
7+
"schemes": {{ marshal .Schemes }},
8+
"swagger": "2.0",
9+
"info": {
10+
"description": "{{escape .Description}}",
11+
"title": "{{.Title}}",
12+
"contact": {},
13+
"version": "{{.Version}}"
14+
},
15+
"host": "{{.Host}}",
16+
"basePath": "{{.BasePath}}",
17+
"paths": {
18+
"/announcements": {
19+
"post": {
20+
"description": "Creates a new announcement and generates unique ID",
21+
"consumes": [
22+
"application/json"
23+
],
24+
"produces": [
25+
"application/json"
26+
],
27+
"tags": [
28+
"Announcements"
29+
],
30+
"summary": "Create new Announcement",
31+
"responses": {}
32+
}
33+
},
34+
"/announcements/:id": {
35+
"get": {
36+
"description": "Retrieves a single announcement from the database.",
37+
"consumes": [
38+
"application/json"
39+
],
40+
"produces": [
41+
"application/json"
42+
],
43+
"tags": [
44+
"Announcements"
45+
],
46+
"summary": "Get an announcement by ID",
47+
"parameters": [
48+
{
49+
"type": "string",
50+
"description": "Announcement ID",
51+
"name": "id",
52+
"in": "path",
53+
"required": true
54+
}
55+
],
56+
"responses": {}
57+
}
58+
},
59+
"/events": {
60+
"get": {
61+
"description": "Gets all the events from the event database",
62+
"consumes": [
63+
"application/json"
64+
],
65+
"produces": [
66+
"application/json"
67+
],
68+
"tags": [
69+
"Events"
70+
],
71+
"summary": "Gets all the events",
72+
"responses": {}
73+
},
74+
"post": {
75+
"description": "Retrieves a single event from the database.",
76+
"consumes": [
77+
"application/json"
78+
],
79+
"produces": [
80+
"application/json"
81+
],
82+
"tags": [
83+
"Events"
84+
],
85+
"summary": "Creates a new event and generates new ID",
86+
"responses": {}
87+
}
88+
},
89+
"/events/:id": {
90+
"get": {
91+
"description": "Retrieves a single event from the database.",
92+
"consumes": [
93+
"application/json"
94+
],
95+
"produces": [
96+
"application/json"
97+
],
98+
"tags": [
99+
"Events"
100+
],
101+
"summary": "Get an Event by ID",
102+
"parameters": [
103+
{
104+
"type": "string",
105+
"description": "Event ID",
106+
"name": "id",
107+
"in": "path",
108+
"required": true
109+
}
110+
],
111+
"responses": {}
112+
},
113+
"put": {
114+
"description": "Updates the event of choice in the database",
115+
"consumes": [
116+
"application/json"
117+
],
118+
"produces": [
119+
"application/json"
120+
],
121+
"tags": [
122+
"Events"
123+
],
124+
"summary": "Update the Event of Choice",
125+
"parameters": [
126+
{
127+
"type": "string",
128+
"description": "Event ID",
129+
"name": "id",
130+
"in": "path",
131+
"required": true
132+
}
133+
],
134+
"responses": {}
135+
},
136+
"delete": {
137+
"description": "Delete the event of choice from the database",
138+
"consumes": [
139+
"application/json"
140+
],
141+
"produces": [
142+
"application/json"
143+
],
144+
"tags": [
145+
"Events"
146+
],
147+
"summary": "Deletes the Event of Choice",
148+
"parameters": [
149+
{
150+
"type": "string",
151+
"description": "Event ID",
152+
"name": "id",
153+
"in": "path",
154+
"required": true
155+
}
156+
],
157+
"responses": {}
158+
}
159+
}
160+
}
161+
}`
162+
163+
// SwaggerInfo holds exported Swagger Info so clients can modify it
164+
var SwaggerInfo = &swag.Spec{
165+
Version: "",
166+
Host: "",
167+
BasePath: "",
168+
Schemes: []string{},
169+
Title: "",
170+
Description: "",
171+
InfoInstanceName: "swagger",
172+
SwaggerTemplate: docTemplate,
173+
LeftDelim: "{{",
174+
RightDelim: "}}",
175+
}
176+
177+
func init() {
178+
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
179+
}

docs/swagger.json

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"contact": {}
5+
},
6+
"paths": {
7+
"/announcements": {
8+
"post": {
9+
"description": "Creates a new announcement and generates unique ID",
10+
"consumes": [
11+
"application/json"
12+
],
13+
"produces": [
14+
"application/json"
15+
],
16+
"tags": [
17+
"Announcements"
18+
],
19+
"summary": "Create new Announcement",
20+
"responses": {}
21+
}
22+
},
23+
"/announcements/:id": {
24+
"get": {
25+
"description": "Retrieves a single announcement from the database.",
26+
"consumes": [
27+
"application/json"
28+
],
29+
"produces": [
30+
"application/json"
31+
],
32+
"tags": [
33+
"Announcements"
34+
],
35+
"summary": "Get an announcement by ID",
36+
"parameters": [
37+
{
38+
"type": "string",
39+
"description": "Announcement ID",
40+
"name": "id",
41+
"in": "path",
42+
"required": true
43+
}
44+
],
45+
"responses": {}
46+
}
47+
},
48+
"/events": {
49+
"get": {
50+
"description": "Gets all the events from the event database",
51+
"consumes": [
52+
"application/json"
53+
],
54+
"produces": [
55+
"application/json"
56+
],
57+
"tags": [
58+
"Events"
59+
],
60+
"summary": "Gets all the events",
61+
"responses": {}
62+
},
63+
"post": {
64+
"description": "Retrieves a single event from the database.",
65+
"consumes": [
66+
"application/json"
67+
],
68+
"produces": [
69+
"application/json"
70+
],
71+
"tags": [
72+
"Events"
73+
],
74+
"summary": "Creates a new event and generates new ID",
75+
"responses": {}
76+
}
77+
},
78+
"/events/:id": {
79+
"get": {
80+
"description": "Retrieves a single event from the database.",
81+
"consumes": [
82+
"application/json"
83+
],
84+
"produces": [
85+
"application/json"
86+
],
87+
"tags": [
88+
"Events"
89+
],
90+
"summary": "Get an Event by ID",
91+
"parameters": [
92+
{
93+
"type": "string",
94+
"description": "Event ID",
95+
"name": "id",
96+
"in": "path",
97+
"required": true
98+
}
99+
],
100+
"responses": {}
101+
},
102+
"put": {
103+
"description": "Updates the event of choice in the database",
104+
"consumes": [
105+
"application/json"
106+
],
107+
"produces": [
108+
"application/json"
109+
],
110+
"tags": [
111+
"Events"
112+
],
113+
"summary": "Update the Event of Choice",
114+
"parameters": [
115+
{
116+
"type": "string",
117+
"description": "Event ID",
118+
"name": "id",
119+
"in": "path",
120+
"required": true
121+
}
122+
],
123+
"responses": {}
124+
},
125+
"delete": {
126+
"description": "Delete the event of choice from the database",
127+
"consumes": [
128+
"application/json"
129+
],
130+
"produces": [
131+
"application/json"
132+
],
133+
"tags": [
134+
"Events"
135+
],
136+
"summary": "Deletes the Event of Choice",
137+
"parameters": [
138+
{
139+
"type": "string",
140+
"description": "Event ID",
141+
"name": "id",
142+
"in": "path",
143+
"required": true
144+
}
145+
],
146+
"responses": {}
147+
}
148+
}
149+
}
150+
}

0 commit comments

Comments
 (0)