From 47b1458e2f00fe461dcd667c3d72921f4cc89a3b Mon Sep 17 00:00:00 2001 From: Atsushi Nakatsugawa Date: Thu, 19 Dec 2024 14:21:33 +0900 Subject: [PATCH 1/2] support(jsdoc): add swagger document to g2g-transfer.ts --- .../app/bin/swagger-jsdoc/definition-apiv3.js | 5 + .../src/server/routes/apiv3/g2g-transfer.ts | 203 +++++++++++++++++- 2 files changed, 207 insertions(+), 1 deletion(-) diff --git a/apps/app/bin/swagger-jsdoc/definition-apiv3.js b/apps/app/bin/swagger-jsdoc/definition-apiv3.js index 097d706d94c..92a73c4afd3 100644 --- a/apps/app/bin/swagger-jsdoc/definition-apiv3.js +++ b/apps/app/bin/swagger-jsdoc/definition-apiv3.js @@ -28,6 +28,11 @@ module.exports = { in: 'cookie', name: 'connect.sid', }, + transferHeaderAuth: { + type: 'apiKey', + in: 'header', + name: 'x-growi-transfer-key', + }, }, }, 'x-tagGroups': [ diff --git a/apps/app/src/server/routes/apiv3/g2g-transfer.ts b/apps/app/src/server/routes/apiv3/g2g-transfer.ts index f1d02a8a79a..68480803451 100644 --- a/apps/app/src/server/routes/apiv3/g2g-transfer.ts +++ b/apps/app/src/server/routes/apiv3/g2g-transfer.ts @@ -36,6 +36,39 @@ const validator = { ], }; +/** + * @swagger + * + * components: + * schemas: + * GrowiInfo: + * type: object + * properties: + * version: + * type: string + * description: The version of the GROWI + * userUpperLimit: + * type: number + * description: The upper limit of the number of users + * fileUploadDisabled: + * type: boolean + * fileUploadTotalLimit: + * type: number + * description: The total limit of the file upload size + * attachmentInfo: + * type: object + * properties: + * type: + * type: string + * writable: + * type: boolean + * bucket: + * type: string + * customEndpoint: + * type: string + * uploadNamespace: + * type: string +*/ /* * Routes */ @@ -136,7 +169,51 @@ module.exports = (crowi: Crowi): Router => { return res.apiv3({ files }); }); - // Auto import + /** + * @swagger + * + * /g2g-transfer: + * post: + * summary: /g2g-transfer + * tags: [Export] + * security: + * - transferHeaderAuth: [] + * requestBody: + * required: true + * content: + * multipart/form-data: + * schema: + * type: object + * properties: + * file: + * format: binary + * description: The zip file of the data to be transferred + * collections: + * type: array + * description: The list of MongoDB collections to be transferred + * items: + * type: string + * optionsMap: + * type: object + * description: The map of options for each collection + * operatorUserId: + * type: string + * description: The ID of the operator user + * uploadConfigs: + * type: object + * description: The map of upload configurations + * responses: + * '200': + * description: Successfully started to receive transfer data + * content: + * application/json: + * schema: + * type: object + * properties: + * message: + * type: string + * description: The message of the result + */ // eslint-disable-next-line max-len receiveRouter.post('/', uploads.single('transferDataZipFile'), validateTransferKey, async(req: Request & { file: any; }, res: ApiV3Response) => { const { file } = req; @@ -221,6 +298,40 @@ module.exports = (crowi: Crowi): Router => { return res.apiv3({ message: 'Successfully started to receive transfer data.' }); }); + /** + * @swagger + * + * /g2g-transfer/attachment: + * post: + * summary: /g2g-transfer/attachment + * tags: [Export] + * security: + * - transferHeaderAuth: [] + * requestBody: + * required: true + * content: + * multipart/form-data: + * schema: + * type: object + * properties: + * file: + * format: binary + * description: The zip file of the data to be transferred + * attachmentMetadata: + * type: object + * description: Metadata of the attachment + * responses: + * '200': + * description: + * content: + * application/json: + * schema: + * type: object + * properties: + * message: + * type: string + * description: The message of the result + */ // This endpoint uses multer's MemoryStorage since the received data should be persisted directly on attachment storage. receiveRouter.post('/attachment', uploadsForAttachment.single('content'), validateTransferKey, async(req: Request & { file: any; }, res: ApiV3Response) => { @@ -250,6 +361,26 @@ module.exports = (crowi: Crowi): Router => { return res.apiv3({ message: 'Successfully imported attached file.' }); }); + /** + * @swagger + * + * /g2g-transfer/growi-info: + * get: + * summary: /g2g-transfer/growi-info + * tags: [Export] + * security: + * - transferHeaderAuth: [] + * responses: + * '200': + * description: + * content: + * application/json: + * schema: + * type: object + * properties: + * growiInfo: + * $ref: '#/components/schemas/GrowiInfo' + */ receiveRouter.get('/growi-info', validateTransferKey, async(req: Request, res: ApiV3Response) => { let growiInfo: IDataGROWIInfo; try { @@ -268,6 +399,37 @@ module.exports = (crowi: Crowi): Router => { return res.apiv3({ growiInfo }); }); + /** + * @swagger + * + * /g2g-transfer/generate-key: + * post: + * summary: /g2g-transfer/generate-key + * tags: [Export] + * security: + * - api_key: [] + * requestBody: + * required: true + * content: + * application/json: + * schema: + * type: object + * properties: + * appSiteUrl: + * type: string + * description: The URL of the GROWI + * responses: + * '200': + * description: Successfully generated transfer key + * content: + * application/json: + * schema: + * type: object + * properties: + * transferKey: + * type: string + * description: The transfer key + */ // eslint-disable-next-line max-len receiveRouter.post('/generate-key', accessTokenParser, adminRequiredIfInstalled, appSiteUrlRequiredIfNotInstalled, async(req: Request, res: ApiV3Response) => { const appSiteUrl = req.body.appSiteUrl ?? crowi.configManager?.getConfig('crowi', 'app:siteUrl'); @@ -294,6 +456,45 @@ module.exports = (crowi: Crowi): Router => { return res.apiv3({ transferKey: transferKeyString }); }); + /** + * @swagger + * + * /g2g-transfer/transfer: + * post: + * summary: /g2g-transfer/transfer + * tags: [Export] + * security: + * - api_key: [] + * requestBody: + * required: true + * content: + * application/json: + * schema: + * type: object + * properties: + * transferKey: + * type: string + * description: The transfer key + * collections: + * type: array + * description: The list of MongoDB collections to be transferred + * items: + * type: string + * optionsMap: + * type: object + * description: The map of options for each collection + * responses: + * '200': + * description: Successfully requested auto transfer + * content: + * application/json: + * schema: + * type: object + * properties: + * message: + * type: string + * description: The message of the result + */ // eslint-disable-next-line max-len pushRouter.post('/transfer', accessTokenParser, loginRequiredStrictly, adminRequired, validator.transfer, apiV3FormValidator, async(req: AuthorizedRequest, res: ApiV3Response) => { const { transferKey, collections, optionsMap } = req.body; From dc07698eead69360cb903f2700a9c3ee261bbac9 Mon Sep 17 00:00:00 2001 From: Atsushi Nakatsugawa Date: Thu, 19 Dec 2024 14:30:09 +0900 Subject: [PATCH 2/2] support(jsdoc): add swagger document to g2g-transfer.ts --- .../src/server/routes/apiv3/g2g-transfer.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/apps/app/src/server/routes/apiv3/g2g-transfer.ts b/apps/app/src/server/routes/apiv3/g2g-transfer.ts index 68480803451..da7445a608e 100644 --- a/apps/app/src/server/routes/apiv3/g2g-transfer.ts +++ b/apps/app/src/server/routes/apiv3/g2g-transfer.ts @@ -163,6 +163,35 @@ module.exports = (crowi: Crowi): Router => { const receiveRouter = express.Router(); const pushRouter = express.Router(); + /** + * @swagger + * + * /g2g-transfer/files: + * get: + * summary: /g2g-transfer/files + * tags: [Export] + * security: + * - transferHeaderAuth: [] + * responses: + * '200': + * description: Successfully got the list of files + * content: + * application/json: + * schema: + * type: object + * properties: + * files: + * type: array + * items: + * type: object + * properties: + * name: + * type: string + * description: The name of the file + * size: + * type: number + * description: The size of the file + */ // eslint-disable-next-line max-len receiveRouter.get('/files', validateTransferKey, async(req: Request, res: ApiV3Response) => { const files = await crowi.fileUploadService.listFiles();