Skip to content

Commit 8c1a549

Browse files
Merge pull request #21 from Rohith-JN/master
feat: setup swagger for docs
2 parents 06d5d84 + 8cf972c commit 8c1a549

File tree

7 files changed

+428
-39
lines changed

7 files changed

+428
-39
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
"react-dom": "19.1.0",
3232
"react-hot-toast": "^2.6.0",
3333
"react-qr-code": "^2.0.18",
34+
"swagger-ui": "^5.29.0",
35+
"swagger-ui-react": "^5.29.0",
3436
"tailwind-merge": "^3.3.1",
3537
"web-push": "^3.6.7",
3638
"zod": "^4.1.5"
@@ -40,6 +42,8 @@
4042
"@types/node": "^20",
4143
"@types/react": "^19",
4244
"@types/react-dom": "^19",
45+
"@types/swagger-ui": "^5.21.1",
46+
"@types/swagger-ui-react": "^5.18.0",
4347
"@types/web-push": "^3.6.4",
4448
"tailwindcss": "^4",
4549
"tw-animate-css": "^1.3.8",

public/docs/base.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"openapi": "3.0.0",
3+
"info": {
4+
"title": "My API",
5+
"version": "1.0.0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost:3000"
10+
}
11+
],
12+
"paths": {
13+
"/api/users/create-team": {
14+
"post": {
15+
"$ref": "./users/create-team.json#/paths/~1api~1users~1create-team/post"
16+
}
17+
},
18+
"/api/users/join-team": {
19+
"post": {
20+
"$ref": "./users/join-team.json#/paths/~1api~1users~1join-team/post"
21+
}
22+
}
23+
}
24+
}

public/docs/users/create-team.json

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
{
2+
"paths": {
3+
"/api/users/create-team": {
4+
"post": {
5+
"summary": "Create a new team",
6+
"description": "Creates a new team with a unique join code. The user creating the team is automatically added as a member. Requires authentication via Bearer token.",
7+
"operationId": "createTeam",
8+
"tags": [
9+
"users"
10+
],
11+
"security": [
12+
{
13+
"bearerAuth": []
14+
}
15+
],
16+
"requestBody": {
17+
"required": true,
18+
"content": {
19+
"application/json": {
20+
"schema": {
21+
"$ref": "#/components/schemas/TeamInput"
22+
}
23+
}
24+
}
25+
},
26+
"responses": {
27+
"201": {
28+
"description": "Team created successfully",
29+
"content": {
30+
"application/json": {
31+
"schema": {
32+
"type": "object",
33+
"properties": {
34+
"message": {
35+
"type": "string",
36+
"example": "Team Created Successfully"
37+
},
38+
"data": {
39+
"$ref": "#/components/schemas/Team"
40+
}
41+
}
42+
}
43+
}
44+
}
45+
},
46+
"400": {
47+
"description": "Validation failed",
48+
"content": {
49+
"application/json": {
50+
"schema": {
51+
"type": "object",
52+
"properties": {
53+
"error": {
54+
"type": "string",
55+
"example": "Validation failed"
56+
},
57+
"details": {
58+
"type": "string"
59+
}
60+
}
61+
}
62+
}
63+
}
64+
},
65+
"401": {
66+
"description": "Unauthorized",
67+
"content": {
68+
"application/json": {
69+
"schema": {
70+
"type": "object",
71+
"properties": {
72+
"error": {
73+
"type": "string",
74+
"example": "Unauthorized"
75+
}
76+
}
77+
}
78+
}
79+
}
80+
},
81+
"404": {
82+
"description": "User not found",
83+
"content": {
84+
"application/json": {
85+
"schema": {
86+
"type": "object",
87+
"properties": {
88+
"error": {
89+
"type": "string",
90+
"example": "User not found"
91+
},
92+
"data": {
93+
"type": "object"
94+
}
95+
}
96+
}
97+
}
98+
}
99+
},
100+
"500": {
101+
"description": "Internal server error",
102+
"content": {
103+
"application/json": {
104+
"schema": {
105+
"type": "object",
106+
"properties": {
107+
"error": {
108+
"type": "string",
109+
"example": "Internal Server Error"
110+
}
111+
}
112+
}
113+
}
114+
}
115+
}
116+
}
117+
}
118+
}
119+
},
120+
"components": {
121+
"securitySchemes": {
122+
"bearerAuth": {
123+
"type": "http",
124+
"scheme": "bearer",
125+
"bearerFormat": "JWT"
126+
}
127+
},
128+
"schemas": {
129+
"TeamInput": {
130+
"type": "object",
131+
"properties": {
132+
"name": {
133+
"type": "string",
134+
"example": "Code Masters"
135+
},
136+
"description": {
137+
"type": "string",
138+
"example": "A team for competitive programming"
139+
}
140+
},
141+
"required": [
142+
"name"
143+
]
144+
},
145+
"Team": {
146+
"type": "object",
147+
"properties": {
148+
"_id": {
149+
"type": "string",
150+
"example": "64c1234abc5678def9012345"
151+
},
152+
"name": {
153+
"type": "string",
154+
"example": "Code Masters"
155+
},
156+
"description": {
157+
"type": "string",
158+
"example": "A team for competitive programming"
159+
},
160+
"joinCode": {
161+
"type": "string",
162+
"example": "XYZ123"
163+
},
164+
"members": {
165+
"type": "array",
166+
"items": {
167+
"type": "string",
168+
"example": "64c9876def5432abc1098765"
169+
}
170+
}
171+
}
172+
}
173+
}
174+
}
175+
}

