Repository navigation
Expand file tree
/
Copy pathsync-openapi.mjs
More file actions
33 lines (32 loc) · 1.54 KB
/
Copy pathsync-openapi.mjs
File metadata and controls
33 lines (32 loc) · 1.54 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
import { execFileSync } from 'node:child_process';
import { resolve } from 'node:path';
import { writeFile } from 'node:fs/promises';
const panel = resolve(process.argv[2] ?? '../panel-next');
const output = execFileSync('php', ['-r', `
require $argv[1].'/vendor/autoload.php';
$spec = Symfony\\Component\\Yaml\\Yaml::parseFile($argv[1].'/storage/app/private/scribe/openapi.yaml', Symfony\\Component\\Yaml\\Yaml::PARSE_OBJECT_FOR_MAP);
echo json_encode($spec, JSON_THROW_ON_ERROR);
`, panel], { encoding: 'utf8', maxBuffer: 10 * 1024 * 1024 });
const spec = JSON.parse(output);
spec.info.title = 'Pterodactyl 2.0 API Reference';
spec.info.version = '2.0.0-dev';
spec.servers = [{ url: 'https://panel.example.com', description: 'Replace with your panel URL' }];
const session = spec.components?.securitySchemes?.panelSession;
if (session) {
session.name = 'pterodactyl_session';
session.description = 'Browser session cookie. This is the default name; SESSION_COOKIE or APP_NAME can change it for a deployment.';
}
// Without a display name Fumadocs titles "Admin API" as "Admin A P I".
for (const tag of spec.tags ?? []) {
tag['x-displayName'] = tag.name;
}
// Sanctum's CSRF route falls into Scribe's default "Endpoints" group.
for (const item of Object.values(spec.paths)) {
for (const operation of Object.values(item)) {
if (operation?.tags?.includes('Endpoints')) {
operation.tags = ['Authentication'];
}
}
}
spec.tags = spec.tags?.filter((tag) => tag.name !== 'Endpoints');
await writeFile('./openapi-v2.json', JSON.stringify(spec, null, 2) + '\n');