generated from mintlify/starter
-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathapi.ts
More file actions
37 lines (30 loc) · 1.05 KB
/
api.ts
File metadata and controls
37 lines (30 loc) · 1.05 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
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 chatApi = await loadOpenApi('./chat-openapi.json')
await generateDocs(
'./api-reference/chat-api/openapi',
chatApi,
'/chat-openapi.json',
'/api-reference/chat-api/openapi'
)
}
void main()