|
1 | | -import { readFileSync } from 'node:fs' |
2 | | -import { join } from 'node:path' |
3 | 1 | import type { MethodInformation } from 'fumadocs-openapi' |
4 | 2 | import type { InlineCodeUsageGenerator } from 'fumadocs-openapi/requests/generators' |
5 | 3 | import { createOpenAPI } from 'fumadocs-openapi/server' |
6 | 4 | import { buildAuthCodeSamples } from '@/lib/openapi-code-samples' |
7 | 5 | import { OPENAPI_SPEC_FILES } from '@/lib/openapi-specs' |
| 6 | +import billingSpec from '@/openapi-v2-billing.json' |
| 7 | +import filesAuditSpec from '@/openapi-v2-files-audit.json' |
| 8 | +import knowledgeSpec from '@/openapi-v2-knowledge.json' |
| 9 | +import logsSpec from '@/openapi-v2-logs.json' |
| 10 | +import resourcesSpec from '@/openapi-v2-resources.json' |
| 11 | +import tablesSpec from '@/openapi-v2-tables.json' |
| 12 | +import workflowsSpec from '@/openapi-v2-workflows.json' |
8 | 13 |
|
9 | 14 | export const openapi = createOpenAPI({ |
10 | 15 | input: OPENAPI_SPEC_FILES.map((file) => `./${file}`), |
@@ -66,16 +71,20 @@ function formatSchema(schema: unknown): string { |
66 | 71 | return JSON.stringify(schema, null, 2) |
67 | 72 | } |
68 | 73 |
|
69 | | -let cachedSpecs: Record<string, unknown>[] | null = null |
| 74 | +const SPEC_BY_FILE = { |
| 75 | + 'openapi-v2-billing.json': billingSpec, |
| 76 | + 'openapi-v2-files-audit.json': filesAuditSpec, |
| 77 | + 'openapi-v2-knowledge.json': knowledgeSpec, |
| 78 | + 'openapi-v2-logs.json': logsSpec, |
| 79 | + 'openapi-v2-resources.json': resourcesSpec, |
| 80 | + 'openapi-v2-tables.json': tablesSpec, |
| 81 | + 'openapi-v2-workflows.json': workflowsSpec, |
| 82 | +} satisfies Record<(typeof OPENAPI_SPEC_FILES)[number], Record<string, unknown>> |
| 83 | + |
| 84 | +const SPECS = OPENAPI_SPEC_FILES.map((file) => SPEC_BY_FILE[file]) |
70 | 85 |
|
71 | 86 | function getSpecs(): Record<string, unknown>[] { |
72 | | - if (!cachedSpecs) { |
73 | | - cachedSpecs = OPENAPI_SPEC_FILES.map( |
74 | | - (file) => |
75 | | - JSON.parse(readFileSync(join(process.cwd(), file), 'utf8')) as Record<string, unknown> |
76 | | - ) |
77 | | - } |
78 | | - return cachedSpecs |
| 87 | + return SPECS |
79 | 88 | } |
80 | 89 |
|
81 | 90 | type SecurityRequirement = Record<string, string[]> |
|
0 commit comments