page.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import { ApiReferenceReact } from '@scalar/api-reference-react'
  2. import '@scalar/api-reference-react/style.css'
  3. const openApiSpec = {
  4. openapi: '3.0.3',
  5. info: {
  6. title: 'Vtorio API',
  7. version: '1.0.0',
  8. description: 'File upload and management API for Vtorio application',
  9. },
  10. servers: [
  11. {
  12. url: 'http://localhost:3000',
  13. description: 'Development server',
  14. },
  15. ],
  16. components: {
  17. schemas: {
  18. File: {
  19. type: 'object',
  20. properties: {
  21. id: { type: 'string' },
  22. filename: { type: 'string' },
  23. mimetype: { type: 'string' },
  24. size: { type: 'number' },
  25. createdAt: { type: 'string', format: 'date-time' },
  26. updatedAt: { type: 'string', format: 'date-time' },
  27. },
  28. required: ['id', 'filename', 'mimetype', 'size', 'createdAt'],
  29. },
  30. Error: {
  31. type: 'object',
  32. properties: {
  33. success: { type: 'boolean', example: false },
  34. error: { type: 'string' },
  35. },
  36. required: ['success', 'error'],
  37. },
  38. },
  39. },
  40. paths: {
  41. '/api/upload': {
  42. post: {
  43. summary: 'Upload a file',
  44. description: 'Upload a file to the server and store it in the database',
  45. tags: ['Files'],
  46. requestBody: {
  47. required: true,
  48. content: {
  49. 'multipart/form-data': {
  50. schema: {
  51. type: 'object',
  52. properties: {
  53. file: {
  54. type: 'string',
  55. format: 'binary',
  56. description: 'The file to upload',
  57. },
  58. },
  59. required: ['file'],
  60. },
  61. },
  62. },
  63. },
  64. responses: {
  65. '200': {
  66. description: 'File uploaded successfully',
  67. content: {
  68. 'application/json': {
  69. schema: {
  70. type: 'object',
  71. properties: {
  72. success: { type: 'boolean', example: true },
  73. file: { $ref: '#/components/schemas/File' },
  74. },
  75. },
  76. },
  77. },
  78. },
  79. '400': {
  80. description: 'Bad request',
  81. content: {
  82. 'application/json': {
  83. schema: { $ref: '#/components/schemas/Error' },
  84. },
  85. },
  86. },
  87. '500': {
  88. description: 'Internal server error',
  89. content: {
  90. 'application/json': {
  91. schema: { $ref: '#/components/schemas/Error' },
  92. },
  93. },
  94. },
  95. },
  96. },
  97. },
  98. '/api/files': {
  99. get: {
  100. summary: 'List all files',
  101. description: 'Get a list of all uploaded files with metadata',
  102. tags: ['Files'],
  103. responses: {
  104. '200': {
  105. description: 'List of files retrieved successfully',
  106. content: {
  107. 'application/json': {
  108. schema: {
  109. type: 'object',
  110. properties: {
  111. success: { type: 'boolean', example: true },
  112. files: {
  113. type: 'array',
  114. items: { $ref: '#/components/schemas/File' },
  115. },
  116. },
  117. },
  118. },
  119. },
  120. },
  121. },
  122. },
  123. },
  124. '/api/files/{id}': {
  125. get: {
  126. summary: 'Download a file',
  127. description: 'Download a specific file by its ID',
  128. tags: ['Files'],
  129. parameters: [
  130. {
  131. name: 'id',
  132. in: 'path',
  133. required: true,
  134. description: 'The ID of the file to download',
  135. schema: {
  136. type: 'string',
  137. example: 'clh123abc456',
  138. },
  139. },
  140. ],
  141. responses: {
  142. '200': {
  143. description: 'File downloaded successfully',
  144. content: {
  145. 'application/octet-stream': {
  146. schema: {
  147. type: 'string',
  148. format: 'binary',
  149. },
  150. },
  151. },
  152. },
  153. '404': {
  154. description: 'File not found',
  155. content: {
  156. 'application/json': {
  157. schema: { $ref: '#/components/schemas/Error' },
  158. },
  159. },
  160. },
  161. '500': {
  162. description: 'Internal server error',
  163. content: {
  164. 'application/json': {
  165. schema: { $ref: '#/components/schemas/Error' },
  166. },
  167. },
  168. },
  169. },
  170. },
  171. },
  172. },
  173. }
  174. export default function ApiDocs() {
  175. return (
  176. <div className="min-h-screen bg-gray-50">
  177. <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
  178. <div className="bg-white shadow rounded-lg">
  179. <div className="px-4 py-5 sm:p-6">
  180. <div className="mb-4">
  181. <h1 className="text-2xl font-bold text-gray-900">
  182. Vtorio API Documentation
  183. </h1>
  184. <p className="text-gray-600 mt-2">
  185. Interactive API documentation for file upload and management endpoints.
  186. </p>
  187. </div>
  188. <ApiReferenceReact
  189. configuration={{
  190. content: openApiSpec,
  191. theme: 'default',
  192. layout: 'modern'
  193. }}
  194. />
  195. </div>
  196. </div>
  197. </div>
  198. </div>
  199. )
  200. }