You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

swagger.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. module.exports = {
  2. servers: [
  3. {
  4. url: "http://localhost:3001/",
  5. description: "Local server",
  6. },
  7. ],
  8. tags: [
  9. {
  10. name: "User"
  11. },
  12. ],
  13. openapi: "3.0.3",
  14. info: {
  15. title: "Trampa",
  16. description: "Trampa api"
  17. },
  18. paths: {
  19. '/users': {
  20. get: {
  21. tags: ["User"],
  22. description: "Get all users",
  23. parameters: [],
  24. responses: {
  25. 200: {
  26. description: "Success",
  27. content: {
  28. "application/json": {
  29. schema: {
  30. $ref: "#/components/schemas/User",
  31. }
  32. }
  33. }
  34. },
  35. 200: {
  36. description: "Users returned successfully"
  37. },
  38. 500: {
  39. description: "Internal server error"
  40. }
  41. }
  42. },
  43. post: {
  44. tags: ["User"],
  45. description: "Create user",
  46. parameters: [],
  47. requestBody: {
  48. content: {
  49. "application/json": {
  50. schema: {
  51. type: "object",
  52. properties: {
  53. name: {
  54. type: "string"
  55. },
  56. email: {
  57. type: "string"
  58. },
  59. password: {
  60. type: "string"
  61. }
  62. }
  63. }
  64. }
  65. }
  66. },
  67. responses: {
  68. 201: {
  69. description: "User created successfully",
  70. content: {
  71. "application/json": {
  72. schema: {
  73. $ref: "#/components/schemas/User"
  74. },
  75. },
  76. },
  77. },
  78. 400: {
  79. description: "Object cant be empty",
  80. },
  81. 401: {
  82. description: "Invalid input parameters",
  83. },
  84. 500: {
  85. description: "Internal server error",
  86. }
  87. }
  88. }
  89. },
  90. '/users/{id}': {
  91. get: {
  92. tags: ["User"],
  93. description: "Get user by id",
  94. parameters: [
  95. {
  96. name: "id",
  97. in: "path",
  98. schema: {
  99. $ref: "#/components/schemas/id",
  100. },
  101. required: true,
  102. description: "A single user id",
  103. }
  104. ],
  105. responses: {
  106. 200: {
  107. description: "Success",
  108. content: {
  109. "application/json": {
  110. schema: {
  111. $ref: "#/components/schemas/User",
  112. }
  113. }
  114. }
  115. },
  116. 400: {
  117. description: "Bad request"
  118. },
  119. 404: {
  120. description: "User with specified id does not exist"
  121. },
  122. 500: {
  123. description: "Internal server error"
  124. }
  125. }
  126. },
  127. put: {
  128. tags: ["User"],
  129. description: "Update user",
  130. parameters: [
  131. {
  132. name: "id",
  133. in: "path",
  134. schema: {
  135. $ref: "#/components/schemas/id", // data model of the param
  136. },
  137. required: true,
  138. description: "A single user id",
  139. }
  140. ],
  141. requestBody: {
  142. content: {
  143. "application/json": {
  144. schema: {
  145. type: "object",
  146. properties: {
  147. name: {
  148. type: "string"
  149. },
  150. email: {
  151. type: "string"
  152. },
  153. password: {
  154. type: "string"
  155. }
  156. }
  157. }
  158. }
  159. }
  160. },
  161. responses: {
  162. 200: {
  163. description: "User updated successfully",
  164. },
  165. 400: {
  166. description: "Invalid input parameters",
  167. },
  168. 500: {
  169. description: "Server error",
  170. }
  171. }
  172. },
  173. patch: {
  174. tags: ["User"],
  175. description: "Update user",
  176. parameters: [
  177. {
  178. name: "id",
  179. in: "path",
  180. // schema: {
  181. // $ref: "#/components/schemas/id", // data model of the param
  182. // },
  183. required: true,
  184. description: "A single user id",
  185. }
  186. ],
  187. requestBody: {
  188. content: {
  189. }
  190. },
  191. responses: {
  192. }
  193. },
  194. delete: {
  195. tags: ["User"],
  196. description: "Delete user",
  197. parameters: [
  198. {
  199. name: "id",
  200. in: "path",
  201. schema: {
  202. $ref: "#/components/schemas/id",
  203. },
  204. required: true,
  205. },
  206. ],
  207. responses: {
  208. 204: {
  209. description: "User deleted successfully",
  210. },
  211. 400: {
  212. description: "You need to provide valid Id'",
  213. },
  214. 404: {
  215. description: "User not found",
  216. },
  217. 500: {
  218. description: "Internal server error",
  219. },
  220. },
  221. }
  222. },
  223. '/auth/token': {
  224. post: {
  225. tags: ["Token"],
  226. description: "Log in user",
  227. parameters: [],
  228. requestBody: {
  229. content: {
  230. "application/json": {
  231. schema: {
  232. type: "object",
  233. properties: {
  234. email: {
  235. type: "string"
  236. },
  237. password: {
  238. type: "string"
  239. }
  240. }
  241. }
  242. }
  243. }
  244. },
  245. responses: {
  246. 201: {
  247. description: "User logged in successfully!"
  248. },
  249. 400: {
  250. description: "Wrong credentials!"
  251. },
  252. 500: {
  253. description: "Internal server error"
  254. }
  255. }
  256. }
  257. },
  258. '/auth/logout': {
  259. post: {
  260. tags: ["Token"],
  261. description: "Log out user",
  262. parameters: [],
  263. requestBody: {
  264. content: {
  265. "application/json": {
  266. schema: {
  267. $ref: "#/components/schemas/Token"
  268. }
  269. }
  270. }
  271. },
  272. responses: {
  273. 201: {
  274. description: "User logged out successfully"
  275. },
  276. 404: {
  277. description: "No user has the token provided!"
  278. },
  279. 500: {
  280. description: "Internal server error"
  281. }
  282. }
  283. }
  284. },
  285. '/auth/refresh': {
  286. post: {
  287. tags: ["Token"],
  288. description: "Log out user",
  289. parameters: [],
  290. requestBody: {
  291. content: {
  292. "application/json": {
  293. schema: {
  294. $ref: "#/components/schemas/Token"
  295. }
  296. }
  297. }
  298. },
  299. responses: {
  300. 201: {
  301. description: "User refreshed successfully"
  302. },
  303. 404: {
  304. description: "Token not valid!"
  305. }
  306. }
  307. }
  308. }
  309. },
  310. components: {
  311. schemas: {
  312. id: {
  313. type: "string",
  314. description: "An id of a user"
  315. },
  316. User: {
  317. type: "object",
  318. properties: {
  319. name: {
  320. type: "string"
  321. },
  322. email: {
  323. type: "string"
  324. },
  325. password: {
  326. type: "string"
  327. },
  328. tokens: {
  329. type: "array",
  330. items: {
  331. type: "string"
  332. }
  333. }
  334. }
  335. },
  336. Token: {
  337. type: "object",
  338. properties: {
  339. token: {
  340. type: "string"
  341. },
  342. userId: {
  343. type: "string"
  344. }
  345. }
  346. }
  347. }
  348. }
  349. }