forked from botpress/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.ts
More file actions
38 lines (30 loc) · 1.76 KB
/
api.ts
File metadata and controls
38 lines (30 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { readFile, mkdir, writeFile } from 'fs/promises'
const loadOpenApi = async (filename: string) => {
const content = await readFile(filename, 'utf8')
return JSON.parse(content)
}
const generateDocs = async (folder: string, api: any, openapiFilename: string, absolutePath: string) => {
const docs: string[] = []
await mkdir(folder, { recursive: true })
for (const [path, value] of Object.entries(api.paths)) {
for (const [method, endpoint] of Object.entries(value as any)) {
const operation = (endpoint as any).operationId
await writeFile(`${folder}/${operation}.mdx`, `---\ntitle: ${operation}\nopenapi: ${openapiFilename} ${method.toUpperCase()} ${path}\n---\n`)
docs.push(`${absolutePath}/${operation}`)
}
}
console.log(JSON.stringify(docs, null, 2))
}
const main = async () => {
const adminApi = await loadOpenApi('./admin-openapi.json')
const chatApi = await loadOpenApi('./chat-openapi.json')
const filesApi = await loadOpenApi('./files-openapi.json')
const runtimeApi = await loadOpenApi('./runtime-openapi.json')
const tablesApi = await loadOpenApi('./tables-openapi.json')
await generateDocs('./api-reference/admin-api/openapi', adminApi, '/admin-openapi.json', '/api-reference/admin-api/openapi')
await generateDocs('./api-reference/chat-api/openapi', chatApi, '/chat-openapi.json', '/api-reference/chat-api/openapi')
await generateDocs('./api-reference/files-api/openapi', filesApi, '/files-openapi.json', '/api-reference/files-api/openapi')
await generateDocs('./api-reference/runtime-api/openapi', runtimeApi, '/runtime-openapi.json', '/api-reference/runtime-api/openapi')
await generateDocs('./api-reference/tables-api/openapi', tablesApi, '/tables-openapi.json', '/api-reference/tables-api/openapi')
}
void main()