page.tsx 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. 'use client';
  2. import SwaggerUI from 'swagger-ui-react';
  3. import 'swagger-ui-react/swagger-ui.css';
  4. export default function ApiDocs() {
  5. const spec = {
  6. openapi: '3.0.0',
  7. info: {
  8. title: 'Vtorio API',
  9. version: '1.0.0',
  10. description: 'File upload and management API for Vtorio application',
  11. },
  12. servers: [
  13. {
  14. url: process.env.NODE_ENV === 'production'
  15. ? 'https://your-domain.com'
  16. : 'http://localhost:3000',
  17. description: process.env.NODE_ENV === 'production' ? 'Production server' : 'Development server',
  18. },
  19. ],
  20. paths: {
  21. '/api/upload': {
  22. post: {
  23. summary: 'Upload a file',
  24. description: 'Upload a file to the server and store it in the database',
  25. tags: ['Files'],
  26. requestBody: {
  27. required: true,
  28. content: {
  29. 'multipart/form-data': {
  30. schema: {
  31. type: 'object',
  32. properties: {
  33. file: {
  34. type: 'string',
  35. format: 'binary',
  36. description: 'The file to upload',
  37. },
  38. },
  39. required: ['file'],
  40. },
  41. },
  42. },
  43. },
  44. responses: {
  45. '200': {
  46. description: 'File uploaded successfully',
  47. content: {
  48. 'application/json': {
  49. schema: {
  50. type: 'object',
  51. properties: {
  52. success: { type: 'boolean', example: true },
  53. file: {
  54. type: 'object',
  55. properties: {
  56. id: { type: 'string', example: 'clh123abc456' },
  57. filename: { type: 'string', example: 'document.pdf' },
  58. mimetype: { type: 'string', example: 'application/pdf' },
  59. size: { type: 'number', example: 1024000 },
  60. createdAt: { type: 'string', format: 'date-time' },
  61. },
  62. },
  63. },
  64. },
  65. },
  66. },
  67. },
  68. '400': {
  69. description: 'Bad request - No file provided',
  70. content: {
  71. 'application/json': {
  72. schema: {
  73. type: 'object',
  74. properties: {
  75. success: { type: 'boolean', example: false },
  76. error: { type: 'string', example: 'No file provided' },
  77. },
  78. },
  79. },
  80. },
  81. },
  82. '500': {
  83. description: 'Internal server error',
  84. content: {
  85. 'application/json': {
  86. schema: {
  87. type: 'object',
  88. properties: {
  89. success: { type: 'boolean', example: false },
  90. error: { type: 'string', example: 'Failed to upload file' },
  91. },
  92. },
  93. },
  94. },
  95. },
  96. },
  97. },
  98. },
  99. '/api/files': {
  100. get: {
  101. summary: 'List all files',
  102. description: 'Get a list of all uploaded files with metadata',
  103. tags: ['Files'],
  104. responses: {
  105. '200': {
  106. description: 'List of files retrieved successfully',
  107. content: {
  108. 'application/json': {
  109. schema: {
  110. type: 'object',
  111. properties: {
  112. success: { type: 'boolean', example: true },
  113. files: {
  114. type: 'array',
  115. items: {
  116. type: 'object',
  117. properties: {
  118. id: { type: 'string', example: 'clh123abc456' },
  119. filename: { type: 'string', example: 'document.pdf' },
  120. mimetype: { type: 'string', example: 'application/pdf' },
  121. size: { type: 'number', example: 1024000 },
  122. createdAt: { type: 'string', format: 'date-time' },
  123. updatedAt: { type: 'string', format: 'date-time' },
  124. },
  125. },
  126. },
  127. },
  128. },
  129. },
  130. },
  131. },
  132. '500': {
  133. description: 'Internal server error',
  134. content: {
  135. 'application/json': {
  136. schema: {
  137. type: 'object',
  138. properties: {
  139. success: { type: 'boolean', example: false },
  140. error: { type: 'string', example: 'Failed to list files' },
  141. },
  142. },
  143. },
  144. },
  145. },
  146. },
  147. },
  148. },
  149. '/api/files/{id}': {
  150. get: {
  151. summary: 'Download a file',
  152. description: 'Download a specific file by its ID',
  153. tags: ['Files'],
  154. parameters: [
  155. {
  156. name: 'id',
  157. in: 'path',
  158. required: true,
  159. description: 'The ID of the file to download',
  160. schema: {
  161. type: 'string',
  162. example: 'clh123abc456',
  163. },
  164. },
  165. ],
  166. responses: {
  167. '200': {
  168. description: 'File downloaded successfully',
  169. content: {
  170. 'application/octet-stream': {
  171. schema: {
  172. type: 'string',
  173. format: 'binary',
  174. },
  175. },
  176. },
  177. headers: {
  178. 'Content-Type': {
  179. description: 'MIME type of the file',
  180. schema: { type: 'string' },
  181. },
  182. 'Content-Disposition': {
  183. description: 'Attachment header with filename',
  184. schema: { type: 'string' },
  185. },
  186. 'Content-Length': {
  187. description: 'Size of the file in bytes',
  188. schema: { type: 'integer' },
  189. },
  190. },
  191. },
  192. '404': {
  193. description: 'File not found',
  194. content: {
  195. 'application/json': {
  196. schema: {
  197. type: 'object',
  198. properties: {
  199. error: { type: 'string', example: 'File not found' },
  200. },
  201. },
  202. },
  203. },
  204. },
  205. '500': {
  206. description: 'Internal server error',
  207. content: {
  208. 'application/json': {
  209. schema: {
  210. type: 'object',
  211. properties: {
  212. error: { type: 'string', example: 'Failed to retrieve file' },
  213. },
  214. },
  215. },
  216. },
  217. },
  218. },
  219. },
  220. },
  221. },
  222. };
  223. return (
  224. <div className="min-h-screen bg-gray-50">
  225. <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
  226. <div className="bg-white shadow rounded-lg">
  227. <div className="px-4 py-5 sm:p-6">
  228. <h1 className="text-2xl font-bold text-gray-900 mb-4">
  229. Vtorio API Documentation
  230. </h1>
  231. <p className="text-gray-600 mb-6">
  232. Interactive API documentation for file upload and management endpoints.
  233. </p>
  234. <SwaggerUI spec={spec} />
  235. </div>
  236. </div>
  237. </div>
  238. </div>
  239. );
  240. }