diff --git a/back/package.json b/back/package.json index b3b7689..a48fcac 100644 --- a/back/package.json +++ b/back/package.json @@ -29,6 +29,7 @@ "class-validator": "^0.14.0", "class-transformer": "^0.5.0", "@asyncapi/cli": "6.0.0", + "@asyncapi/bundler": "0.9.0", "@asyncapi/generator": "3.0.1", "@asyncapi/html-template": "3.5.6", "@redocly/cli": "latest" diff --git a/back/src/modules/uploads/uploads.controller.ts b/back/src/modules/uploads/uploads.controller.ts index 2a6a176..c00d78b 100644 --- a/back/src/modules/uploads/uploads.controller.ts +++ b/back/src/modules/uploads/uploads.controller.ts @@ -15,6 +15,8 @@ import * as os from 'os'; import { execFile } from 'child_process'; import { promisify } from 'util'; import { randomUUID } from 'crypto'; +// eslint-disable-next-line @typescript-eslint/no-require-imports +const asyncapiBundle = require('@asyncapi/bundler'); const execFileAsync = promisify(execFile); const localBin = path.join(process.cwd(), 'node_modules', '.bin'); @@ -152,12 +154,15 @@ export class UploadsController { const mainPath = path.join(tempDir, mainFile.originalname); if (type === 'OPENAPI') { + /* redocly bundle : pas d'appel réseau, fonctionne en local */ await execFileAsync('redocly', ['bundle', mainPath, '--output', bundledPath], { shell: true, env: execEnv }); + return await fsPromises.readFile(bundledPath, 'utf-8'); } else { - await execFileAsync('asyncapi', ['bundle', mainPath, '--output', bundledPath], { shell: true, env: execEnv }); + /* @asyncapi/bundler API programmatique : aucun appel réseau */ + const bundleFn = asyncapiBundle.default ?? asyncapiBundle; + const document = await bundleFn([mainPath], { base: mainPath }); + return document.string(); } - - return await fsPromises.readFile(bundledPath, 'utf-8'); } finally { /* Nettoyage du répertoire temp même en cas d'erreur */ await fsPromises.rm(tempDir, { recursive: true, force: true }).catch(() => undefined);