api.ts 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. import * as p from '../../package.json';
  2. export default {
  3. openapi: '3.0.0',
  4. info: {
  5. title: "Kutt.it",
  6. description: "API referrence for [http://kutt.it](http://kutt.it).\n",
  7. version: p.version
  8. },
  9. servers: [{
  10. url: "https://kutt.it/api/v2"
  11. }],
  12. tags: [{
  13. name: "health"
  14. }, {
  15. name: "links"
  16. }, {
  17. name: "domains"
  18. }, {
  19. name: "users"
  20. }],
  21. paths: {
  22. '/health': {
  23. get: {
  24. tags: ["health"],
  25. summary: "API health",
  26. responses: {
  27. 200: {
  28. description: "Health",
  29. content: {
  30. 'text/html': {
  31. example: "OK"
  32. }
  33. }
  34. }
  35. }
  36. }
  37. },
  38. '/links': {
  39. get: {
  40. tags: ["links"],
  41. description: "Get list of links",
  42. parameters: [{
  43. name: "limit",
  44. in: "query",
  45. description: "Limit",
  46. required: false,
  47. style: "form",
  48. explode: true,
  49. schema: {
  50. type: "number",
  51. example: 10
  52. }
  53. }, {
  54. name: "skip",
  55. in: "query",
  56. description: "Skip",
  57. required: false,
  58. style: "form",
  59. explode: true,
  60. schema: {
  61. type: "number",
  62. example: 0
  63. }
  64. }, {
  65. name: "all",
  66. in: "query",
  67. description: "All links (ADMIN only)",
  68. required: false,
  69. style: "form",
  70. explode: true,
  71. schema: {
  72. type: "boolean",
  73. example: false
  74. }
  75. }],
  76. responses: {
  77. 200: {
  78. description: "List of links",
  79. content: {
  80. 'application/json': {
  81. schema: {
  82. $ref: "#/components/schemas/inline_response_200"
  83. }
  84. }
  85. }
  86. }
  87. },
  88. security: [{
  89. APIKeyAuth: []
  90. }]
  91. },
  92. post: {
  93. tags: ["links"],
  94. description: "Create a short link",
  95. requestBody: {
  96. content: {
  97. 'application/json': {
  98. schema: {
  99. $ref: "#/components/schemas/body"
  100. }
  101. }
  102. }
  103. },
  104. responses: {
  105. 200: {
  106. description: "Craeted link",
  107. content: {
  108. 'application/json': {
  109. schema: {
  110. $ref: "#/components/schemas/Link"
  111. }
  112. }
  113. }
  114. }
  115. },
  116. security: [{
  117. APIKeyAuth: []
  118. }]
  119. }
  120. },
  121. '/links/{id}': {
  122. delete: {
  123. tags: ["links"],
  124. description: "Delete a link",
  125. parameters: [{
  126. name: "id",
  127. in: "path",
  128. required: true,
  129. style: "simple",
  130. explode: false,
  131. schema: {
  132. type: "string",
  133. format: "uuid"
  134. }
  135. }],
  136. responses: {
  137. 200: {
  138. description: "Deleted link successfully",
  139. content: {
  140. 'application/json': {
  141. schema: {
  142. $ref: "#/components/schemas/inline_response_200_1"
  143. }
  144. }
  145. }
  146. }
  147. },
  148. security: [{
  149. APIKeyAuth: []
  150. }]
  151. }
  152. },
  153. '/links/{id}/stats': {
  154. get: {
  155. tags: ["links"],
  156. description: "Get link stats",
  157. parameters: [{
  158. name: "id",
  159. in: "path",
  160. required: true,
  161. style: "simple",
  162. explode: false,
  163. schema: {
  164. type: "string",
  165. format: "uuid"
  166. }
  167. }],
  168. responses: {
  169. 200: {
  170. description: "Link stats",
  171. content: {
  172. 'application/json': {
  173. schema: {
  174. $ref: "#/components/schemas/Stats"
  175. }
  176. }
  177. }
  178. }
  179. },
  180. security: [{
  181. APIKeyAuth: []
  182. }]
  183. }
  184. },
  185. '/domains': {
  186. post: {
  187. tags: ["domains"],
  188. description: "Create a domain",
  189. requestBody: {
  190. content: {
  191. 'application/json': {
  192. schema: {
  193. $ref: "#/components/schemas/body_1"
  194. }
  195. }
  196. }
  197. },
  198. responses: {
  199. 200: {
  200. description: "Created domain",
  201. content: {
  202. 'application/json': {
  203. schema: {
  204. $ref: "#/components/schemas/Domain"
  205. }
  206. }
  207. }
  208. }
  209. },
  210. security: [{
  211. APIKeyAuth: []
  212. }]
  213. }
  214. },
  215. '/domains/{id}': {
  216. delete: {
  217. tags: ["domains"],
  218. description: "Delete a domain",
  219. parameters: [{
  220. name: "id",
  221. in: "path",
  222. required: true,
  223. style: "simple",
  224. explode: false,
  225. schema: {
  226. type: "string",
  227. format: "uuid"
  228. }
  229. }],
  230. responses: {
  231. 200: {
  232. description: "Deleted domain successfully",
  233. content: {
  234. 'application/json': {
  235. schema: {
  236. $ref: "#/components/schemas/inline_response_200_1"
  237. }
  238. }
  239. }
  240. }
  241. },
  242. security: [{
  243. APIKeyAuth: []
  244. }]
  245. }
  246. },
  247. '/users': {
  248. get: {
  249. tags: ["users"],
  250. description: "Get user info",
  251. responses: {
  252. 200: {
  253. description: "User info",
  254. content: {
  255. 'application/json': {
  256. schema: {
  257. $ref: "#/components/schemas/User"
  258. }
  259. }
  260. }
  261. }
  262. },
  263. security: [{
  264. APIKeyAuth: []
  265. }]
  266. }
  267. }
  268. },
  269. components: {
  270. schemas: {
  271. Link: {
  272. type: "object",
  273. properties: {
  274. address: {
  275. type: "string"
  276. },
  277. banned: {
  278. type: "boolean",
  279. default: false
  280. },
  281. created_at: {
  282. type: "string",
  283. format: "date-time"
  284. },
  285. id: {
  286. type: "string",
  287. format: "uuid"
  288. },
  289. link: {
  290. type: "string"
  291. },
  292. password: {
  293. type: "boolean",
  294. default: false
  295. },
  296. target: {
  297. type: "string"
  298. },
  299. updated_at: {
  300. type: "string",
  301. format: "date-time"
  302. },
  303. visit_count: {
  304. type: "number"
  305. }
  306. }
  307. },
  308. Domain: {
  309. type: "object",
  310. properties: {
  311. address: {
  312. type: "string"
  313. },
  314. banned: {
  315. type: "boolean",
  316. default: false
  317. },
  318. created_at: {
  319. type: "string",
  320. format: "date-time"
  321. },
  322. id: {
  323. type: "string",
  324. format: "uuid"
  325. },
  326. homepage: {
  327. type: "string"
  328. },
  329. updated_at: {
  330. type: "string",
  331. format: "date-time"
  332. }
  333. }
  334. },
  335. User: {
  336. type: "object",
  337. properties: {
  338. apikey: {
  339. type: "string"
  340. },
  341. email: {
  342. type: "string"
  343. },
  344. domains: {
  345. type: "array",
  346. items: {
  347. $ref: "#/components/schemas/Domain"
  348. }
  349. }
  350. }
  351. },
  352. StatsItem: {
  353. type: "object",
  354. properties: {
  355. stats: {
  356. $ref: "#/components/schemas/StatsItem_stats"
  357. },
  358. views: {
  359. type: "array",
  360. items: {
  361. type: "number"
  362. }
  363. }
  364. }
  365. },
  366. Stats: {
  367. type: "object",
  368. properties: {
  369. allTime: {
  370. $ref: "#/components/schemas/StatsItem"
  371. },
  372. lastDay: {
  373. $ref: "#/components/schemas/StatsItem"
  374. },
  375. lastMonth: {
  376. $ref: "#/components/schemas/StatsItem"
  377. },
  378. lastWeek: {
  379. $ref: "#/components/schemas/StatsItem"
  380. },
  381. updatedAt: {
  382. type: "string"
  383. },
  384. address: {
  385. type: "string"
  386. },
  387. banned: {
  388. type: "boolean",
  389. default: false
  390. },
  391. created_at: {
  392. type: "string",
  393. format: "date-time"
  394. },
  395. id: {
  396. type: "string",
  397. format: "uuid"
  398. },
  399. link: {
  400. type: "string"
  401. },
  402. password: {
  403. type: "boolean",
  404. default: false
  405. },
  406. target: {
  407. type: "string"
  408. },
  409. updated_at: {
  410. type: "string",
  411. format: "date-time"
  412. },
  413. visit_count: {
  414. type: "number"
  415. }
  416. }
  417. },
  418. inline_response_200: {
  419. properties: {
  420. limit: {
  421. type: "number",
  422. default: 10
  423. },
  424. skip: {
  425. type: "number",
  426. default: 0
  427. },
  428. total: {
  429. type: "number",
  430. default: 0
  431. },
  432. data: {
  433. type: "array",
  434. items: {
  435. $ref: "#/components/schemas/Link"
  436. }
  437. }
  438. }
  439. },
  440. body: {
  441. required: ["target"],
  442. properties: {
  443. target: {
  444. type: "string"
  445. },
  446. password: {
  447. type: "string"
  448. },
  449. customurl: {
  450. type: "string"
  451. },
  452. reuse: {
  453. type: "boolean",
  454. default: false
  455. },
  456. domain: {
  457. type: "string"
  458. }
  459. }
  460. },
  461. inline_response_200_1: {
  462. properties: {
  463. message: {
  464. type: "string"
  465. }
  466. }
  467. },
  468. body_1: {
  469. required: ["address"],
  470. properties: {
  471. address: {
  472. type: "string"
  473. },
  474. homepage: {
  475. type: "string"
  476. }
  477. }
  478. },
  479. StatsItem_stats_browser: {
  480. type: "object",
  481. properties: {
  482. name: {
  483. type: "string"
  484. },
  485. value: {
  486. type: "number"
  487. }
  488. }
  489. },
  490. StatsItem_stats: {
  491. type: "object",
  492. properties: {
  493. browser: {
  494. type: "array",
  495. items: {
  496. $ref: "#/components/schemas/StatsItem_stats_browser"
  497. }
  498. },
  499. os: {
  500. type: "array",
  501. items: {
  502. $ref: "#/components/schemas/StatsItem_stats_browser"
  503. }
  504. },
  505. country: {
  506. type: "array",
  507. items: {
  508. $ref: "#/components/schemas/StatsItem_stats_browser"
  509. }
  510. },
  511. referrer: {
  512. type: "array",
  513. items: {
  514. $ref: "#/components/schemas/StatsItem_stats_browser"
  515. }
  516. }
  517. }
  518. }
  519. },
  520. securitySchemes: {
  521. APIKeyAuth: {
  522. type: "apiKey",
  523. name: "X-API-KEY",
  524. in: "header"
  525. }
  526. }
  527. }
  528. };