Quellcode durchsuchen

fix(openapi): update OpenAPI version to 3.0.3 and refine schema definitions

vtugulan vor 6 Monaten
Ursprung
Commit
574f6196d1
1 geänderte Dateien mit 18 neuen und 78 gelöschten Zeilen
  1. 18 78
      app/api/openapi.json/route.ts

+ 18 - 78
app/api/openapi.json/route.ts

@@ -1,7 +1,7 @@
 import { NextResponse } from 'next/server';
 import { NextResponse } from 'next/server';
 
 
 const openApiSpec = {
 const openApiSpec = {
-  openapi: '3.0.0',
+  openapi: '3.0.3',
   info: {
   info: {
     title: 'Vtorio API',
     title: 'Vtorio API',
     version: '1.0.0',
     version: '1.0.0',
@@ -25,6 +25,15 @@ const openApiSpec = {
           createdAt: { type: 'string', format: 'date-time' },
           createdAt: { type: 'string', format: 'date-time' },
           updatedAt: { type: 'string', format: 'date-time' },
           updatedAt: { type: 'string', format: 'date-time' },
         },
         },
+        required: ['id', 'filename', 'mimetype', 'size', 'createdAt'],
+      },
+      Error: {
+        type: 'object',
+        properties: {
+          success: { type: 'boolean', example: false },
+          error: { type: 'string' },
+        },
+        required: ['success', 'error'],
       },
       },
     },
     },
   },
   },
@@ -61,32 +70,17 @@ const openApiSpec = {
                   type: 'object',
                   type: 'object',
                   properties: {
                   properties: {
                     success: { type: 'boolean', example: true },
                     success: { type: 'boolean', example: true },
-                    file: {
-                      type: 'object',
-                      properties: {
-                        id: { type: 'string', example: 'clh123abc456' },
-                        filename: { type: 'string', example: 'document.pdf' },
-                        mimetype: { type: 'string', example: 'application/pdf' },
-                        size: { type: 'number', example: 1024000 },
-                        createdAt: { type: 'string', format: 'date-time' },
-                      },
-                    },
+                    file: { $ref: '#/components/schemas/File' },
                   },
                   },
                 },
                 },
               },
               },
             },
             },
           },
           },
           '400': {
           '400': {
-            description: 'Bad request - No file provided',
+            description: 'Bad request',
             content: {
             content: {
               'application/json': {
               'application/json': {
-                schema: {
-                  type: 'object',
-                  properties: {
-                    success: { type: 'boolean', example: false },
-                    error: { type: 'string', example: 'No file provided' },
-                  },
-                },
+                schema: { $ref: '#/components/schemas/Error' },
               },
               },
             },
             },
           },
           },
@@ -94,13 +88,7 @@ const openApiSpec = {
             description: 'Internal server error',
             description: 'Internal server error',
             content: {
             content: {
               'application/json': {
               'application/json': {
-                schema: {
-                  type: 'object',
-                  properties: {
-                    success: { type: 'boolean', example: false },
-                    error: { type: 'string', example: 'Failed to upload file' },
-                  },
-                },
+                schema: { $ref: '#/components/schemas/Error' },
               },
               },
             },
             },
           },
           },
@@ -123,37 +111,13 @@ const openApiSpec = {
                     success: { type: 'boolean', example: true },
                     success: { type: 'boolean', example: true },
                     files: {
                     files: {
                       type: 'array',
                       type: 'array',
-                      items: {
-                        type: 'object',
-                        properties: {
-                          id: { type: 'string', example: 'clh123abc456' },
-                          filename: { type: 'string', example: 'document.pdf' },
-                          mimetype: { type: 'string', example: 'application/pdf' },
-                          size: { type: 'number', example: 1024000 },
-                          createdAt: { type: 'string', format: 'date-time' },
-                          updatedAt: { type: 'string', format: 'date-time' },
-                        },
-                      },
+                      items: { $ref: '#/components/schemas/File' },
                     },
                     },
                   },
                   },
                 },
                 },
               },
               },
             },
             },
           },
           },
-          '500': {
-            description: 'Internal server error',
-            content: {
-              'application/json': {
-                schema: {
-                  type: 'object',
-                  properties: {
-                    success: { type: 'boolean', example: false },
-                    error: { type: 'string', example: 'Failed to list files' },
-                  },
-                },
-              },
-            },
-          },
         },
         },
       },
       },
     },
     },
@@ -185,31 +149,12 @@ const openApiSpec = {
                 },
                 },
               },
               },
             },
             },
-            headers: {
-              'Content-Type': {
-                description: 'MIME type of the file',
-                schema: { type: 'string' },
-              },
-              'Content-Disposition': {
-                description: 'Attachment header with filename',
-                schema: { type: 'string' },
-              },
-              'Content-Length': {
-                description: 'Size of the file in bytes',
-                schema: { type: 'integer' },
-              },
-            },
           },
           },
           '404': {
           '404': {
             description: 'File not found',
             description: 'File not found',
             content: {
             content: {
               'application/json': {
               'application/json': {
-                schema: {
-                  type: 'object',
-                  properties: {
-                    error: { type: 'string', example: 'File not found' },
-                  },
-                },
+                schema: { $ref: '#/components/schemas/Error' },
               },
               },
             },
             },
           },
           },
@@ -217,12 +162,7 @@ const openApiSpec = {
             description: 'Internal server error',
             description: 'Internal server error',
             content: {
             content: {
               'application/json': {
               'application/json': {
-                schema: {
-                  type: 'object',
-                  properties: {
-                    error: { type: 'string', example: 'Failed to retrieve file' },
-                  },
-                },
+                schema: { $ref: '#/components/schemas/Error' },
               },
               },
             },
             },
           },
           },
@@ -238,4 +178,4 @@ export const GET = async () => {
       'Content-Type': 'application/json',
       'Content-Type': 'application/json',
     },
     },
   });
   });
-};
+};