-
Notifications
You must be signed in to change notification settings - Fork 2
/
swagger.js
174 lines (171 loc) · 5.8 KB
/
swagger.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import swaggerJsdoc from 'swagger-jsdoc';
import dotenv from 'dotenv';
dotenv.config();
const options = {
definition: {
openapi: '3.0.0',
info: {
title: 'SchoolERP API',
// description: '1. Assignment Routes: CRUD for Assignments. \n2. Common Routes: Any User can Access. \n3. Teacher Only Ruotes: Only Teacher can access. \n4. Student Routes: CRUD on Students. \n5. Submission Route: CRUD on Submissions \n6. Student Only Routes: Only Student can access them. \n7. User Routes: Login/Signup',
description: "School ERP API: Using NodeJs, MongoDb by bhaveshpatil07.",
contact: {
email: "[email protected]",
url: "https://github.com/bhaveshpatil07"
},
version: '1.0.0',
},
components: {
schemas: {
Student: {
type: 'object',
properties: {
userName: {
type: 'string',
description: 'Unique username of the student, references the User model.',
required: true,
},
name: {
type: 'string',
description: 'Name of the student.',
required: true,
},
rollNumber: {
type: 'string',
description: 'Roll number assigned to the student.',
required: true,
},
class: {
type: 'string',
enum: ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X', 'XI', 'XII'],
description: 'Class in which the student is enrolled.',
required: true,
},
section: {
type: 'string',
enum: ['A', 'B', 'C', 'D', 'E', 'F'],
description: 'Section assigned to the student.',
required: true,
},
},
required: ['userName', 'name', 'rollNumber', 'class', 'section'],
},
Assignment: {
type: 'object',
properties: {
teacherId: {
type: 'string',
description: 'ID of the teacher assigned to this assignment.',
required: true,
},
title: {
type: 'string',
minLength: 3,
description: 'Title of the assignment.',
required: true,
},
description: {
type: 'string',
minLength: 10,
description: 'Detailed description of the assignment.',
required: true,
},
dueDate: {
type: 'string',
format: 'date-time',
description: 'Due date for the assignment.',
required: true,
},
status: {
type: 'string',
enum: ['Pending', 'Completed'],
default: 'Pending',
description: 'Current status of the assignment.',
required: true,
},
},
required: ['teacherId', 'title', 'description', 'dueDate', 'status'],
},
Submission: {
type: 'object',
properties: {
assignmentId: {
type: 'string',
description: 'ID of the assignment being submitted.',
required: true,
},
studentId: {
type: 'string',
description: 'ID of the student submitting the assignment.',
required: true,
},
submissionLink: {
type: 'string',
description: 'Valid Link to the submitted assignment.',
required: true,
},
grade: {
type: 'string',
enum: ['A', 'B', 'C', 'D', 'E', null],
default: null,
description: 'Grade assigned to the submission.',
},
},
required: ['assignmentId', 'studentId', 'submissionLink'],
},
User: {
type: 'object',
properties: {
userName: {
type: 'string',
minLength: 3,
unique: true,
description: 'Unique username of the user, must be at least 3 characters long.',
},
password: {
type: 'string',
description: 'Hashed password for the user account.',
minLength: 6,
required: true,
},
role: {
type: 'string',
enum: ['Teacher', 'Student'],
default: 'Student',
description: 'Role of the user, either Teacher or Student.',
required: true,
},
},
required: ['userName', 'password', 'role'],
},
},
securitySchemes: {
bearerAuth: {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
description: 'JWT Authorization header using the Bearer scheme.',
},
},
},
servers: [
{
url: `${process.env.BACKEND_URL || "http://localhost:8000"}/api/v1`
},
{
url: `http://localhost:${process.env.PORT || 8000}/api/v1`,
},
],
tags: [
{ name: "Teacher Only Routes", description: "Only Teacher accessible endpoints" },
{ name: "Student Only Routes", description: "Only Student accessible endpoints" },
{ name: "Common Routes", description: "Common accessible endpoints" },
{ name: 'User Routes', description: 'User-related endpoints' },
{ name: 'Student Routes', description: 'Student-related endpoints' },
{ name: 'Assignment Routes', description: 'Assignment-related endpoints' },
{ name: 'Submission Routes', description: 'Submission-related endpoints' },
],
},
apis: ['./routes/*.js'],
};
const swaggerSpec = swaggerJsdoc(options);
export default swaggerSpec;