· 4 years ago · Jun 29, 2021, 11:16 AM
1// @ts-ignore
2import { version } from '../package.json';
3import { Settings } from './types';
4
5const env = process.env.SETTINGS || Settings.Local;
6
7const baseUrlMap: { [key: string]: string } = {
8 [Settings.Local]: 'localhost:5000',
9 [Settings.Staging]: 'http://staging.lighter-api.com',
10 [Settings.Production]: 'http://lighter-api.com',
11};
12
13const baseUrl = baseUrlMap[env];
14
15export default {
16 swagger: '2.0',
17 info: {
18 version,
19 title: 'Ligher API',
20 description: 'This is Ligher API documentation',
21 license: {
22 name: 'MIT',
23 url: 'https://opensource.org/licenses/MIT',
24 },
25 },
26 host: baseUrl,
27 basePath: '/api',
28 tags: [
29 {
30 name: 'Events',
31 description: 'API for events in the system',
32 },
33 ],
34 schemes: ['http'],
35 consumes: ['application/json'],
36 produces: ['application/json'],
37 paths: {
38 '/events': {
39 post: {
40 tags: ['Events'],
41 description: 'Create new event',
42 parameters: [
43 {
44 name: 'user',
45 in: 'body',
46 description: 'Event that we want to create',
47 schema: {
48 $ref: '#/definitions/Event',
49 },
50 },
51 ],
52 produces: ['application/json'],
53 responses: {
54 '200': {
55 description: 'New event is created',
56 schema: {
57 $ref: '#/definitions/Event',
58 },
59 },
60 },
61 },
62 get: {
63 tags: ['Events'],
64 summary: 'Get the list of all events',
65 responses: {
66 '200': {
67 description: 'OK',
68 schema: {
69 $ref: '#/definitions/Events',
70 },
71 },
72 },
73 },
74 },
75 '/events/:id': {
76 get: {
77 tags: ['Events'],
78 summary: 'Get the particular event',
79 responses: {
80 '200': {
81 description: 'OK',
82 schema: {
83 $ref: '#/definitions/Event',
84 },
85 },
86 },
87 parameters: [
88 {
89 name: 'id',
90 in: 'params',
91 description: 'object id of the event',
92 schema: {
93 type: 'string',
94 },
95 },
96 ],
97 },
98 },
99 '/events/:id/request-join': {
100 post: {
101 tags: ['Events'],
102 summary: 'Request to join the particular event',
103 responses: {
104 '200': {
105 description: 'OK',
106 schema: {
107 $ref: '#/definitions/Event',
108 },
109 },
110 },
111 parameters: [
112 {
113 name: 'id',
114 in: 'params',
115 description: 'object id of the event',
116 schema: {
117 type: 'string',
118 },
119 },
120 ],
121 },
122 },
123 '/events/:id/manage/approve-request': {
124 post: {
125 tags: ['Events'],
126 summary: 'Approve the request to join the particular event',
127 responses: {
128 '200': {
129 description: 'OK',
130 schema: {
131 $ref: '#/definitions/Event',
132 },
133 },
134 },
135 parameters: [
136 {
137 name: 'id',
138 in: 'params',
139 description: 'object id of the event',
140 schema: {
141 type: 'string',
142 },
143 },
144 {
145 in: 'body',
146 description:
147 'post request body includes userId of the user that requested to join',
148 schema: {
149 type: 'object',
150 properties: {
151 userId: {
152 type: 'string',
153 },
154 },
155 },
156 },
157 ],
158 },
159 },
160 '/events/:id/manage/dismiss-request': {
161 post: {
162 tags: ['Events'],
163 summary: 'Dismiss the request to join the particular event',
164 responses: {
165 '200': {
166 description: 'OK',
167 schema: {
168 $ref: '#/definitions/Event',
169 },
170 },
171 },
172 parameters: [
173 {
174 name: 'id',
175 in: 'params',
176 description: 'object id of the event',
177 schema: {
178 type: 'string',
179 },
180 },
181 {
182 in: 'body',
183 description:
184 'post request body includes userId of the user that you want to dismiss',
185 schema: {
186 type: 'object',
187 properties: {
188 userId: {
189 type: 'string',
190 },
191 },
192 },
193 },
194 ],
195 },
196 },
197 '/user/me': {
198 get: {
199 tags: ['User'],
200 summary: 'Get the current user information',
201 responses: {
202 '200': {
203 description: 'OK',
204 schema: {
205 $ref: '#/definitions/User',
206 },
207 },
208 '401': {
209 description: 'The user is not authorized',
210 schema: {
211 $ref: '#/definitions/ErrorMessage',
212 },
213 },
214 },
215 parameters: [
216 {
217 name: 'firebaseid',
218 in: 'headers',
219 description: 'firebase id of the user',
220 schema: {
221 type: 'string',
222 },
223 },
224 ],
225 },
226 },
227 '/user/create': {
228 post: {
229 tags: ['User'],
230 summary: 'Create the new user',
231 responses: {
232 '200': {
233 description: 'OK',
234 schema: {
235 $ref: '#/definitions/User',
236 },
237 },
238 '400': {
239 description: 'The firebase id is not specified',
240 schema: {
241 $ref: '#/definitions/ErrorMessage',
242 },
243 },
244 },
245 parameters: [
246 {
247 name: 'firebaseid',
248 in: 'headers',
249 description: 'firebase id of the user',
250 schema: {
251 type: 'string',
252 },
253 },
254 {
255 name: 'firstName',
256 in: 'body',
257 description: 'first name of the user',
258 schema: {
259 type: 'string',
260 example: 'John',
261 },
262 },
263 {
264 name: 'lastName',
265 in: 'body',
266 description: 'last name of the user',
267 schema: {
268 type: 'string',
269 example: 'Doe',
270 },
271 },
272 {
273 name: 'phoneNumber',
274 in: 'body',
275 description: 'phone number of the user',
276 schema: {
277 type: 'string',
278 example: '+79161234567',
279 },
280 },
281 ],
282 },
283 },
284 },
285 definitions: {
286 Event: {
287 required: ['_id'],
288 properties: {
289 _id: {
290 type: 'string',
291 uniqueItems: true,
292 },
293 admins: {
294 type: 'array',
295 items: {
296 type: 'string',
297 },
298 },
299 date: {
300 type: 'string',
301 format: 'date-time',
302 },
303 geo: {
304 type: 'object',
305 properties: {
306 lat: {
307 type: 'number',
308 format: 'float',
309 },
310 lng: {
311 type: 'number',
312 format: 'float',
313 },
314 },
315 },
316 createdAt: {
317 type: 'string',
318 format: 'date-time',
319 },
320 updatedAt: {
321 type: 'string',
322 format: 'date-time',
323 },
324 requests: {
325 type: 'array',
326 items: {
327 type: 'object',
328 properties: {
329 userId: {
330 type: 'string',
331 },
332 firstName: {
333 type: 'string',
334 },
335 lastName: {
336 type: 'string',
337 },
338 },
339 },
340 },
341 },
342 },
343 Events: {
344 type: 'array',
345 items: {
346 $ref: '#/definitions/Event',
347 },
348 },
349 User: {
350 required: ['_id'],
351 properties: {
352 _id: {
353 type: 'string',
354 uniqueItems: true,
355 },
356 firebaseId: {
357 type: 'string',
358 uniqueItems: true,
359 },
360 firstName: {
361 type: 'string',
362 },
363 lastName: {
364 type: 'string',
365 },
366 phoneNumber: {
367 type: 'string',
368 },
369 createdAt: {
370 type: 'string',
371 format: 'date-time',
372 },
373 updatedAt: {
374 type: 'string',
375 format: 'date-time',
376 },
377 },
378 },
379 ErrorMessage: {
380 properties: {
381 message: {
382 type: 'string',
383 },
384 },
385 },
386 },
387};
388