clqms-be/public/bundle-api-docs.php
mahdahar fcaf9b74ea feat: Restructure OpenAPI documentation with modular components
- Add OpenApiDocs controller for serving bundled API docs

- Split monolithic api-docs.yaml into modular components/

- Add organized paths/ directory with endpoint definitions

- Create bundling scripts (JS, PHP, Python) for merging docs

- Add API_DOCS_README.md with documentation guidelines

- Update Routes.php for new API documentation endpoints

- Update swagger.php view and TestDefSiteModel
2026-02-16 14:20:52 +07:00

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";