56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
/**
|
||
|
|
* OpenAPI Documentation Bundler
|
||
|
|
*
|
||
|
|
* This script merges the modular OpenAPI specification files into a single
|
||
|
|
* api-docs.yaml file that can be served to Swagger UI or other OpenAPI tools.
|
||
|
|
*
|
||
|
|
* Usage: php bundle-api-docs.php
|
||
|
|
*/
|
||
|
|
|
||
|
|
$publicDir = __DIR__;
|
||
|
|
$componentsDir = $publicDir . '/components/schemas';
|
||
|
|
$pathsDir = $publicDir . '/paths';
|
||
|
|
$outputFile = $publicDir . '/api-docs.bundled.yaml';
|
||
|
|
|
||
|
|
// Read the base api-docs.yaml
|
||
|
|
$apiDocsContent = file_get_contents($publicDir . '/api-docs.yaml');
|
||
|
|
$apiDocs = yaml_parse($apiDocsContent);
|
||
|
|
|
||
|
|
if ($apiDocs === false) {
|
||
|
|
die("Error: Failed to parse api-docs.yaml\n");
|
||
|
|
}
|
||
|
|
|
||
|
|
// Merge paths from all path files
|
||
|
|
$paths = [];
|
||
|
|
$pathFiles = glob($pathsDir . '/*.yaml');
|
||
|
|
|
||
|
|
echo "Found " . count($pathFiles) . " path files to merge...\n";
|
||
|
|
|
||
|
|
foreach ($pathFiles as $filepath) {
|
||
|
|
$filename = basename($filepath);
|
||
|
|
$content = file_get_contents($filepath);
|
||
|
|
$parsed = yaml_parse($content);
|
||
|
|
|
||
|
|
if ($parsed === false) {
|
||
|
|
echo " ⚠ Warning: Failed to parse $filename\n";
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
$paths = array_merge($paths, $parsed);
|
||
|
|
echo " ✓ Merged " . count($parsed) . " paths from $filename\n";
|
||
|
|
}
|
||
|
|
|
||
|
|
// Replace the empty paths with merged paths
|
||
|
|
$apiDocs['paths'] = $paths;
|
||
|
|
|
||
|
|
// Write the bundled file
|
||
|
|
$bundledYaml = yaml_emit($apiDocs, YAML_UTF8_ENCODING);
|
||
|
|
|
||
|
|
file_put_contents($outputFile, $bundledYaml);
|
||
|
|
|
||
|
|
echo "\n✅ Successfully bundled OpenAPI spec to: $outputFile\n";
|
||
|
|
echo " Total paths: " . count($paths) . "\n";
|
||
|
|
echo " Total schemas: " . count($apiDocs['components']['schemas']) . "\n";
|