api.ts 13 KB

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