( externalHTTPRoutes = [], externalWebSocketRoutes = [], disabledRoutes = [], )
| 58 | }; |
| 59 | |
| 60 | const buildOpenAPI = async ( |
| 61 | externalHTTPRoutes = [], |
| 62 | externalWebSocketRoutes = [], |
| 63 | disabledRoutes = [], |
| 64 | ) => { |
| 65 | const [{ getRouteFiles }, { Config }, { errorCodes }, packageJSON] = |
| 66 | await Promise.all([ |
| 67 | import('../build/utils.js'), |
| 68 | import('../build/config.js'), |
| 69 | import('../build/http.js'), |
| 70 | fs.readFile(packageJSONPath), |
| 71 | ]); |
| 72 | |
| 73 | const isWin = process.platform === 'win32'; |
| 74 | const readme = (await fs.readFile('README.md').catch(() => '')).toString(); |
| 75 | const changelog = marked.parse( |
| 76 | (await fs.readFile('CHANGELOG.md').catch(() => '')).toString(), |
| 77 | ); |
| 78 | |
| 79 | const [httpRoutes, wsRoutes] = await getRouteFiles(new Config()); |
| 80 | const swaggerJSON = { |
| 81 | customSiteTitle: 'Browserless Documentation', |
| 82 | definitions: {}, |
| 83 | info: { |
| 84 | title: 'Browserless', |
| 85 | version: JSON.parse(packageJSON.toString()).version, |
| 86 | 'x-logo': { |
| 87 | altText: 'browserless logo', |
| 88 | url: './docs/browserless-logo-inline.svg', |
| 89 | }, |
| 90 | }, |
| 91 | openapi: '3.0.0', |
| 92 | paths: {}, |
| 93 | servers: [], |
| 94 | // Inject routes here... |
| 95 | }; |
| 96 | |
| 97 | const routeMetaData = await Promise.all( |
| 98 | [ |
| 99 | ...httpRoutes, |
| 100 | ...wsRoutes, |
| 101 | ...externalHTTPRoutes, |
| 102 | ...externalWebSocketRoutes, |
| 103 | ] |
| 104 | .filter((r) => r.endsWith('.js')) |
| 105 | .map(async (routeModule) => { |
| 106 | const routeImport = `${isWin ? 'file:///' : ''}${routeModule}`; |
| 107 | const { default: Route } = await import(routeImport); |
| 108 | if (!Route) { |
| 109 | throw new Error(`Invalid route file to import docs ${routeModule}`); |
| 110 | } |
| 111 | const route = new Route(); |
| 112 | |
| 113 | if (disabledRoutes.includes(route.name)) { |
| 114 | return null; |
| 115 | } |
| 116 | |
| 117 | const { name } = parse(routeModule); |
no test coverage detected