public/docs/users/join-team.json

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
{
2+
"paths": {
3+
"/api/users/join-team": {
4+
"post": {
5+
"summary": "Join a team using join code",
6+
"description": "Allows an authenticated user to join a team by providing a valid join code. The team cannot exceed 5 members.",
7+
"operationId": "joinTeam",
8+
"tags": [
9+
"users"
10+
],
11+
"security": [
12+
{
13+
"bearerAuth": []
14+
}
15+
],
16+
"requestBody": {
17+
"required": true,
18+
"content": {
19+
"application/json": {
20+
"schema": {
21+
"type": "object",
22+
"properties": {
23+
"joinCode": {
24+
"type": "string",
25+
"example": "XYZ123"
26+
}
27+
},
28+
"required": [
29+
"joinCode"
30+
]
31+
}
32+
}
33+
}
34+
},
35+
"responses": {
36+
"200": {
37+
"description": "Successfully joined the team",
38+
"content": {
39+
"application/json": {
40+
"schema": {
41+
"type": "object",
42+
"properties": {
43+
"message": {
44+
"type": "string",
45+
"example": "Successfully joined the team"
46+
},
47+
"team": {
48+
"$ref": "#/components/schemas/Team"
49+
}
50+
}
51+
}
52+
}
53+
}
54+
},
55+
"400": {
56+
"description": "Bad request (missing join code, user already in a team, or team full)",
57+
"content": {
58+
"application/json": {
59+
"schema": {
60+
"type": "object",
61+
"properties": {
62+
"error": {
63+
"type": "string",
64+
"example": "User already in a team"
65+
}
66+
}
67+
}
68+
}
69+
}
70+
},
71+
"401": {
72+
"description": "Unauthorized (invalid or missing token)",
73+
"content": {
74+
"application/json": {
75+
"schema": {
76+
"type": "object",
77+
"properties": {
78+
"error": {
79+
"type": "string",
80+
"example": "Unauthorized"
81+
}
82+
}
83+
}
84+
}
85+
}
86+
},
87+
"404": {
88+
"description": "Not found (invalid join code or user not found)",
89+
"content": {
90+
"application/json": {
91+
"schema": {
92+
"type": "object",
93+
"properties": {
94+
"error": {
95+
"type": "string",
96+
"example": "Invalid join code"
97+
}
98+
}
99+
}
100+
}
101+
}
102+
},
103+
"500": {
104+
"description": "Internal server error",
105+
"content": {
106+
"application/json": {
107+
"schema": {
108+
"type": "object",
109+
"properties": {
110+
"error": {
111+
"type": "string",
112+
"example": "Internal server error"
113+
}
114+
}
115+
}
116+
}
117+
}
118+
}
119+
}
120+
}
121+
}
122+
},
123+
"components": {
124+
"securitySchemes": {
125+
"bearerAuth": {
126+
"type": "http",
127+
"scheme": "bearer",
128+
"bearerFormat": "JWT"
129+
}
130+
},
131+
"schemas": {
132+
"Team": {
133+
"type": "object",
134+
"properties": {
135+
"_id": {
136+
"type": "string",
137+
"example": "64c1234abc5678def9012345"
138+
},
139+
"name": {
140+
"type": "string",
141+
"example": "Code Masters"
142+
},
143+
"description": {
144+
"type": "string",
145+
"example": "A team for competitive programming"
146+
},
147+
"joinCode": {
148+
"type": "string",
149+
"example": "XYZ123"
150+
},
151+
"members": {
152+
"type": "array",
153+
"items": {
154+
"type": "string",
155+
"example": "64c9876def5432abc1098765"
156+
}
157+
}
158+
}
159+
}
160+
}
161+
}
162+
}

src/app/docs/page.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use client";
2+
import SwaggerUI from "swagger-ui-react";
3+
import "swagger-ui-react/swagger-ui.css";
4+
5+
export default function DocsPage() {
6+
return (
7+
<main style={{ padding: 16, backgroundColor: 'white', height: '100vh' }}>
8+
<div style={{ border: "1px solid #e6e6e6", borderRadius: 8, overflow: "hidden" }}>
9+
<SwaggerUI url="/docs/base.json" />
10+
</div>
11+
</main>
12+
);
13+
}

0 commit comments

Comments
 (0)